blob: f7e5af513c6b91884f2798c96ba4771f1f1ee940 [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]005bab02011-10-07 18:36:0016#include "base/json/json_value_serializer.h"
[email protected]b1cf3372011-04-20 21:28:1017#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4918#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2820#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2922#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]7ef40ffe12011-03-08 05:05:2832#include "content/common/file_system/file_system_dispatcher.h"
33#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]a2ef54c2011-10-10 16:20:3134#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5135#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1036#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0037#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4038#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0539#include "content/common/request_extra_data.h"
[email protected]778574e2011-03-21 22:03:5040#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2141#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4842#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2943#include "content/public/common/content_switches.h"
[email protected]8caadeb2011-11-22 02:45:2344#include "content/public/common/file_chooser_params.h"
[email protected]a1d29162011-10-14 17:14:0345#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3446#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0747#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3248#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4449#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3650#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1951#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0252#include "content/renderer/devtools_agent.h"
[email protected]55722152011-03-22 01:33:5353#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1954#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4055#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]1784b2f2011-11-24 10:53:4856#include "content/renderer/idle_user_detector.h"
[email protected]0d9989d2011-12-21 20:26:0057#include "content/renderer/web_intents_host.h"
[email protected]07161902011-11-11 09:57:4258#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0259#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0860#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3761#include "content/renderer/media/audio_renderer_impl.h"
[email protected]273558fb2012-01-12 15:03:5162#include "content/renderer/media/media_stream_dependency_factory.h"
63#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4064#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:4065#include "content/renderer/media/render_media_log.h"
[email protected]4a19be92011-09-22 14:25:0266#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1967#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3768#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3569#include "content/renderer/plugin_channel_host.h"
[email protected]9e2269d2012-01-07 00:06:2170#include "content/renderer/render_audiosourceprovider.h"
[email protected]8704f89b2011-04-15 00:30:0571#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4472#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4473#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3274#include "content/renderer/renderer_accessibility.h"
[email protected]e1d69d762011-12-13 05:12:1875#include "content/renderer/renderer_gpu_video_decoder_factories.h"
[email protected]663bd9e2011-03-21 01:07:0176#include "content/renderer/renderer_webapplicationcachehost_impl.h"
77#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1978#include "content/renderer/speech_input_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3279#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1980#include "content/renderer/v8_value_converter_impl.h"
[email protected]663bd9e2011-03-21 01:07:0181#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3582#include "content/renderer/webplugin_delegate_proxy.h"
83#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4984#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4185#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2786#include "media/base/message_loop_factory_impl.h"
[email protected]e1d69d762011-12-13 05:12:1887#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2988#include "net/base/escape.h"
89#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0490#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5791#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3792#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:3793#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3794#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3795#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
96#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3797#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
98#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
99#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
100#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
101#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37102#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37103#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57104#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58105#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14107#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37108#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19109#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37110#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36111#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37112#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
113#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
114#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37115#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17119#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37121#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40122#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51123#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08124#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]273558fb2012-01-12 15:03:51130#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08132#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]e6e90dc2011-12-03 00:01:37135#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26141#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47142#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38143#include "ui/gfx/native_widget_types.h"
144#include "ui/gfx/point.h"
145#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55146#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04147#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]9c4bf232011-12-15 02:25:08148#include "webkit/forms/form_data.h"
149#include "webkit/forms/form_field.h"
150#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43151#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24152#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19153#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24154#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29155#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07156#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29157#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03158#include "webkit/glue/weburlloader_impl.h"
[email protected]a9288f52011-11-17 05:18:16159#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50160#include "webkit/plugins/npapi/plugin_list.h"
161#include "webkit/plugins/npapi/webplugin_delegate.h"
162#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
163#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52164#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29165
[email protected]6c8afae52009-01-22 02:24:57166#if defined(OS_WIN)
167// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57168// * theming
[email protected]08397d52011-02-05 01:53:38169#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03170#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37171#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51172#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33173#elif defined(OS_MACOSX)
174#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57175#endif
176
[email protected]9892b472010-09-16 00:23:42177using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08178using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21179using WebKit::WebApplicationCacheHost;
180using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26181using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41182using WebKit::WebColor;
183using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59184using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44185using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51186using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55187using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28188using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00189using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58190using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25191using WebKit::WebDragOperation;
192using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51193using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51194using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08195using WebKit::WebExternalPopupMenu;
196using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47197using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22198using WebKit::WebFileSystem;
199using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49200using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59201using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48202using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45203using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17204using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13205using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41206using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50207using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17208using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28209using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17210using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28211using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28212using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51213using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19214using WebKit::WebPageSerializer;
215using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17216using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36217using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40218using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49219using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09220using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52221using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59222using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51223using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52224using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15225using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40226using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35227using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29228using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17229using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59230using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42231using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02232using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34233using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40234using WebKit::WebStorageQuotaCallbacks;
235using WebKit::WebStorageQuotaError;
236using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28237using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51238using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52239using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24240using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28241using WebKit::WebURL;
242using WebKit::WebURLError;
243using WebKit::WebURLRequest;
244using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28245using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03246using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28247using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26248using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26249using appcache::WebApplicationCacheHostImpl;
250using base::Time;
251using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07252using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32253using content::NavigationState;
[email protected]380244092011-10-07 17:26:27254using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44255using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36256using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15257using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19258using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08259using webkit::forms::FormField;
260using webkit::forms::PasswordForm;
261using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26262using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23263using webkit_glue::ResourceFetcher;
[email protected]e1acf6f2008-10-27 20:43:33264
initial.commit09911bf2008-07-26 23:55:29265//-----------------------------------------------------------------------------
266
[email protected]310ebd6302011-10-10 19:06:28267typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49268static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02269
[email protected]882daa92009-11-05 16:31:31270// Time, in seconds, we delay before sending content state changes (such as form
271// state and scroll position) to the browser. We delay sending changes to avoid
272// spamming the browser.
273// To avoid having tab/session restore require sending a message to get the
274// current content state during tab closing we use a shorter timeout for the
275// foreground renderer. This means there is a small window of time from which
276// content state is modified and not sent to session restore, but this is
277// better than having to wake up all renderers during shutdown.
278static const int kDelaySecondsForContentStateSyncHidden = 5;
279static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29280
[email protected]e99ef6f2011-10-16 01:13:00281static const size_t kExtraCharsBeforeAndAfterSelection = 100;
282
[email protected]0aa55312008-10-17 21:53:08283// The maximum number of popups that can be spawned from one page.
284static const int kMaximumNumberOfUnacknowledgedPopups = 25;
285
[email protected]c514d6372011-08-16 22:54:44286static const float kScalingIncrement = 0.1f;
287
[email protected]47578fa02011-11-02 19:34:41288static const float kScalingIncrementForGesture = 0.01f;
289
[email protected]726985e22009-06-18 21:09:28290static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
291 WebVector<WebURL> urls;
292 ds->redirectChain(urls);
293 result->reserve(urls.size());
294 for (size_t i = 0; i < urls.size(); ++i)
295 result->push_back(urls[i]);
296}
297
[email protected]007733c2011-11-17 00:34:07298// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44299// the AltErrorPageResourceFetcher is reset.
300static void StopAltErrorPageFetcher(WebDataSource* data_source) {
301 if (data_source) {
[email protected]007733c2011-11-17 00:34:07302 DocumentState* document_state = DocumentState::FromDataSource(data_source);
303 if (document_state)
304 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44305 }
306}
307
[email protected]007733c2011-11-17 00:34:07308static bool IsReload(const ViewMsg_Navigate_Params& params) {
309 return
310 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
311 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
312}
313
[email protected]445e1042011-12-03 21:03:15314static WebReferrerPolicy getReferrerPolicyFromRequest(
315 const WebURLRequest& request) {
316 return request.extraData() ?
317 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
318 WebKit::WebReferrerPolicyDefault;
319}
320
initial.commit09911bf2008-07-26 23:55:29321///////////////////////////////////////////////////////////////////////////////
322
[email protected]310ebd6302011-10-10 19:06:28323struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23324 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47325 WebFileChooserCompletion* c)
326 : params(p),
327 completion(c) {
328 }
[email protected]8caadeb2011-11-22 02:45:23329 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47330 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
331};
332
[email protected]daf82f82011-10-31 22:35:31333RenderViewImpl::RenderViewImpl(
334 gfx::NativeViewId parent_hwnd,
335 int32 opener_id,
336 const content::RendererPreferences& renderer_prefs,
337 const WebPreferences& webkit_prefs,
338 SharedRenderViewCounter* counter,
339 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56340 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31341 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46342 const string16& frame_name,
343 int32 next_page_id)
[email protected]380244092011-10-07 17:26:27344 : RenderWidget(WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51345 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02346 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09347 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02348 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24349 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21350 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02351 opened_by_user_gesture_(true),
352 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24353 page_id_(-1),
354 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46355 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00356 history_list_offset_(-1),
357 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02358 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55359 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31360 cached_is_main_frame_pinned_to_left_(false),
361 cached_is_main_frame_pinned_to_right_(false),
362 cached_has_main_frame_horizontal_scrollbar_(false),
363 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]3354d3e2010-06-10 19:53:02364 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51365 geolocation_dispatcher_(NULL),
366 speech_input_dispatcher_(NULL),
367 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51368 media_stream_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18369 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41370 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32371 renderer_accessibility_(NULL),
[email protected]4fb60142011-08-09 02:22:08372 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18373 handling_select_range_(false),
374#if defined(OS_WIN)
375 focused_plugin_id_(-1),
376#endif
377 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51378 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56379 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51380 if (opener_id != MSG_ROUTING_NONE)
381 opener_id_ = opener_id;
382
[email protected]74ce1ad2011-12-16 21:51:46383 // Ensure we start with a valid next_page_id_ from the browser.
384 DCHECK_GE(next_page_id_, 0);
385
[email protected]21b3a6ae2011-11-30 00:45:29386#if defined(ENABLE_NOTIFICATIONS)
387 notification_provider_ = new NotificationProvider(this);
388#else
389 notification_provider_ = NULL;
390#endif
391
[email protected]11fee2332011-03-29 20:36:35392 webwidget_ = WebView::create(this);
393
[email protected]676126f72011-01-15 00:03:51394 if (counter) {
395 shared_popup_counter_ = counter;
396 shared_popup_counter_->data++;
397 decrement_shared_popup_at_destruction_ = true;
398 } else {
399 shared_popup_counter_ = new SharedRenderViewCounter(0);
400 decrement_shared_popup_at_destruction_ = false;
401 }
402
[email protected]0d9989d2011-12-21 20:26:00403 intents_host_ = new WebIntentsHost(this);
[email protected]7cce3232011-10-28 10:41:57404
[email protected]380244092011-10-07 17:26:27405 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51406 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47407 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51408 AddRef();
409
410 // If this is a popup, we must wait for the CreatingNew_ACK message before
411 // completing initialization. Otherwise, we can finish it now.
412 if (opener_id == MSG_ROUTING_NONE) {
413 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55414 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51415 }
416
[email protected]34c61bd52011-05-02 19:38:33417 g_view_map.Get().insert(std::make_pair(webview(), this));
418 webkit_preferences_.Apply(webview());
419 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35420 if (!frame_name.empty())
421 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33422 webview()->settings()->setMinimumTimerInterval(
423 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
424 webkit_glue::kForegroundTabTimerInterval);
425
426 OnSetRendererPrefs(renderer_prefs);
427
[email protected]676126f72011-01-15 00:03:51428 host_window_ = parent_hwnd;
429
[email protected]a026daa2011-04-20 15:49:51430#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51431 if (!p2p_socket_dispatcher_)
432 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51433#endif
[email protected]cae8c8492011-03-03 11:12:18434
[email protected]8f6a3b852011-07-19 16:48:56435 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32436#if defined(OS_MACOSX)
437 new TextInputClientObserver(this);
438#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56439
[email protected]c5c1d6d2011-07-28 18:42:41440 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20441
[email protected]063afcb2011-09-29 07:54:32442 renderer_accessibility_ = new RendererAccessibility(this);
443
[email protected]1784b2f2011-11-24 10:53:48444 new IdleUserDetector(this);
445
[email protected]e48869a2011-04-01 19:56:03446 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29447}
448
[email protected]310ebd6302011-10-10 19:06:28449RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03450 history_page_ids_.clear();
451
[email protected]0aa55312008-10-17 21:53:08452 if (decrement_shared_popup_at_destruction_)
453 shared_popup_counter_->data--;
454
[email protected]a1128322009-10-06 18:38:46455 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47456 while (!file_chooser_completions_.empty()) {
457 if (file_chooser_completions_.front()->completion) {
458 file_chooser_completions_.front()->completion->didChooseFile(
459 WebVector<WebString>());
460 }
461 file_chooser_completions_.pop_front();
462 }
[email protected]a1128322009-10-06 18:38:46463
[email protected]83dde542009-09-11 20:59:55464#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11465 // Destroy all fake plugin window handles on the browser side.
466 while (!fake_plugin_window_handles_.empty()) {
467 // Make sure no NULL plugin window handles were inserted into this list.
468 DCHECK(*fake_plugin_window_handles_.begin());
469 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
470 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
471 }
[email protected]83dde542009-09-11 20:59:55472#endif
[email protected]98324892009-09-09 21:16:05473
[email protected]60c42a8c72009-10-09 04:08:59474#ifndef NDEBUG
475 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49476 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59477 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
478 DCHECK_NE(this, it->second) << "Failed to call Close?";
479#endif
[email protected]676126f72011-01-15 00:03:51480
[email protected]273558fb2012-01-12 15:03:51481 // MediaStreamImpl holds weak references to RenderViewObserver objects,
482 // ensure it's deleted before the observers.
483 media_stream_impl_ = NULL;
484
[email protected]310ebd6302011-10-10 19:06:28485 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51486 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59487}
488
489/*static*/
[email protected]310ebd6302011-10-10 19:06:28490RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31491 ViewMap* views = g_view_map.Pointer();
492 ViewMap::iterator it = views->find(webview);
493 return it == views->end() ? NULL : it->second;
494}
495
496/*static*/
497content::RenderView*
498 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28499 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31500}
501
502/*static*/
503void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49504 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59505 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
506 if (!visitor->Visit(it->second))
507 return;
508 }
509}
510
511/*static*/
[email protected]310ebd6302011-10-10 19:06:28512RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15513 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08514 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31515 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08516 const WebPreferences& webkit_prefs,
517 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34518 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56519 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26520 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46521 const string16& frame_name,
522 int32 next_page_id) {
initial.commit09911bf2008-07-26 23:55:29523 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28524 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51525 parent_hwnd,
526 opener_id,
527 renderer_prefs,
528 webkit_prefs,
529 counter,
530 routing_id,
[email protected]9f4f3322012-01-18 22:29:56531 surface_id,
[email protected]676126f72011-01-15 00:03:51532 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46533 frame_name,
534 next_page_id); // adds reference
initial.commit09911bf2008-07-26 23:55:29535}
536
[email protected]273558fb2012-01-12 15:03:51537WebKit::WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
538 WebKit::WebPeerConnectionHandlerClient* client) {
539 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
540 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
541 return NULL;
542 EnsureMediaStreamImpl();
543 return media_stream_impl_->CreatePeerConnectionHandler(client);
544}
545
[email protected]310ebd6302011-10-10 19:06:28546void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51547 observers_.AddObserver(observer);
548}
549
[email protected]310ebd6302011-10-10 19:06:28550void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
551 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51552 observers_.RemoveObserver(observer);
553}
554
[email protected]310ebd6302011-10-10 19:06:28555WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26556 return static_cast<WebKit::WebView*>(webwidget());
557}
558
[email protected]310ebd6302011-10-10 19:06:28559void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40560 if (!enabled) {
561 load_progress_tracker_.reset(NULL);
562 return;
563 }
564 if (load_progress_tracker_ == NULL)
565 load_progress_tracker_.reset(new LoadProgressTracker(this));
566}
567
[email protected]310ebd6302011-10-10 19:06:28568void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51569 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29570}
571
[email protected]310ebd6302011-10-10 19:06:28572void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26573 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30574 // If the renderer is visible, set initial visibility and focus state.
575 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34576#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30577 delegate->SetContainerVisibility(true);
578 if (webview() && webview()->isActive())
579 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34580#endif
[email protected]49232292010-09-03 19:07:30581 }
[email protected]784ea1ab2010-09-18 00:02:34582 // Plugins start assuming the content has focus (so that they work in
583 // environments where RenderView isn't hosting them), so we always have to
584 // set the initial state. See webplugin_delegate_impl.h for details.
585 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26586}
587
[email protected]310ebd6302011-10-10 19:06:28588void RenderViewImpl::UnregisterPluginDelegate(
589 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26590 plugin_delegates_.erase(delegate);
591}
[email protected]d8fd6fa2010-02-01 15:54:26592
[email protected]310ebd6302011-10-10 19:06:28593bool RenderViewImpl::GetPluginInfo(const GURL& url,
594 const GURL& page_url,
595 const std::string& mime_type,
596 webkit::WebPluginInfo* plugin_info,
597 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08598 bool found = false;
599 Send(new ViewHostMsg_GetPluginInfo(
600 routing_id_, url, page_url, mime_type, &found, plugin_info,
601 actual_mime_type));
602 return found;
603}
604
[email protected]310ebd6302011-10-10 19:06:28605bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27606 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27607 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41608 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26609
[email protected]676126f72011-01-15 00:03:51610 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
611 RenderViewObserver* observer;
612 while ((observer = it.GetNext()) != NULL)
613 if (observer->OnMessageReceived(message))
614 return true;
[email protected]b2abac72009-02-26 12:39:28615
[email protected]a95986a82010-12-24 06:19:28616 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40617 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28618 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29619 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
620 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56621 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29622 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
623 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
624 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
625 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27626#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35627 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27628#endif
initial.commit09911bf2008-07-26 23:55:29629 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15630 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29631 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
632 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
633 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08634 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29635 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15636 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29637 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49638 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
639 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17640 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17641 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41642 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54643 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
644 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29645 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18646 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
647 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29648 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48649 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55650 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
651 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
652 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
653 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
654 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
655 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
656 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45657 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40658 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29659 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19660 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
661 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29662 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
663 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
664 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51665 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
666 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29667 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04668 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15669 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29670 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
671 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08672 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
673 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00674 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16675 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14676 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25677 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
678 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47679 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]cda45c02010-02-25 19:28:10680 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
681 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51682 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56683 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36684 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34685 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14686#if defined(OS_MACOSX)
687 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13688 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13689 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
690 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14691#endif
[email protected]446705872009-09-10 07:22:48692 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33693 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33694 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
695 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24696 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42697 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
698 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19699 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
700 OnGetAllSavableResourceLinksForCurrentPage)
701 IPC_MESSAGE_HANDLER(
702 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
703 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08704#if defined(OS_MACOSX)
705 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
706#endif
[email protected]521b2482011-01-15 00:10:10707 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51708 // TODO(viettrungluu): Move to a separate message filter.
709#if defined(ENABLE_FLAPPER_HACKS)
710 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
711#endif
[email protected]54ca3ca892011-06-07 21:14:54712#if defined(OS_MACOSX)
713 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
714#endif
[email protected]9e1ad4b2011-08-14 16:49:19715 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
716 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18717 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]67bfb83f2011-09-22 03:36:37718 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
719 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
[email protected]7f3c7af2011-10-20 22:52:51720 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19721
initial.commit09911bf2008-07-26 23:55:29722 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28723 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29724 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40725
726 if (!msg_is_ok) {
727 // The message had a handler, but its deserialization failed.
728 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28729 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40730 }
731
[email protected]a95986a82010-12-24 06:19:28732 return handled;
initial.commit09911bf2008-07-26 23:55:29733}
734
[email protected]310ebd6302011-10-10 19:06:28735void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
initial.commit09911bf2008-07-26 23:55:29736 if (!webview())
737 return;
738
[email protected]440a0e52011-09-13 17:38:58739 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
740
[email protected]007733c2011-11-17 00:34:07741 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03742
743 // If this is a stale back/forward (due to a recent navigation the browser
744 // didn't know about), ignore it.
745 if (IsBackForwardToStaleEntry(params, is_reload))
746 return;
747
[email protected]992db4c2011-05-12 15:37:15748 // Swap this renderer back in if necessary.
749 if (is_swapped_out_)
750 SetSwappedOut(false);
751
[email protected]3cc72b12010-03-18 23:03:00752 history_list_offset_ = params.current_history_list_offset;
753 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03754 if (history_list_length_ >= 0)
755 history_page_ids_.resize(history_list_length_, -1);
756 if (params.pending_history_list_offset >= 0 &&
757 params.pending_history_list_offset < history_list_length_)
758 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00759
[email protected]38b592902011-04-16 02:08:42760 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29761
[email protected]26aa0482009-09-30 16:55:27762 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45763 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29764 // We cannot reload if we do not have any history state. This happens, for
765 // example, when recovering from a crash. Our workaround here is a bit of
766 // a hack since it means that reload after a crashed tab does not cause an
767 // end-to-end cache validation.
768 is_reload = false;
769 }
770
[email protected]007733c2011-11-17 00:34:07771 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
772 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50773
[email protected]04d3c6e2009-05-22 17:00:13774 // If we are reloading, then WebKit will use the history state of the current
775 // page, so we should just ignore any given history state. Otherwise, if we
776 // have history state, then we need to navigate to it, which corresponds to a
777 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55778 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29779 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02780 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29781 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55782 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13783 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58784 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45785 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17786 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13787 } else {
788 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28789 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29790
[email protected]e6f546c32009-07-01 17:12:55791 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23792 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13793
[email protected]dd7daa82009-08-10 05:46:45794 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55795 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13796
[email protected]445e1042011-12-03 21:03:15797 if (params.referrer.url.is_valid()) {
798 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
799 params.referrer.policy,
800 params.url,
801 WebString::fromUTF8(params.referrer.url.spec()));
802 if (!referrer.isEmpty())
803 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28804 }
[email protected]04d3c6e2009-05-22 17:00:13805
[email protected]52c68652010-12-07 17:47:04806 if (!params.extra_headers.empty()) {
807 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
808 params.extra_headers.end(), "\n");
809 i.GetNext(); ) {
810 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
811 WebString::fromUTF8(i.values()));
812 }
813 }
814
[email protected]dd7daa82009-08-10 05:46:45815 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50816 }
817
[email protected]77f17a82009-05-21 04:42:54818 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07819 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29820}
821
[email protected]310ebd6302011-10-10 19:06:28822bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03823 const ViewMsg_Navigate_Params& params,
824 bool is_reload) {
825 // Make sure this isn't a back/forward to an entry we have already cropped
826 // or replaced from our history, before the browser knew about it. If so,
827 // a new navigation has committed in the mean time, and we can ignore this.
828 bool is_back_forward = !is_reload && !params.state.empty();
829
830 // Note: if the history_list_length_ is 0 for a back/forward, we must be
831 // restoring from a previous session. We'll update our state in OnNavigate.
832 if (!is_back_forward || history_list_length_ <= 0)
833 return false;
834
835 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
836
837 // Check for whether the forward history has been cropped due to a recent
838 // navigation the browser didn't know about.
839 if (params.pending_history_list_offset >= history_list_length_)
840 return true;
841
842 // Check for whether this entry has been replaced with a new one.
843 int expected_page_id =
844 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44845 if (expected_page_id > 0 && params.page_id != expected_page_id) {
846 if (params.page_id < expected_page_id)
847 return true;
848
849 // Otherwise we've removed an earlier entry and should have shifted all
850 // entries left. For now, it's ok to lazily update the list.
851 // TODO(creis): Notify all live renderers when we remove entries from
852 // the front of the list, so that we don't hit this case.
853 history_page_ids_[params.pending_history_list_offset] = params.page_id;
854 }
[email protected]d466b8a2011-07-15 21:48:03855
856 return false;
857}
858
initial.commit09911bf2008-07-26 23:55:29859// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28860void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44861 if (webview()) {
862 WebFrame* main_frame = webview()->mainFrame();
863 // Stop the alt error page fetcher. If we let it continue it may complete
864 // and cause RenderViewHostManager to swap to this RenderView, even though
865 // it may no longer be active.
866 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
867 StopAltErrorPageFetcher(main_frame->dataSource());
868 main_frame->stopLoading();
869 }
initial.commit09911bf2008-07-26 23:55:29870}
871
[email protected]ecbf10d2010-02-18 13:03:29872// Reload current focused frame.
873// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28874void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29875 if (webview() && webview()->focusedFrame()) {
876 // We always obey the cache (ignore_cache=false) here.
877 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
878 // a cache-ignoring reload of the frame.
879 webview()->focusedFrame()->reload(false);
880 }
[email protected]1dda4022010-01-28 18:24:56881}
882
[email protected]310ebd6302011-10-10 19:06:28883void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27884 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29885}
886
[email protected]310ebd6302011-10-10 19:06:28887void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:25888 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27889 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25890 return;
891
[email protected]26aa0482009-09-30 16:55:27892 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45893 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25894}
895
[email protected]310ebd6302011-10-10 19:06:28896void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:29897 // Check if there is a targeturl waiting to be sent.
898 if (target_url_status_ == TARGET_PENDING) {
899 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
900 pending_target_url_));
901 }
902
903 target_url_status_ = TARGET_NONE;
904}
905
[email protected]310ebd6302011-10-10 19:06:28906void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:29907 if (!webview())
908 return;
909
[email protected]26aa0482009-09-30 16:55:27910 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29911}
912
[email protected]310ebd6302011-10-10 19:06:28913void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:29914 if (!webview())
915 return;
916
[email protected]26aa0482009-09-30 16:55:27917 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29918}
919
[email protected]310ebd6302011-10-10 19:06:28920void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:29921 if (!webview())
922 return;
923
[email protected]26aa0482009-09-30 16:55:27924 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29925}
926
[email protected]310ebd6302011-10-10 19:06:28927void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:29928 if (!webview())
929 return;
930
[email protected]f6b1856b2011-06-29 22:02:53931 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
932 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29933}
934
[email protected]c0cc3092009-09-12 08:27:27935#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:28936void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:35937 if (!webview())
938 return;
939
940 // Since the find pasteboard supports only plain text, this can be simpler
941 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27942 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35943 if (frame->hasSelection()) {
944 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:27945 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:17946 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35947 }
[email protected]a954bf72009-09-12 07:30:35948}
[email protected]c0cc3092009-09-12 08:27:27949#endif
[email protected]a954bf72009-09-12 07:30:35950
[email protected]310ebd6302011-10-10 19:06:28951void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:29952 if (!webview())
953 return;
954
[email protected]26aa0482009-09-30 16:55:27955 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29956}
957
[email protected]44bf7002011-10-16 02:46:15958void RenderViewImpl::OnPasteAndMatchStyle() {
959 if (!webview())
960 return;
961
962 webview()->focusedFrame()->executeCommand(
963 WebString::fromUTF8("PasteAndMatchStyle"));
964}
965
[email protected]310ebd6302011-10-10 19:06:28966void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29967 if (!webview())
968 return;
969
[email protected]1ff7a032010-02-03 02:46:03970 WebFrame* frame = webview()->focusedFrame();
971 if (!frame->hasSelection())
972 frame->selectWordAroundCaret();
973 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29974}
975
[email protected]310ebd6302011-10-10 19:06:28976void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:29977 if (!webview())
978 return;
979
[email protected]26aa0482009-09-30 16:55:27980 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29981}
982
[email protected]310ebd6302011-10-10 19:06:28983void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:29984 if (!webview())
985 return;
986
[email protected]26aa0482009-09-30 16:55:27987 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22988 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29989}
990
[email protected]310ebd6302011-10-10 19:06:28991void RenderViewImpl::OnSelectRange(const gfx::Point& start,
992 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:08993 if (!webview())
994 return;
995
996 handling_select_range_ = true;
997 webview()->focusedFrame()->selectRange(start, end);
998 handling_select_range_ = false;
999}
1000
[email protected]310ebd6302011-10-10 19:06:281001void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1002 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191003 DCHECK(history_length >= 0);
1004 DCHECK(history_list_offset_ == history_list_length_ - 1);
1005 DCHECK(minimum_page_id >= -1);
1006
1007 // Generate the new list.
1008 std::vector<int32> new_history_page_ids(history_length, -1);
1009 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1010 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1011 continue;
1012 new_history_page_ids.push_back(history_page_ids_[i]);
1013 }
1014 new_history_page_ids.swap(history_page_ids_);
1015
1016 // Update indexes.
1017 history_list_length_ = history_page_ids_.size();
1018 history_list_offset_ = history_list_length_ - 1;
1019}
1020
1021
[email protected]310ebd6302011-10-10 19:06:281022void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291023 if (!webview())
1024 return;
[email protected]26aa0482009-09-30 16:55:271025 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291026}
1027
[email protected]54ca3ca892011-06-07 21:14:541028#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281029void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331030 if (!webview())
1031 return;
1032 if (in_live_resize)
1033 webview()->willStartLiveResize();
1034 else
1035 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541036}
1037#endif
1038
[email protected]310ebd6302011-10-10 19:06:281039void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1040 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091041 WebKit::WebNode node = GetFocusedNode();
1042 if (!node.isNull()) {
1043 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191044 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511045 }
1046}
1047
initial.commit09911bf2008-07-26 23:55:291048///////////////////////////////////////////////////////////////////////////////
1049
1050// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281051void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451052 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291053 DCHECK(ds);
1054
[email protected]726985e22009-06-18 21:09:281055 const WebURLRequest& request = ds->request();
1056 const WebURLRequest& original_request = ds->originalRequest();
1057 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291058
[email protected]007733c2011-11-17 00:34:071059 DocumentState* document_state = DocumentState::FromDataSource(ds);
1060 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291061
1062 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281063 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291064 params.is_post = false;
1065 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071066 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191067 params.socket_address.set_host(response.remoteIPAddress().utf8());
1068 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031069 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091070 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071071 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291072 // SSL state specified in the request takes precedence over the one in the
1073 // response.
1074 // So far this is only intended for error pages that are not expected to be
1075 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281076 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071077 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291078 } else {
[email protected]726985e22009-06-18 21:09:281079 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291080 }
1081
1082 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281083 if (ds->hasUnreachableURL()) {
1084 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291085 } else {
[email protected]726985e22009-06-18 21:09:281086 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291087 }
1088
[email protected]5f9b8712011-11-23 08:55:571089 if (frame->document().baseURL() != params.url)
1090 params.base_url = frame->document().baseURL();
1091
[email protected]726985e22009-06-18 21:09:281092 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241093 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041094 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291095
[email protected]007733c2011-11-17 00:34:071096 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351097 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071098 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291099
1100 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071101 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291102 if (password_form_data)
1103 params.password_form = *password_form_data;
1104
1105 params.gesture = navigation_gesture_;
1106 navigation_gesture_ = NavigationGestureUnknown;
1107
[email protected]0f38dc4552011-02-25 11:24:001108 // Make navigation state a part of the FrameNavigate message so that commited
1109 // entry had it at all times.
1110 const WebHistoryItem& item = frame->currentHistoryItem();
1111 if (!item.isNull()) {
1112 params.content_state = webkit_glue::HistoryItemToString(item);
1113 } else {
1114 params.content_state =
1115 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1116 }
1117
[email protected]dd7daa82009-08-10 05:46:451118 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291119 // Top-level navigation.
1120
[email protected]b75b8292010-10-01 07:28:251121 // Set zoom level, but don't do it for full-page plugin since they don't use
1122 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011123 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541124 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251125 if (webview()->mainFrame()->document().isPluginDocument()) {
1126 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251127 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251128 } else {
1129 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251130 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251131 }
1132
[email protected]f85f0702010-01-30 09:31:011133 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511134 // This zoom level was merely recorded transiently for this load. We can
1135 // erase it now. If at some point we reload this page, the browser will
1136 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011137 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511138 }
1139
[email protected]b75b8292010-10-01 07:28:251140 // Reset the zoom limits in case a plugin had changed them previously. This
1141 // will also call us back which will cause us to send a message to
1142 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251143 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011144 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1145 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251146
initial.commit09911bf2008-07-26 23:55:291147 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551148 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291149
[email protected]daa8c58e2009-06-15 17:21:101150 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581151 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291152 // If the main frame does a load, it should not be reported as a subframe
1153 // navigation. This can occur in the following case:
1154 // 1. You're on a site with frames.
1155 // 2. You do a subframe navigation. This is stored with transition type
1156 // MANUAL_SUBFRAME.
1157 // 3. You navigate to some non-frame site, say, google.com.
1158 // 4. You navigate back to the page from step 2. Since it was initially
1159 // MANUAL_SUBFRAME, it will be that same transition type here.
1160 // We don't want that, because any navigation that changes the toplevel
1161 // frame should be tracked as a toplevel navigation (this allows us to
1162 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581163 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291164 }
1165
initial.commit09911bf2008-07-26 23:55:291166 // If we have a valid consumed client redirect source,
1167 // the page contained a client redirect (meta refresh, document.loc...),
1168 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151169 if (completed_client_redirect_src_.url.is_valid()) {
1170 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291171 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581172 params.transition = static_cast<content::PageTransition>(
1173 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291174 } else {
1175 // Bug 654101: the referrer will be empty on https->http transitions. It
1176 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151177 params.referrer = Referrer(GURL(
1178 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
1179 getReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291180 }
1181
[email protected]726985e22009-06-18 21:09:281182 string16 method = request.httpMethod();
1183 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291184 params.is_post = true;
1185
[email protected]c2a797d2009-09-21 16:46:321186 // Save some histogram data so we can compute the average memory used per
1187 // page load of the glyphs.
1188 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1189 webkit_glue::GetGlyphPageCount());
1190
[email protected]15cf526b2010-02-12 06:33:491191 // This message needs to be sent before any of allowScripts(),
1192 // allowImages(), allowPlugins() is called for the new page, so that when
1193 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1194 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291195 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1196 } else {
1197 // Subframe navigation: the type depends on whether this navigation
1198 // generated a new session history entry. When they do generate a session
1199 // history entry, it means the user initiated the navigation and we should
1200 // mark it as such. This test checks if this is the first time UpdateURL
1201 // has been called since WillNavigateToURL was called to initiate the load.
1202 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581203 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291204 else
[email protected]2905f742011-10-13 03:51:581205 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291206
initial.commit09911bf2008-07-26 23:55:291207 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1208 }
1209
1210 last_page_id_sent_to_browser_ =
1211 std::max(last_page_id_sent_to_browser_, page_id_);
1212
1213 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101214 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581215 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291216}
1217
1218// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281219void RenderViewImpl::UpdateTitle(WebFrame* frame,
1220 const string16& title,
1221 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461222 // Ignore all but top level navigations.
1223 if (frame->parent())
1224 return;
1225
1226 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1227 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1228 title_direction));
initial.commit09911bf2008-07-26 23:55:291229}
1230
[email protected]310ebd6302011-10-10 19:06:281231void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1232 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291233 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271234 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291235 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301236 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291237 last_encoding_name_ = encoding_name;
1238
[email protected]e38f40152008-09-12 23:08:301239 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291240 }
1241}
1242
[email protected]e15f680732010-11-23 22:30:201243// Sends the last committed session history state to the browser so it will be
1244// saved before we navigate to a new page. This must be called *before* the
1245// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281246void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291247 // If we have a valid page ID at this point, then it corresponds to the page
1248 // we are navigating away from. Otherwise, this is the first navigation, so
1249 // there is no past session history to record.
1250 if (page_id_ == -1)
1251 return;
1252
[email protected]ca948a22009-06-25 19:36:171253 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271254 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171255 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291256 return;
[email protected]ca948a22009-06-25 19:36:171257
1258 Send(new ViewHostMsg_UpdateState(
1259 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291260}
1261
[email protected]310ebd6302011-10-10 19:06:281262void RenderViewImpl::OpenURL(WebFrame* frame,
1263 const GURL& url,
[email protected]445e1042011-12-03 21:03:151264 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281265 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171266 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581267 routing_id_,
1268 url,
1269 referrer,
1270 NavigationPolicyToDisposition(policy),
1271 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171272}
1273
[email protected]79dbc662009-09-04 05:42:511274// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291275
[email protected]310ebd6302011-10-10 19:06:281276void RenderViewImpl::LoadNavigationErrorPage(
1277 WebFrame* frame,
1278 const WebURLRequest& failed_request,
1279 const WebURLError& error,
1280 const std::string& html,
1281 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581282 std::string alt_html;
1283 const std::string* error_html;
1284
1285 if (!html.empty()) {
1286 error_html = &html;
1287 } else {
1288 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1289 failed_request, error, &alt_html, NULL);
1290 error_html = &alt_html;
1291 }
1292
1293 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361294 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251295 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551296 replace);
initial.commit09911bf2008-07-26 23:55:291297}
1298
[email protected]269f86d2011-12-07 02:43:471299bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281300 const string16& message,
1301 const string16& default_value,
1302 const GURL& frame_url,
1303 string16* result) {
initial.commit09911bf2008-07-26 23:55:291304 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411305 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291306 if (!result)
1307 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291308
[email protected]12636df2009-09-28 22:32:211309 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1310 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291311 return success;
1312}
1313
[email protected]310ebd6302011-10-10 19:06:281314bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571315 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1316 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1317 // it is particularly important that we do not call willEnterModalLoop as
1318 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441319 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1320 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571321
1322 message->EnableMessagePumping(); // Runs a nested message loop.
1323 return Send(message);
1324}
1325
[email protected]48c9cf2d2009-09-16 16:47:521326// WebKit::WebViewClient ------------------------------------------------------
1327
[email protected]310ebd6302011-10-10 19:06:281328WebView* RenderViewImpl::createView(
[email protected]844acf372011-01-14 10:49:271329 WebFrame* creator,
1330 const WebURLRequest& request,
1331 const WebWindowFeatures& features,
1332 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521333 // Check to make sure we aren't overloading on popups.
1334 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1335 return NULL;
1336
[email protected]8ab04652010-06-12 02:47:261337 ViewHostMsg_CreateWindow_Params params;
1338 params.opener_id = routing_id_;
1339 params.user_gesture = creator->isProcessingUserGesture();
1340 params.window_container_type = WindowFeaturesToContainerType(features);
1341 params.session_storage_namespace_id = session_storage_namespace_id_;
1342 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111343 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411344 params.opener_url = creator->document().url();
1345 params.opener_security_origin =
1346 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111347 if (!request.isNull())
1348 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261349
[email protected]48c9cf2d2009-09-16 16:47:521350 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561351 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341352 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261353 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521354
[email protected]380244092011-10-07 17:26:271355 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261356 new ViewHostMsg_CreateWindow(params,
1357 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561358 &surface_id,
[email protected]8ab04652010-06-12 02:47:261359 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211360 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521361 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521362
[email protected]310ebd6302011-10-10 19:06:281363 RenderViewImpl* view = RenderViewImpl::Create(
1364 0,
1365 routing_id_,
1366 renderer_preferences_,
1367 webkit_preferences_,
1368 shared_popup_counter_,
1369 routing_id,
[email protected]9f4f3322012-01-18 22:29:561370 surface_id,
[email protected]310ebd6302011-10-10 19:06:281371 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461372 frame_name,
1373 1);
[email protected]8ab04652010-06-12 02:47:261374 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521375
[email protected]007a848b2009-10-26 15:55:461376 // Record whether the creator frame is trying to suppress the opener field.
1377 view->opener_suppressed_ = opener_suppressed;
1378
[email protected]48c9cf2d2009-09-16 16:47:521379 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411380 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521381 if (!creator_url.is_valid() || !creator_url.IsStandard())
1382 creator_url = GURL();
1383 view->creator_url_ = creator_url;
1384
1385 // Copy over the alternate error page URL so we can have alt error pages in
1386 // the new render view (we don't need the browser to send the URL back down).
1387 view->alternate_error_page_url_ = alternate_error_page_url_;
1388
1389 return view->webview();
1390}
1391
[email protected]310ebd6302011-10-10 19:06:281392WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]380244092011-10-07 17:26:271393 RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521394 return widget->webwidget();
1395}
1396
[email protected]310ebd6302011-10-10 19:06:281397WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441398 // TODO(jcivelli): Remove this deprecated method when its been removed from
1399 // the WebViewClient interface. It's been replaced by
1400 // createExternalPopupMenu.
1401 NOTREACHED();
1402 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521403}
1404
[email protected]310ebd6302011-10-10 19:06:281405WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081406 const WebPopupMenuInfo& popup_menu_info,
1407 WebExternalPopupMenuClient* popup_menu_client) {
1408 DCHECK(!external_popup_menu_.get());
1409 external_popup_menu_.reset(
1410 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1411 return external_popup_menu_.get();
1412}
1413
[email protected]310ebd6302011-10-10 19:06:281414RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521415 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531416 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421417 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411418 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531419 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271420 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391421 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561422 return widget;
[email protected]79c7bed2010-09-14 22:28:391423}
1424
[email protected]310ebd6302011-10-10 19:06:281425WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1426 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341427 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391428 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291429 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1430 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1431 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341432}
1433
[email protected]310ebd6302011-10-10 19:06:281434void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521435 const WebConsoleMessage& message, const WebString& source_name,
1436 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081437 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511438 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081439 case WebConsoleMessage::LevelTip:
1440 log_severity = logging::LOG_VERBOSE;
1441 break;
1442 case WebConsoleMessage::LevelLog:
1443 log_severity = logging::LOG_INFO;
1444 break;
1445 case WebConsoleMessage::LevelWarning:
1446 log_severity = logging::LOG_WARNING;
1447 break;
1448 case WebConsoleMessage::LevelError:
1449 log_severity = logging::LOG_ERROR;
1450 break;
1451 default:
1452 NOTREACHED();
1453 }
1454
[email protected]48c9cf2d2009-09-16 16:47:521455 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081456 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311457 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521458 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311459 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521460}
1461
[email protected]310ebd6302011-10-10 19:06:281462void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421463 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521464}
1465
[email protected]310ebd6302011-10-10 19:06:281466WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511467 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021468}
1469
[email protected]310ebd6302011-10-10 19:06:281470bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121471 const WebString& path,
1472 WebFileChooserCompletion* chooser_completion) {
1473 int id = enumeration_completion_id_++;
1474 enumeration_completions_[id] = chooser_completion;
1475 return Send(new ViewHostMsg_EnumerateDirectory(
1476 routing_id_,
1477 id,
1478 webkit_glue::WebStringToFilePath(path)));
1479}
1480
[email protected]310ebd6302011-10-10 19:06:281481void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521482 if (is_loading_) {
1483 DLOG(WARNING) << "didStartLoading called while loading";
1484 return;
1485 }
1486
1487 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521488
1489 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311490
1491 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521492}
1493
[email protected]310ebd6302011-10-10 19:06:281494void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521495 if (!is_loading_) {
1496 DLOG(WARNING) << "DidStopLoading called while not loading";
1497 return;
1498 }
1499
1500 is_loading_ = false;
1501
1502 // NOTE: For now we're doing the safest thing, and sending out notification
1503 // when done loading. This currently isn't an issue as the favicon is only
1504 // displayed when done loading. Ideally we would send notification when
1505 // finished parsing the head, but webkit doesn't support that yet.
1506 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521507 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1508
[email protected]90109412010-12-15 17:14:241509 if (load_progress_tracker_ != NULL)
1510 load_progress_tracker_->DidStopLoading();
1511
[email protected]93b9d692011-04-13 00:44:311512 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521513}
1514
[email protected]310ebd6302011-10-10 19:06:281515void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1516 double load_progress) {
[email protected]90109412010-12-15 17:14:241517 if (load_progress_tracker_ != NULL)
1518 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1519}
1520
[email protected]310ebd6302011-10-10 19:06:281521bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061522#if defined(OS_MACOSX)
1523 return true;
1524#else
1525 return false;
1526#endif
1527}
1528
[email protected]310ebd6302011-10-10 19:06:281529bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031530#if defined(OS_WIN)
1531 return true;
1532#else
1533 return false;
1534#endif
1535}
1536
[email protected]310ebd6302011-10-10 19:06:281537void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081538 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031539 return;
[email protected]4fb60142011-08-09 02:22:081540 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011541
[email protected]b781ff282011-08-20 06:19:361542 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031543}
1544
[email protected]310ebd6302011-10-10 19:06:281545void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121546 const std::string& name = UTF16ToUTF8(command_name);
1547 if (StartsWithASCII(name, "Move", true) ||
1548 StartsWithASCII(name, "Insert", true) ||
1549 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031550 return;
[email protected]f1a29a02011-10-06 23:08:441551 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031552}
1553
[email protected]310ebd6302011-10-10 19:06:281554bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101555 if (edit_commands_.empty())
1556 return false;
1557
[email protected]26aa0482009-09-30 16:55:271558 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101559 if (!frame)
1560 return false;
1561
1562 EditCommands::iterator it = edit_commands_.begin();
1563 EditCommands::iterator end = edit_commands_.end();
1564
[email protected]507b33ea2009-09-29 03:56:511565 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101566 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331567 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1568 // key (but it's the exception). Once one edit command is not executed, it
1569 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101570 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1571 WebString::fromUTF8(it->value)))
1572 break;
[email protected]507b33ea2009-09-29 03:56:511573 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101574 }
1575
[email protected]507b33ea2009-09-29 03:56:511576 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101577}
1578
[email protected]310ebd6302011-10-10 19:06:281579bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351580 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471581 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351582 // Do not open the file dialog in a hidden RenderView.
1583 if (is_hidden())
1584 return false;
[email protected]8caadeb2011-11-22 02:45:231585 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261586 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231587 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261588 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231589 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501590 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231591 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261592 else
[email protected]8caadeb2011-11-22 02:45:231593 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471594 ipc_params.title = params.title;
1595 ipc_params.default_file_name =
1596 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461597 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1598 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1599 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471600
1601 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461602}
1603
[email protected]269f86d2011-12-07 02:43:471604void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1605 const WebString& message) {
1606 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411607 message,
1608 string16(),
[email protected]b6cb3a842011-06-24 18:28:411609 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521610 NULL);
1611}
1612
[email protected]269f86d2011-12-07 02:43:471613bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1614 const WebString& message) {
1615 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411616 message,
1617 string16(),
[email protected]b6cb3a842011-06-24 18:28:411618 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521619 NULL);
1620}
1621
[email protected]269f86d2011-12-07 02:43:471622bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1623 const WebString& message,
1624 const WebString& default_value,
1625 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411626 string16 result;
[email protected]269f86d2011-12-07 02:43:471627 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411628 message,
1629 default_value,
[email protected]b6cb3a842011-06-24 18:28:411630 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521631 &result);
1632 if (ok)
[email protected]4f5ce842011-05-27 19:34:411633 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521634 return ok;
1635}
1636
[email protected]310ebd6302011-10-10 19:06:281637bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521638 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151639 // If we are swapping out, we have already run the beforeunload handler.
1640 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1641 // at all, to avoid running it twice.
1642 if (is_swapped_out_)
1643 return true;
1644
[email protected]48c9cf2d2009-09-16 16:47:521645 bool success = false;
1646 // This is an ignored return value, but is included so we can accept the same
1647 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411648 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211649 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411650 routing_id_, frame->document().url(), message,
1651 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521652 return success;
1653}
1654
[email protected]310ebd6302011-10-10 19:06:281655void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441656 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291657 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371658
1659 // frame is NULL if invoked by BlockedPlugin.
1660 if (frame)
1661 params.frame_id = frame->identifier();
1662
[email protected]db803aae2011-03-05 02:00:421663 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271664 // it. We replace it with an empty GURL so the appropriate items are disabled
1665 // in the context menu.
1666 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1667 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421668 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271669 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101670 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291671 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441672}
1673
[email protected]310ebd6302011-10-10 19:06:281674void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261675 // TODO(darin): Remove once WebKit roll is complete.
1676 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471677}
1678
[email protected]310ebd6302011-10-10 19:06:281679void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261680 // TODO(darin): Remove once WebKit roll is complete.
1681 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471682}
1683
[email protected]310ebd6302011-10-10 19:06:281684void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521685}
1686
[email protected]310ebd6302011-10-10 19:06:281687void RenderViewImpl::UpdateTargetURL(const GURL& url,
1688 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581689 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521690 if (latest_url == target_url_)
1691 return;
[email protected]163f8242009-10-30 20:19:551692
[email protected]48c9cf2d2009-09-16 16:47:521693 // Tell the browser to display a destination link.
1694 if (target_url_status_ == TARGET_INFLIGHT ||
1695 target_url_status_ == TARGET_PENDING) {
1696 // If we have a request in-flight, save the URL to be sent when we
1697 // receive an ACK to the in-flight request. We can happily overwrite
1698 // any existing pending sends.
1699 pending_target_url_ = latest_url;
1700 target_url_status_ = TARGET_PENDING;
1701 } else {
[email protected]c85f0212011-11-04 16:54:411702 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1703 // see |ParamTraits<GURL>|.
1704 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1705 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521706 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1707 target_url_ = latest_url;
1708 target_url_status_ = TARGET_INFLIGHT;
1709 }
1710}
1711
[email protected]310ebd6302011-10-10 19:06:281712void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311713 int delay;
1714 if (send_content_state_immediately_)
1715 delay = 0;
1716 else if (is_hidden())
1717 delay = kDelaySecondsForContentStateSyncHidden;
1718 else
1719 delay = kDelaySecondsForContentStateSync;
1720
1721 if (nav_state_sync_timer_.IsRunning()) {
1722 // The timer is already running. If the delay of the timer maches the amount
1723 // we want to delay by, then return. Otherwise stop the timer so that it
1724 // gets started with the right delay.
1725 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1726 return;
1727 nav_state_sync_timer_.Stop();
1728 }
1729
[email protected]d323a172011-09-02 18:23:021730 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281731 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311732}
1733
[email protected]310ebd6302011-10-10 19:06:281734void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551735 mouse_over_url_ = GURL(url);
1736 UpdateTargetURL(mouse_over_url_, focus_url_);
1737}
1738
[email protected]310ebd6302011-10-10 19:06:281739void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551740 focus_url_ = GURL(url);
1741 UpdateTargetURL(focus_url_, mouse_over_url_);
1742}
1743
[email protected]310ebd6302011-10-10 19:06:281744void RenderViewImpl::startDragging(const WebDragData& data,
1745 WebDragOperationsMask mask,
1746 const WebImage& image,
1747 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411748#if WEBKIT_USING_SKIA
1749 SkBitmap bitmap(image.getSkBitmap());
1750#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331751 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411752#endif
1753
[email protected]59f4f2fa2011-03-23 01:00:551754 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521755 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411756 mask,
1757 bitmap,
1758 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521759}
1760
[email protected]310ebd6302011-10-10 19:06:281761bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451762 return renderer_preferences_.can_accept_load_drops;
1763}
1764
[email protected]310ebd6302011-10-10 19:06:281765void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521766 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1767}
1768
[email protected]310ebd6302011-10-10 19:06:281769void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521770 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1771}
1772
[email protected]310ebd6302011-10-10 19:06:281773void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511774 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071775
[email protected]38b592902011-04-16 02:08:421776 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491777}
1778
[email protected]169d4282011-11-30 19:33:591779void RenderViewImpl::didUpdateLayout() {
1780 // We don't always want to set up a timer, only if we've been put in that
1781 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1782 // message.
1783 if (!send_preferred_size_changes_ || !webview())
1784 return;
1785
1786 if (check_preferred_size_timer_.IsRunning())
1787 return;
1788 check_preferred_size_timer_.Start(FROM_HERE,
1789 TimeDelta::FromMilliseconds(0), this,
1790 &RenderViewImpl::CheckPreferredSize);
1791}
1792
[email protected]310ebd6302011-10-10 19:06:281793void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521794 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1795}
1796
[email protected]310ebd6302011-10-10 19:06:281797int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001798 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521799}
1800
[email protected]310ebd6302011-10-10 19:06:281801int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001802 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521803}
1804
[email protected]310ebd6302011-10-10 19:06:281805void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321806 const WebAccessibilityObject& obj,
1807 WebAccessibilityNotification notification) {
1808 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1809}
1810
[email protected]310ebd6302011-10-10 19:06:281811void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141812 const WebString& value) {
1813 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1814 key.utf8(),
1815 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261816}
1817
[email protected]79dbc662009-09-04 05:42:511818// WebKit::WebWidgetClient ----------------------------------------------------
1819
[email protected]310ebd6302011-10-10 19:06:281820void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121821 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1822 // we won't have to test for user gesture anymore and we can
1823 // move that code back to render_widget.cc
1824 if (webview() && webview()->mainFrame() &&
1825 webview()->mainFrame()->isProcessingUserGesture()) {
1826 Send(new ViewHostMsg_Focus(routing_id_));
1827 }
1828}
1829
[email protected]310ebd6302011-10-10 19:06:281830void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121831 // TODO(jcivelli): see TODO above in didFocus().
1832 if (webview() && webview()->mainFrame() &&
1833 webview()->mainFrame()->isProcessingUserGesture()) {
1834 Send(new ViewHostMsg_Blur(routing_id_));
1835 }
1836}
1837
initial.commit09911bf2008-07-26 23:55:291838// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281839// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291840// point to dispatch the ShowView message.
1841//
1842// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281843// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291844//
[email protected]310ebd6302011-10-10 19:06:281845void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291846 DCHECK(!did_show_) << "received extraneous Show call";
1847 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1848
1849 if (did_show_)
1850 return;
1851 did_show_ = true;
1852
[email protected]6779aa12011-03-29 17:32:241853 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041854 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041855
[email protected]28295ec2009-10-16 05:34:331856 // Force new windows to a popup if they were not opened with a user gesture.
1857 if (!opened_by_user_gesture_) {
1858 // We exempt background tabs for compat with older versions of Chrome.
1859 // TODO(darin): This seems bogus. These should have a user gesture, so
1860 // we probably don't need this check.
1861 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1862 policy = WebKit::WebNavigationPolicyNewPopup;
1863 }
1864
initial.commit09911bf2008-07-26 23:55:291865 // NOTE: initial_pos_ may still have its default values at this point, but
1866 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1867 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281868 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1869 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291870 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241871 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291872}
1873
[email protected]310ebd6302011-10-10 19:06:281874void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:291875 DCHECK(did_show_) << "should already have shown the view";
1876
[email protected]c1f50aa2010-02-18 03:46:571877 // We must keep WebKit's shared timer running in this case in order to allow
1878 // showModalDialog to function properly.
1879 //
1880 // TODO(darin): WebKit should really be smarter about suppressing events and
1881 // timers so that we do not need to manage the shared timer in such a heavy
1882 // handed manner.
1883 //
[email protected]f1a29a02011-10-06 23:08:441884 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1885 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:571886
[email protected]12636df2009-09-28 22:32:211887 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291888}
1889
[email protected]2b624c562011-10-27 22:58:261890bool RenderViewImpl::enterFullScreen() {
1891 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1892 return true;
1893}
1894
1895void RenderViewImpl::exitFullScreen() {
1896 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1897}
1898
[email protected]3d9689372009-09-10 04:29:171899// WebKit::WebFrameClient -----------------------------------------------------
1900
[email protected]310ebd6302011-10-10 19:06:281901WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
1902 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:551903 WebPlugin* plugin = NULL;
1904 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
1905 this, frame, params, &plugin)) {
1906 return plugin;
1907 }
1908
[email protected]a813c8e2011-10-08 01:34:111909 webkit::WebPluginInfo info;
1910 std::string mime_type;
1911 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
1912 params.mimeType.utf8(), &info, &mime_type);
1913 if (!found)
1914 return NULL;
1915
1916 WebPluginParams params_to_use = params;
1917 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:311918 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:171919}
1920
[email protected]310ebd6302011-10-10 19:06:281921WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:421922 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371923 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421924
[email protected]30447b62009-11-13 01:13:371925 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511926 bool exists = false;
[email protected]30447b62009-11-13 01:13:371927 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511928 ViewHostMsg_CreateWorker_Params params;
1929 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:511930 params.name = name;
1931 params.document_id = document_id;
1932 params.render_view_route_id = routing_id_;
1933 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231934 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371935 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511936 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371937 if (url_mismatch) {
1938 return NULL;
1939 } else {
[email protected]f1a29a02011-10-06 23:08:441940 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:491941 document_id,
[email protected]6de0bcf2010-02-17 22:00:511942 exists,
[email protected]30447b62009-11-13 01:13:371943 route_id,
1944 routing_id_);
1945 }
[email protected]9c00f002009-11-05 22:37:421946}
1947
[email protected]310ebd6302011-10-10 19:06:281948WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:171949 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441950 FOR_EACH_OBSERVER(
1951 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171952
[email protected]bb6fd402011-12-09 02:45:441953 media::MessageLoopFactory* message_loop_factory =
1954 new media::MessageLoopFactoryImpl();
1955 media::FilterCollection* collection = new media::FilterCollection();
1956 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:371957
[email protected]9e2269d2012-01-07 00:06:211958 RenderAudioSourceProvider* audio_source_provider = NULL;
1959
[email protected]3d9689372009-09-10 04:29:171960 // Add in any custom filter factories first.
1961 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1962 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:211963 // audio_source_provider is a "provider" to WebKit, and a sink
1964 // from the perspective of the audio renderer.
1965 audio_source_provider = new RenderAudioSourceProvider();
1966
1967 // Add the chrome specific audio renderer, using audio_source_provider
1968 // as the sink.
1969 AudioRendererImpl* audio_renderer =
1970 new AudioRendererImpl(audio_source_provider);
1971 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:171972 }
1973
[email protected]e1d69d762011-12-13 05:12:181974#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
1975 // Currently only cros/arm has any HW video decode support in
1976 // GpuVideoDecodeAccelerator so we don't even try to use it on other
1977 // platforms. This is a startup-time optimization. When new VDA
1978 // implementations are added, relax the #if above.
1979 WebKit::WebGraphicsContext3D* wk_context3d = webview()->graphicsContext3D();
1980 if (wk_context3d) {
1981 WebGraphicsContext3DCommandBufferImpl* context3d =
1982 static_cast<WebGraphicsContext3DCommandBufferImpl*>(wk_context3d);
1983 GpuChannelHost* gpu_channel_host =
1984 RenderThreadImpl::current()->EstablishGpuChannelSync(
1985 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
1986 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:311987 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
1988 new RendererGpuVideoDecoderFactories(
1989 gpu_channel_host, context3d->context()->AsWeakPtr())));
[email protected]e1d69d762011-12-13 05:12:181990 }
1991#endif
1992
[email protected]da952fd2012-01-13 03:49:251993 webkit_media::WebMediaPlayerImpl* media_player =
1994 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
1995 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
1996 message_loop_factory, media_stream_impl_.get(), render_media_log);
1997 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:561998 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:251999 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]9e2269d2012-01-07 00:06:212000 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]bb6fd402011-12-09 02:45:442001 }
[email protected]cec4eb82012-01-12 17:51:562002 return media_player;
[email protected]3d9689372009-09-10 04:29:172003}
2004
[email protected]310ebd6302011-10-10 19:06:282005WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212006 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232007 if (!frame || !frame->view())
2008 return NULL;
[email protected]035545f2010-04-09 13:10:212009 return new RendererWebApplicationCacheHostImpl(
2010 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442011 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212012}
2013
[email protected]310ebd6302011-10-10 19:06:282014WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382015 return &cookie_jar_;
2016}
2017
[email protected]310ebd6302011-10-10 19:06:282018void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512019 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452020}
2021
[email protected]310ebd6302011-10-10 19:06:282022void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512023 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172024}
2025
[email protected]310ebd6302011-10-10 19:06:282026void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172027 WebFrame* frame, const WebURLRequest& request,
2028 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342029 loadURLExternally(frame, request, policy, WebString());
2030}
2031
[email protected]310ebd6302011-10-10 19:06:282032void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342033 WebFrame* frame, const WebURLRequest& request,
2034 WebNavigationPolicy policy,
2035 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592036 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2037 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342038 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2039 suggested_name));
[email protected]efce17b2009-09-11 18:04:592040 } else {
[email protected]445e1042011-12-03 21:03:152041 OpenURL(frame, request.url(),
2042 Referrer(referrer, getReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592043 }
[email protected]3d9689372009-09-10 04:29:172044}
2045
[email protected]310ebd6302011-10-10 19:06:282046WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172047 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222048 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152049 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2050 if (is_swapped_out_) {
2051 DCHECK(request.url() == GURL("about:swappedout"));
2052 return default_policy;
2053 }
2054
[email protected]3d9689372009-09-10 04:29:172055 // Webkit is asking whether to navigate to a new URL.
2056 // This is fine normally, except if we're showing UI from one security
2057 // context and they're trying to navigate to a different context.
2058 const GURL& url = request.url();
2059
[email protected]d19ea342011-04-20 20:31:132060 // A content initiated navigation may have originated from a link-click,
2061 // script, drag-n-drop operation, etc.
2062 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072063 DocumentState::FromDataSource(frame->provisionalDataSource())->
2064 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132065
[email protected]a8c269a2011-10-25 20:17:222066 // Experimental:
2067 // If --enable-strict-site-isolation is enabled, send all top-level
2068 // navigations to the browser to let it swap processes when crossing site
2069 // boundaries. This is currently expected to break some script calls and
2070 // navigations, such as form submissions.
2071 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102072 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2073 !frame->parent() && (is_content_initiated || is_redirect)) {
2074 WebString origin_str = frame->document().securityOrigin().toString();
2075 GURL frame_url(origin_str.utf8().data());
2076 // TODO(cevans): revisit whether this origin check is still necessary once
2077 // crbug.com/101395 is fixed.
2078 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]445e1042011-12-03 21:03:152079 Referrer referrer(
2080 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2081 getReferrerPolicyFromRequest(request));
[email protected]313b80bd2011-11-23 03:49:102082 OpenURL(frame, url, referrer, default_policy);
2083 return WebKit::WebNavigationPolicyIgnore;
2084 }
[email protected]a8c269a2011-10-25 20:17:222085 }
2086
[email protected]3d9689372009-09-10 04:29:172087 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302088 // navigations.
[email protected]5f000f272012-01-19 05:25:082089 if (is_content_initiated) {
2090 bool browser_handles_top_level_requests =
2091 renderer_preferences_.browser_handles_top_level_requests &&
2092 IsNonLocalTopLevelNavigation(url, frame, type);
2093 if (browser_handles_top_level_requests ||
2094 renderer_preferences_.browser_handles_all_requests) {
2095 Referrer referrer(
2096 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2097 getReferrerPolicyFromRequest(request));
2098 // Reset these counters as the RenderView could be reused for the next
2099 // navigation.
2100 page_id_ = -1;
2101 last_page_id_sent_to_browser_ = -1;
2102 OpenURL(frame, url, referrer, default_policy);
2103 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2104 }
[email protected]3d9689372009-09-10 04:29:172105 }
2106
[email protected]6101c342010-12-16 22:44:372107 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552108 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572109 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372110 // opening a new window). But we sometimes navigate to about:blank to clear a
2111 // tab, and we want to still allow that.
2112 //
[email protected]8f4da8c2011-02-09 19:49:572113 // Note: we do this only for GET requests because our mechanism for switching
2114 // processes only issues GET requests. In particular, POST requests don't
2115 // work, because this mechanism does not preserve form POST data. If it
2116 // becomes necessary to support process switching for POST requests, we will
2117 // need to send the request's httpBody data up to the browser process, and
2118 // issue a special POST navigation in WebKit (via
2119 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2120 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222121 if (!frame->parent() && is_content_initiated &&
[email protected]6101c342010-12-16 22:44:372122 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2123 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2124 bool send_referrer = false;
2125 bool should_fork =
[email protected]e091df82011-10-11 18:13:212126 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172127 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372128 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112129
[email protected]e48869a2011-04-01 19:56:032130 if (!should_fork) {
2131 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362132 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032133 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362134 frame, url, is_content_initiated, is_initial_navigation,
2135 &send_referrer);
[email protected]6101c342010-12-16 22:44:372136 }
2137
2138 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152139 Referrer referrer(
2140 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2141 getReferrerPolicyFromRequest(request));
2142 OpenURL(
2143 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112144 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2145 }
[email protected]3d9689372009-09-10 04:29:172146 }
2147
[email protected]43763f982011-08-26 18:33:402148 // Use the frame's original request's URL rather than the document's URL for
2149 // this check. For a popup, the document's URL may become the opener window's
2150 // URL if the opener has called document.write. See http://crbug.com/93517.
2151 GURL old_url(frame->dataSource()->request().url());
2152
[email protected]3d9689372009-09-10 04:29:172153 // Detect when a page is "forking" a new tab that can be safely rendered in
2154 // its own process. This is done by sites like Gmail that try to open links
2155 // in new windows without script connections back to the original page. We
2156 // treat such cases as browser navigations (in which we will create a new
2157 // renderer for a cross-site navigation), rather than WebKit navigations.
2158 //
2159 // We use the following heuristic to decide whether to fork a new page in its
2160 // own process:
2161 // The parent page must open a new tab to about:blank, set the new tab's
2162 // window.opener to null, and then redirect the tab to a cross-site URL using
2163 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462164 //
2165 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2166 // (see below).
[email protected]3d9689372009-09-10 04:29:172167 bool is_fork =
2168 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582169 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172170 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522171 historyBackListCount() < 1 &&
2172 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172173 // The parent page must have set the child's window.opener to null before
2174 // redirecting to the desired URL.
2175 frame->opener() == NULL &&
2176 // Must be a top-level frame.
2177 frame->parent() == NULL &&
2178 // Must not have issued the request from this page.
2179 is_content_initiated &&
2180 // Must be targeted at the current tab.
2181 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2182 // Must be a JavaScript navigation, which appears as "other".
2183 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462184
2185 // Recognize if this navigation is from a link with rel=noreferrer and
2186 // target=_blank attributes, in which case the opener will be suppressed. If
2187 // so, it is safe to load cross-site pages in a separate process, so we
2188 // should let the browser handle it.
2189 bool is_noreferrer_and_blank_target =
2190 // Frame should be top level and not yet navigated.
2191 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412192 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462193 historyBackListCount() < 1 &&
2194 historyForwardListCount() < 1 &&
2195 // Links with rel=noreferrer will have no Referer field, and their
2196 // resulting frame will have its window.opener suppressed.
2197 // TODO(creis): should add a request.httpReferrer() method to help avoid
2198 // typos on the unusual spelling of Referer.
2199 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2200 opener_suppressed_ &&
2201 frame->opener() == NULL &&
2202 // Links with target=_blank will have no name.
2203 frame->name().isNull() &&
2204 // Another frame (with a non-empty creator) should have initiated the
2205 // request, targeted at this frame.
2206 !creator_url_.is_empty() &&
2207 is_content_initiated &&
2208 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2209 type == WebKit::WebNavigationTypeOther;
2210
2211 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172212 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152213 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172214 return WebKit::WebNavigationPolicyIgnore;
2215 }
2216
2217 return default_policy;
2218}
2219
[email protected]310ebd6302011-10-10 19:06:282220bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492221 WebFrame* frame, const WebURLRequest& request) {
2222 // We allow WebKit to think that everything can be handled even though
2223 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342224 return true;
2225}
2226
[email protected]310ebd6302011-10-10 19:06:282227WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492228 WebFrame* frame, const WebURLRequest& request) {
2229 NOTREACHED(); // Since we said we can handle all requests.
2230 return WebURLError();
2231}
2232
[email protected]310ebd6302011-10-10 19:06:282233WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492234 WebFrame* frame, const WebURLRequest& request) {
2235 WebURLError error;
2236 error.domain = WebString::fromUTF8(net::kErrorDomain);
2237 error.reason = net::ERR_ABORTED;
2238 error.unreachableURL = request.url();
2239 return error;
[email protected]7b7a7dc2009-10-19 02:23:342240}
2241
[email protected]310ebd6302011-10-10 19:06:282242void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492243 WebFrame*, const WebURLError&) {
2244 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342245}
2246
[email protected]310ebd6302011-10-10 19:06:282247void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432248 const WebKit::WebFormElement& form) {
2249 // Some login forms have onSubmit handlers that put a hash of the password
2250 // into a hidden field and then clear the password. (Issue 28910.)
2251 // This method gets called before any of those handlers run, so save away
2252 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072253 DocumentState* document_state =
2254 DocumentState::FromDataSource(frame->dataSource());
2255 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432256 PasswordFormDomManager::CreatePasswordForm(form));
2257}
2258
[email protected]310ebd6302011-10-10 19:06:282259void RenderViewImpl::willSubmitForm(WebFrame* frame,
2260 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072261 DocumentState* document_state =
2262 DocumentState::FromDataSource(frame->provisionalDataSource());
2263 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172264
[email protected]2905f742011-10-13 03:51:582265 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2266 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172267
2268 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352269 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072270 document_state->set_searchable_form_url(web_searchable_form_data.url());
2271 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212272 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432273 PasswordForm* password_form_data =
2274 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072275 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432276
[email protected]098c95cb2011-04-28 16:49:012277 // In order to save the password that the user actually typed and not one
2278 // that may have gotten transformed by the site prior to submit, recover it
2279 // from the form contents already stored by |willSendSubmitEvent| into the
2280 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2281 // which is what we're storing into now.)
2282 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072283 DocumentState* old_document_state =
2284 DocumentState::FromDataSource(frame->dataSource());
2285 if (old_document_state) {
2286 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432287 if (old_form_data && old_form_data->action == password_form_data->action)
2288 password_form_data->password_value = old_form_data->password_value;
2289 }
2290 }
[email protected]3d9689372009-09-10 04:29:172291
[email protected]2a5b1732011-04-01 23:55:552292 FOR_EACH_OBSERVER(
2293 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172294}
2295
[email protected]310ebd6302011-10-10 19:06:282296void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172297 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2298 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382299 FOR_EACH_OBSERVER(
2300 RenderViewObserver, observers_,
2301 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172302}
2303
[email protected]310ebd6302011-10-10 19:06:282304void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382305 FOR_EACH_OBSERVER(
2306 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172307}
2308
[email protected]310ebd6302011-10-10 19:06:282309void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172310 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152311 if (!frame->parent()) {
2312 WebDataSource* ds = frame->provisionalDataSource();
2313 // If there's no provisional data source, it's a reference fragment
2314 // navigation.
2315 completed_client_redirect_src_ = Referrer(
2316 from, ds ? getReferrerPolicyFromRequest(ds->request()) :
2317 frame->referrerPolicy());
2318 }
[email protected]eb0bff942011-04-07 22:08:382319 FOR_EACH_OBSERVER(
2320 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172321}
2322
[email protected]310ebd6302011-10-10 19:06:282323void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072324 DocumentState* document_state = DocumentState::FromDataSource(ds);
2325 if (!document_state) {
2326 document_state = new DocumentState;
2327 ds->setExtraData(document_state);
2328 }
2329
[email protected]3d9689372009-09-10 04:29:172330 // The rest of RenderView assumes that a WebDataSource will always have a
2331 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072332 bool content_initiated = !pending_navigation_params_.get();
2333 if (content_initiated)
2334 document_state->set_navigation_state(
2335 NavigationState::CreateContentInitiated());
2336 else
2337 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512338
[email protected]007733c2011-11-17 00:34:072339 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512340 // navigating from a page that used prefetching using a link on that
2341 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072342 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512343 // this value appropriately.
2344 // TODO(gavinp): catch the important case of navigation in a new
2345 // renderer process.
2346 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302347 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522348 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512349 const GURL referrer(
2350 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2351 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072352 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512353 old_frame->dataSource())->was_prefetcher()) {
2354 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2355 WebDataSource* old_frame_ds = old_frame->dataSource();
2356 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072357 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512358 break;
2359 }
2360 }
2361 }
2362 }
2363 }
2364
[email protected]4c1b6f0b2010-02-07 16:38:182365 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522366 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512367 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182368 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072369 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182370 break;
2371 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072372 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182373 break;
2374 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072375 document_state->set_load_type(
2376 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182377 break;
2378 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072379 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182380 break;
2381 }
2382 }
[email protected]fa7b6b542009-11-03 05:02:302383
[email protected]946a0032011-03-31 18:42:282384 FOR_EACH_OBSERVER(
2385 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172386}
2387
[email protected]007733c2011-11-17 00:34:072388void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2389 DocumentState* document_state) {
2390 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2391
2392 if (document_state->request_time().is_null())
2393 document_state->set_request_time(params.request_time);
2394
2395 // A navigation resulting from loading a javascript URL should not be treated
2396 // as a browser initiated event. Instead, we want it to look as if the page
2397 // initiated any load resulting from JS execution.
2398 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2399 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2400 params.page_id,
2401 params.pending_history_list_offset,
2402 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482403 navigation_state->set_transferred_request_child_id(
2404 params.transferred_request_child_id);
2405 navigation_state->set_transferred_request_request_id(
2406 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072407 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2408 // We're doing a load of a page that was restored from the last session.
2409 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2410 // which can result in stale data for pages that are set to expire. We
2411 // explicitly override that by setting the policy here so that as
2412 // necessary we load from the network.
2413 document_state->set_cache_policy_override(
2414 WebURLRequest::UseProtocolCachePolicy);
2415 }
2416 document_state->set_navigation_state(navigation_state);
2417 } else {
2418 document_state->set_navigation_state(
2419 NavigationState::CreateContentInitiated());
2420 }
2421
2422 if (IsReload(params))
2423 document_state->set_load_type(DocumentState::RELOAD);
2424 else if (!params.state.empty())
2425 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2426 else
2427 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2428
2429 pending_navigation_params_.reset();
2430}
2431
[email protected]310ebd6302011-10-10 19:06:282432void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172433 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072434 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172435
[email protected]3d9689372009-09-10 04:29:172436 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072437 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172438 double event_time = ds->triggeringEventTime();
2439 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072440 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172441 }
2442
[email protected]05c8e502010-08-15 15:13:522443 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072444 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522445
[email protected]3d9689372009-09-10 04:29:172446 bool is_top_most = !frame->parent();
2447 if (is_top_most) {
2448 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132449 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172450
2451 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152452 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172453 } else if (frame->parent()->isLoading()) {
2454 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002455 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072456 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582457 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172458 }
2459
[email protected]28685da92011-02-07 21:49:172460 FOR_EACH_OBSERVER(
2461 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2462
[email protected]3d9689372009-09-10 04:29:172463 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592464 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262465 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172466}
2467
[email protected]310ebd6302011-10-10 19:06:282468void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2469 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172470 if (frame->parent())
2471 return;
2472 // Received a redirect on the main frame.
2473 WebDataSource* data_source = frame->provisionalDataSource();
2474 if (!data_source) {
2475 // Should only be invoked when we have a data source.
2476 NOTREACHED();
2477 return;
2478 }
2479 std::vector<GURL> redirects;
2480 GetRedirectChain(data_source, &redirects);
2481 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512482 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592483 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172484 }
2485}
2486
[email protected]310ebd6302011-10-10 19:06:282487void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2488 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172489 // Notify the browser that we failed a provisional load with an error.
2490 //
2491 // Note: It is important this notification occur before DidStopLoading so the
2492 // SSL manager can react to the provisional load failure before being
2493 // notified the load stopped.
2494 //
2495 WebDataSource* ds = frame->provisionalDataSource();
2496 DCHECK(ds);
2497
2498 const WebURLRequest& failed_request = ds->request();
2499
[email protected]28685da92011-02-07 21:49:172500 FOR_EACH_OBSERVER(
2501 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2502
[email protected]3d9689372009-09-10 04:29:172503 bool show_repost_interstitial =
2504 (error.reason == net::ERR_CACHE_MISS &&
2505 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582506
2507 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2508 params.frame_id = frame->identifier();
2509 params.is_main_frame = !frame->parent();
2510 params.error_code = error.reason;
2511 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2512 failed_request,
2513 error,
2514 NULL,
2515 &params.error_description);
2516 params.url = error.unreachableURL;
2517 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172518 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582519 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172520
2521 // Don't display an error page if this is simply a cancelled load. Aside
2522 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2523 if (error.reason == net::ERR_ABORTED)
2524 return;
[email protected]b553edd52012-01-10 12:15:232525 // Don't display an error message if the request was handled by an
2526 // external protocol handler.
2527 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2528 return;
[email protected]3d9689372009-09-10 04:29:172529
2530 // Make sure we never show errors in view source mode.
2531 frame->enableViewSourceMode(false);
2532
[email protected]007733c2011-11-17 00:34:072533 DocumentState* document_state = DocumentState::FromDataSource(ds);
2534 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172535
2536 // If this is a failed back/forward/reload navigation, then we need to do a
2537 // 'replace' load. This is necessary to avoid messing up session history.
2538 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2539 // as session history is concerned.
2540 //
2541 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2542 // the page id.
2543 //
2544 bool replace =
2545 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582546 navigation_state->transition_type() ==
2547 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172548
2549 // If we failed on a browser initiated request, then make sure that our error
2550 // page load is regarded as the same browser initiated request.
2551 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072552 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2553 pending_navigation_params_->page_id =
2554 navigation_state->pending_page_id();
2555 pending_navigation_params_->pending_history_list_offset =
2556 navigation_state->pending_history_list_offset();
2557 pending_navigation_params_->transition =
2558 navigation_state->transition_type();
2559 pending_navigation_params_->request_time =
2560 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172561 }
2562
2563 // Provide the user with a more helpful error page?
2564 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2565 return;
2566
2567 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082568 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172569}
2570
[email protected]310ebd6302011-10-10 19:06:282571void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172572 WebFrame* frame, const char* data, size_t data_len,
2573 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072574 DocumentState* document_state =
2575 DocumentState::FromDataSource(frame->dataSource());
2576 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172577}
2578
[email protected]310ebd6302011-10-10 19:06:282579void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2580 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072581 DocumentState* document_state =
2582 DocumentState::FromDataSource(frame->dataSource());
2583 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172584
[email protected]007733c2011-11-17 00:34:072585 if (document_state->commit_load_time().is_null())
2586 document_state->set_commit_load_time(Time::Now());
2587
[email protected]3d9689372009-09-10 04:29:172588 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202589 // When we perform a new navigation, we need to update the last committed
2590 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172591 UpdateSessionHistory(frame);
2592
2593 // We bump our Page ID to correspond with the new session history entry.
2594 page_id_ = next_page_id_++;
2595
[email protected]3cc72b12010-03-18 23:03:002596 // Advance our offset in session history, applying the length limit. There
2597 // is now no forward history.
2598 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102599 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2600 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002601 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032602 history_page_ids_.resize(history_list_length_, -1);
2603 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172604 } else {
2605 // Inspect the navigation_state on this frame to see if the navigation
2606 // corresponds to a session history navigation... Note: |frame| may or
2607 // may not be the toplevel frame, but for the case of capturing session
2608 // history, the first committed frame suffices. We keep track of whether
2609 // we've seen this commit before so that only capture session history once
2610 // per navigation.
2611 //
2612 // Note that we need to check if the page ID changed. In the case of a
2613 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2614 // previous URL and the current page ID, which would be wrong.
2615 if (navigation_state->pending_page_id() != -1 &&
2616 navigation_state->pending_page_id() != page_id_ &&
2617 !navigation_state->request_committed()) {
2618 // This is a successful session history navigation!
2619 UpdateSessionHistory(frame);
2620 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002621
2622 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032623
2624 // If the history list is valid, our list of page IDs should be correct.
2625 DCHECK(history_list_length_ <= 0 ||
2626 history_list_offset_ < 0 ||
2627 history_list_offset_ >= history_list_length_ ||
2628 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172629 }
2630 }
2631
[email protected]28685da92011-02-07 21:49:172632 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2633 DidCommitProvisionalLoad(frame, is_new_navigation));
2634
[email protected]3d9689372009-09-10 04:29:172635 // Remember that we've already processed this request, so we don't update
2636 // the session history again. We do this regardless of whether this is
2637 // a session history navigation, because if we attempted a session history
2638 // navigation without valid HistoryItem state, WebCore will think it is a
2639 // new navigation.
2640 navigation_state->set_request_committed(true);
2641
2642 UpdateURL(frame);
2643
2644 // If this committed load was initiated by a client redirect, we're
2645 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152646 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172647
2648 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272649 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172650}
2651
[email protected]310ebd6302011-10-10 19:06:282652void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102653 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2654 DidClearWindowObject(frame));
2655
[email protected]b6cb3a842011-06-24 18:28:412656 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212657 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252658 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2659 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272660 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172661 }
[email protected]3d9689372009-09-10 04:29:172662}
2663
[email protected]310ebd6302011-10-10 19:06:282664void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172665 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412666 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252667 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272668 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172669 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2670 }
[email protected]e48869a2011-04-01 19:56:032671
2672 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2673 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172674}
2675
[email protected]310ebd6302011-10-10 19:06:282676void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2677 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462678 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172679
2680 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272681 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172682}
2683
[email protected]310ebd6302011-10-10 19:06:282684void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132685 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2686 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582687}
2688
[email protected]310ebd6302011-10-10 19:06:282689void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172690 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072691 DocumentState* document_state = DocumentState::FromDataSource(ds);
2692 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172693
[email protected]622474d2010-11-04 09:21:082694 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172695
[email protected]28685da92011-02-07 21:49:172696 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2697 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172698
2699 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272700 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172701}
2702
[email protected]310ebd6302011-10-10 19:06:282703void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082704 if (webview()->mainFrame() == frame) {
2705 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2706 page_id_));
2707 }
[email protected]3d9689372009-09-10 04:29:172708}
2709
[email protected]310ebd6302011-10-10 19:06:282710void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312711 WebDataSource* ds = frame->dataSource();
2712 DCHECK(ds);
2713
2714
[email protected]28685da92011-02-07 21:49:172715 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312716
2717 const WebURLRequest& failed_request = ds->request();
2718 string16 error_description;
2719 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2720 failed_request,
2721 error,
2722 NULL,
2723 &error_description);
2724 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2725 frame->identifier(),
2726 failed_request.url(),
2727 !frame->parent(),
2728 error.reason,
2729 error_description));
[email protected]3d9689372009-09-10 04:29:172730}
2731
[email protected]310ebd6302011-10-10 19:06:282732void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172733 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072734 DocumentState* document_state = DocumentState::FromDataSource(ds);
2735 if (document_state->finish_load_time().is_null())
2736 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412737
[email protected]676126f72011-01-15 00:03:512738 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172739
[email protected]1a55c5be2011-11-29 11:36:312740 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2741 frame->identifier(),
2742 ds->request().url(),
2743 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172744}
2745
[email protected]310ebd6302011-10-10 19:06:282746void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172747 WebFrame* frame, bool is_new_navigation) {
2748 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072749 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172750 // update the ExtraData on the datasource so that others who read the
2751 // ExtraData will get the new NavigationState. Similarly, if we did not
2752 // initiate this navigation, then we need to take care to reset any pre-
2753 // existing navigation state to a content-initiated navigation state.
2754 // DidCreateDataSource conveniently takes care of this for us.
2755 didCreateDataSource(frame, frame->dataSource());
2756
[email protected]007733c2011-11-17 00:34:072757 DocumentState* document_state =
2758 DocumentState::FromDataSource(frame->dataSource());
2759 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092760 new_state->set_was_within_same_page(true);
2761
[email protected]3d9689372009-09-10 04:29:172762 didCommitProvisionalLoad(frame, is_new_navigation);
2763
[email protected]750fcf872011-08-03 23:10:472764 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2765 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172766}
2767
[email protected]310ebd6302011-10-10 19:06:282768void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312769 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592770}
2771
[email protected]310ebd6302011-10-10 19:06:282772void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172773 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2774 // Ignore
2775}
2776
[email protected]310ebd6302011-10-10 19:06:282777void RenderViewImpl::willSendRequest(WebFrame* frame,
2778 unsigned identifier,
2779 WebURLRequest& request,
2780 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302781 WebFrame* top_frame = frame->top();
2782 if (!top_frame)
2783 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512784 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2785 WebDataSource* top_data_source = top_frame->dataSource();
2786 WebDataSource* data_source =
2787 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222788
[email protected]78d5cfe2011-02-04 08:43:222789 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032790 GURL new_url;
2791 if (content::GetContentClient()->renderer()->WillSendRequest(
2792 frame, request_url, &new_url)) {
2793 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222794 }
2795
[email protected]2905f742011-10-13 03:51:582796 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072797 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2798 NavigationState* navigation_state = document_state->navigation_state();
2799 if (document_state) {
2800 if (document_state->is_cache_policy_override_set())
2801 request.setCachePolicy(document_state->cache_policy_override());
2802 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:302803 }
[email protected]8a3125a712010-08-09 18:58:512804
[email protected]91043a8232011-11-04 16:41:192805 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:062806 new RequestExtraData(frame->referrerPolicy(),
2807 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:192808 frame->identifier(),
2809 frame->parent() == top_frame,
2810 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:482811 transition_type,
2812 navigation_state->transferred_request_child_id(),
2813 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:572814
[email protected]007733c2011-11-17 00:34:072815 DocumentState* top_document_state =
2816 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:572817 // TODO(gavinp): separate out prefetching and prerender field trials
2818 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:072819 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:572820 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2821 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:072822 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512823
[email protected]3d9689372009-09-10 04:29:172824 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132825 request.setHasUserGesture(frame->isProcessingUserGesture());
2826
[email protected]0a8db0d2011-04-13 15:15:402827 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132828 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172829}
2830
[email protected]310ebd6302011-10-10 19:06:282831void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:172832 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492833
[email protected]3d9689372009-09-10 04:29:172834 // Only do this for responses that correspond to a provisional data source
2835 // of the top-most frame. If we have a provisional data source, then we
2836 // can't have any sub-resources yet, so we know that this response must
2837 // correspond to a frame load.
2838 if (!frame->provisionalDataSource() || frame->parent())
2839 return;
2840
2841 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082842 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172843 if (frame->isViewSourceModeEnabled())
2844 return;
2845
[email protected]007733c2011-11-17 00:34:072846 DocumentState* document_state =
2847 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:082848 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532849
[email protected]972ebdff2010-06-10 22:59:072850 // Record page load flags.
[email protected]007733c2011-11-17 00:34:072851 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2852 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
2853 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:572854 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:072855 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
2856 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092857 // Whether or not the http status code actually corresponds to an error is
2858 // only checked when the page is done loading, if |use_error_page| is
2859 // still true.
[email protected]007733c2011-11-17 00:34:072860 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172861}
2862
[email protected]310ebd6302011-10-10 19:06:282863void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:172864 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:072865 DocumentState* document_state =
2866 DocumentState::FromDataSource(frame->dataSource());
2867 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172868 return;
2869
[email protected]7bfc153f2011-09-23 22:00:202870 // Do not show error page when DevTools is attached.
2871 if (devtools_agent_->IsAttached())
2872 return;
2873
[email protected]06333afe2011-02-24 14:55:092874 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:072875 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:082876 if (http_status_code == 404) {
2877 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412878 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172879
[email protected]b6cb3a842011-06-24 18:28:412880 const GURL& error_page_url =
2881 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092882 if (error_page_url.is_valid()) {
2883 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472884 original_error.domain = "http";
2885 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412886 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172887
[email protected]007733c2011-11-17 00:34:072888 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:092889 new AltErrorPageResourceFetcher(
2890 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:082891 base::Bind(&RenderViewImpl::AltErrorPageFinished,
2892 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:092893 return;
2894 }
2895 }
[email protected]3d9689372009-09-10 04:29:172896
[email protected]e6a2ce52011-10-08 01:40:132897 std::string error_domain;
2898 if (content::GetContentClient()->renderer()->HasErrorPage(
2899 http_status_code, &error_domain)) {
2900 WebURLError error;
2901 error.unreachableURL = frame->document().url();
2902 error.domain = WebString::fromUTF8(error_domain);
2903 error.reason = http_status_code;
2904
2905 LoadNavigationErrorPage(
2906 frame, frame->dataSource()->request(), error, std::string(), true);
2907 }
[email protected]3d9689372009-09-10 04:29:172908}
2909
[email protected]310ebd6302011-10-10 19:06:282910void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:172911 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2912 // Ignore
2913}
2914
[email protected]310ebd6302011-10-10 19:06:282915void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:172916 WebFrame* frame, const WebURLRequest& request,
2917 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:002918 // The recipients of this message have no use for data: URLs: they don't
2919 // affect the page's insecure content list and are not in the disk cache. To
2920 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
2921 // filter them out here.
2922 GURL url(request.url());
2923 if (url.SchemeIs("data"))
2924 return;
2925
[email protected]3d9689372009-09-10 04:29:172926 // Let the browser know we loaded a resource from the memory cache. This
2927 // message is needed to display the correct SSL indicators.
2928 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2929 routing_id_,
[email protected]84703292011-10-28 20:44:002930 url,
[email protected]70435962011-08-02 20:13:282931 response.securityInfo(),
2932 request.httpMethod().utf8(),
2933 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172934}
2935
[email protected]310ebd6302011-10-10 19:06:282936void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292937 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2938}
2939
[email protected]310ebd6302011-10-10 19:06:282940void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:022941 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292942 Send(new ViewHostMsg_DidRunInsecureContent(
2943 routing_id_,
[email protected]92771112011-01-20 00:13:022944 origin.toString().utf8(),
2945 target));
[email protected]e3d60e5d2009-09-25 21:08:292946}
2947
[email protected]310ebd6302011-10-10 19:06:282948void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:032949 webkit_glue::WebURLLoaderImpl* loader_impl =
2950 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2951 loader_impl->UpdateRoutingId(routing_id_);
2952}
2953
[email protected]310ebd6302011-10-10 19:06:282954void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172955 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2956}
2957
[email protected]310ebd6302011-10-10 19:06:282958void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
2959 v8::Handle<v8::Context> context,
2960 int world_id) {
[email protected]5bc10932011-09-21 21:03:302961 content::GetContentClient()->renderer()->DidCreateScriptContext(
2962 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282963}
2964
[email protected]310ebd6302011-10-10 19:06:282965void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
2966 v8::Handle<v8::Context> context,
2967 int world_id) {
[email protected]5bc10932011-09-21 21:03:302968 content::GetContentClient()->renderer()->WillReleaseScriptContext(
2969 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282970}
2971
[email protected]310ebd6302011-10-10 19:06:282972void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:072973 // We don't always want to send the change messages over IPC, only if we've
2974 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2975 // message.
2976 if (!send_preferred_size_changes_ || !webview())
2977 return;
2978
[email protected]705243f2010-05-05 19:58:072979 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2980 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532981
2982 // In the presence of zoom, these sizes are still reported as if unzoomed,
2983 // so we need to adjust.
2984 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2985 size.set_width(static_cast<int>(size.width() * zoom_factor));
2986 size.set_height(static_cast<int>(size.height() * zoom_factor));
2987
[email protected]6b5576cb2011-12-05 08:23:002988 if (!size.height())
2989 size.set_height(preferred_size_.height());
2990
[email protected]705243f2010-05-05 19:58:072991 if (size == preferred_size_)
2992 return;
[email protected]c27324b2009-11-19 22:44:292993
[email protected]705243f2010-05-05 19:58:072994 preferred_size_ = size;
2995 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2996 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172997}
2998
[email protected]273558fb2012-01-12 15:03:512999void RenderViewImpl::EnsureMediaStreamImpl() {
3000#if defined(ENABLE_P2P_APIS)
3001 if (!p2p_socket_dispatcher_)
3002 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3003#endif
3004
3005 if (!media_stream_dispatcher_)
3006 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3007
3008 if (!media_stream_impl_.get()) {
3009 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3010 media_stream_impl_ = new MediaStreamImpl(
3011 media_stream_dispatcher_,
3012 p2p_socket_dispatcher_,
3013 RenderThreadImpl::current()->video_capture_impl_manager(),
3014 factory);
3015 }
3016}
3017
[email protected]310ebd6302011-10-10 19:06:283018void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3019 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313020 if (webview()->mainFrame() != frame)
3021 return;
3022 WebView* frameView = frame->view();
3023 if (!frameView)
3024 return;
3025
3026 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3027 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3028
3029 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3030 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3031 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3032 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3033
3034 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3035 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3036 }
3037}
3038
[email protected]310ebd6302011-10-10 19:06:283039void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313040 WebSize offset = frame->scrollOffset();
3041 WebSize minimum_offset = frame->minimumScrollOffset();
3042 WebSize maximum_offset = frame->maximumScrollOffset();
3043
3044 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3045 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3046
3047 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3048 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3049 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3050 routing_id_, is_pinned_to_left, is_pinned_to_right));
3051
3052 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3053 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3054 }
3055}
3056
[email protected]310ebd6302011-10-10 19:06:283057void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493058 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313059
3060 if (webview()->mainFrame() == frame)
3061 UpdateScrollState(frame);
3062}
3063
[email protected]310ebd6302011-10-10 19:06:283064void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313065 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493066}
3067
[email protected]310ebd6302011-10-10 19:06:283068void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3069 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113070 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3071 if (!count)
3072 active_match_ordinal = 0;
3073
3074 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3075 routing_id_,
3076 request_id,
3077 count,
3078 gfx::Rect(),
3079 active_match_ordinal,
3080 final_update);
3081
[email protected]8922e1f2009-10-03 05:01:263082 // If we have a message that has been queued up, then we should just replace
3083 // it. The ACK from the browser will make sure it gets sent when the browser
3084 // wants it.
3085 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263086 queued_find_reply_message_.reset(msg);
3087 } else {
3088 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113089 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263090 }
3091}
3092
[email protected]310ebd6302011-10-10 19:06:283093void RenderViewImpl::reportFindInPageSelection(int request_id,
3094 int active_match_ordinal,
3095 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263096 // Send the search result over to the browser process.
3097 Send(new ViewHostMsg_Find_Reply(routing_id_,
3098 request_id,
3099 -1,
3100 selection_rect,
3101 active_match_ordinal,
3102 false));
3103}
3104
[email protected]310ebd6302011-10-10 19:06:283105void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223106 WebFrame* frame,
3107 WebFileSystem::Type type,
3108 long long size,
[email protected]d275d7a2010-11-03 01:34:493109 bool create,
[email protected]2b06a992010-08-21 05:48:223110 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083111 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223112
[email protected]b6cb3a842011-06-24 18:28:413113 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563114 if (origin.isUnique()) {
3115 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083116 callbacks->didFail(WebKit::WebFileErrorAbort);
3117 return;
3118 }
[email protected]2b06a992010-08-21 05:48:223119
[email protected]c5a272d2010-09-27 18:37:083120 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3121 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493122 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223123}
3124
[email protected]310ebd6302011-10-10 19:06:283125void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403126 WebFrame* frame,
3127 WebStorageQuotaType type,
3128 WebStorageQuotaCallbacks* callbacks) {
3129 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413130 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563131 if (origin.isUnique()) {
3132 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403133 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3134 return;
3135 }
3136 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533137 GURL(origin.toString()),
3138 static_cast<quota::StorageType>(type),
3139 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403140}
3141
[email protected]310ebd6302011-10-10 19:06:283142void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403143 WebFrame* frame,
3144 WebStorageQuotaType type,
3145 unsigned long long requested_size,
3146 WebStorageQuotaCallbacks* callbacks) {
3147 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413148 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563149 if (origin.isUnique()) {
3150 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403151 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3152 return;
3153 }
3154 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533155 routing_id(), GURL(origin.toString()),
3156 static_cast<quota::StorageType>(type), requested_size,
3157 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403158}
3159
[email protected]8b5af492011-11-28 21:50:583160void RenderViewImpl::registerIntentService(
3161 WebKit::WebFrame* frame, const WebKit::WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063162 string16 title = service.title();
3163 if (title.empty())
3164 title = webview()->mainFrame()->document().title();
3165
[email protected]8b5af492011-11-28 21:50:583166 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3167 service.action(),
3168 service.type(),
3169 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063170 title,
[email protected]8b5af492011-11-28 21:50:583171 service.disposition()));
3172}
3173
3174void RenderViewImpl::dispatchIntent(WebKit::WebFrame* frame,
3175 const WebKit::WebIntent& intent) {
[email protected]678105012011-12-09 04:01:213176 webkit_glue::WebIntentData intent_data(intent);
[email protected]8b5af492011-11-28 21:50:583177 Send(new IntentsHostMsg_WebIntentDispatch(
3178 routing_id_, intent_data, intent.identifier()));
3179}
3180
[email protected]18d5be92011-07-25 18:00:193181// WebKit::WebPageSerializerClient implementation ------------------------------
3182
[email protected]310ebd6302011-10-10 19:06:283183void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193184 const WebURL& frame_url,
3185 const WebCString& data,
3186 WebPageSerializerClient::PageSerializationStatus status) {
3187 Send(new ViewHostMsg_SendSerializedHtmlData(
3188 routing_id(),
3189 frame_url,
3190 data.data(),
3191 static_cast<int32>(status)));
3192}
3193
[email protected]a2ef54c2011-10-10 16:20:313194// content::RenderView implementation ------------------------------------------
3195
[email protected]310ebd6302011-10-10 19:06:283196bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313197 return RenderWidget::Send(message);
3198}
3199
[email protected]310ebd6302011-10-10 19:06:283200int RenderViewImpl::GetRoutingId() const {
[email protected]a2ef54c2011-10-10 16:20:313201 return routing_id_;
3202}
3203
[email protected]310ebd6302011-10-10 19:06:283204int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313205 return page_id_;
3206}
3207
[email protected]310ebd6302011-10-10 19:06:283208gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313209 return size();
3210}
3211
[email protected]310ebd6302011-10-10 19:06:283212gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313213 return host_window();
3214}
3215
[email protected]310ebd6302011-10-10 19:06:283216WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313217 return webkit_preferences_;
3218}
3219
[email protected]310ebd6302011-10-10 19:06:283220WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313221 return webview();
3222}
3223
[email protected]310ebd6302011-10-10 19:06:283224WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313225 if (!webview())
3226 return WebNode();
3227 WebFrame* focused_frame = webview()->focusedFrame();
3228 if (focused_frame) {
3229 WebDocument doc = focused_frame->document();
3230 if (!doc.isNull())
3231 return doc.focusedNode();
3232 }
3233
3234 return WebNode();
3235}
3236
[email protected]310ebd6302011-10-10 19:06:283237WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313238 return context_menu_node_;
3239}
3240
[email protected]310ebd6302011-10-10 19:06:283241bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313242 bool is_editable_node = false;
3243 if (!node.isNull()) {
3244 if (node.isContentEditable()) {
3245 is_editable_node = true;
3246 } else if (node.isElementNode()) {
3247 is_editable_node =
3248 node.toConst<WebElement>().isTextFormControlElement();
3249 }
3250 }
3251 return is_editable_node;
3252}
3253
[email protected]310ebd6302011-10-10 19:06:283254WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313255 WebKit::WebFrame* frame,
3256 const webkit::WebPluginInfo& info,
3257 const WebKit::WebPluginParams& params) {
3258 bool pepper_plugin_was_registered = false;
3259 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3260 pepper_delegate_.CreatePepperPluginModule(info,
3261 &pepper_plugin_was_registered));
3262 if (pepper_plugin_was_registered) {
3263 if (!pepper_module)
3264 return NULL;
3265 return new webkit::ppapi::WebPluginImpl(
3266 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3267 }
3268
3269 return new webkit::npapi::WebPluginImpl(
3270 frame, params, info.path, AsWeakPtr());
3271}
3272
[email protected]310ebd6302011-10-10 19:06:283273void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3274 const string16& jscript,
3275 int id,
3276 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313277 v8::Handle<v8::Value> result;
3278 WebFrame* web_frame = GetChildFrame(frame_xpath);
3279 if (web_frame)
3280 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3281 if (notify_result) {
3282 ListValue list;
3283 if (!result.IsEmpty() && web_frame) {
3284 v8::HandleScope handle_scope;
3285 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3286 v8::Context::Scope context_scope(context);
3287 V8ValueConverterImpl converter;
3288 converter.set_allow_date(true);
3289 converter.set_allow_regexp(true);
3290 list.Set(0, converter.FromV8Value(result, context));
3291 } else {
3292 list.Set(0, Value::CreateNullValue());
3293 }
3294 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3295 }
3296}
3297
[email protected]310ebd6302011-10-10 19:06:283298bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313299 return (!send_preferred_size_changes_ ||
3300 (disable_scrollbars_size_limit_.width() <= width ||
3301 disable_scrollbars_size_limit_.height() <= height));
3302}
3303
[email protected]310ebd6302011-10-10 19:06:283304int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313305 return enabled_bindings_;
3306}
3307
[email protected]310ebd6302011-10-10 19:06:283308void RenderViewImpl::SetEnabledBindings(int enabled_bindings) {
[email protected]a2ef54c2011-10-10 16:20:313309 enabled_bindings_ = enabled_bindings;
3310}
3311
[email protected]310ebd6302011-10-10 19:06:283312bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313313 return send_content_state_immediately_;
3314}
3315
[email protected]310ebd6302011-10-10 19:06:283316float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313317 return filtered_time_per_frame();
3318}
3319
[email protected]310ebd6302011-10-10 19:06:283320void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3321 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313322 showContextMenu(frame, data);
3323}
3324
[email protected]310ebd6302011-10-10 19:06:283325WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313326 return visibilityState();
3327}
3328
[email protected]310ebd6302011-10-10 19:06:283329void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3330 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313331 return runModalAlertDialog(frame, message);
3332}
3333
[email protected]310ebd6302011-10-10 19:06:283334void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313335 WebKit::WebFrame* frame,
3336 const WebKit::WebURLRequest& request,
3337 WebKit::WebNavigationPolicy policy) {
3338 loadURLExternally(frame, request, policy);
3339}
3340
3341// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513342
[email protected]310ebd6302011-10-10 19:06:283343webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533344 const FilePath& file_path,
3345 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593346 if (!PluginChannelHost::IsListening())
3347 return NULL;
3348
[email protected]00c39612010-03-06 02:53:283349 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463350 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323351#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223352 return webkit::npapi::WebPluginDelegateImpl::Create(
3353 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093354#else
[email protected]7398dcc2011-09-06 21:40:323355 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223356 NOTIMPLEMENTED();
3357 return NULL;
[email protected]7b6616f2010-01-14 18:07:553358#endif
[email protected]f103ab72009-09-02 17:10:593359 }
3360
[email protected]4e0616e2010-05-28 14:55:533361 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593362}
3363
[email protected]310ebd6302011-10-10 19:06:283364void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033365#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273366 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593367#endif
3368}
3369
[email protected]310ebd6302011-10-10 19:06:283370void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033371#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273372 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593373#endif
3374 CleanupWindowInPluginMoves(window);
3375}
3376
[email protected]310ebd6302011-10-10 19:06:283377void RenderViewImpl::DidMovePlugin(
3378 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593379 SchedulePluginMove(move);
3380}
3381
[email protected]310ebd6302011-10-10 19:06:283382void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593383 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523384 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593385}
3386
[email protected]310ebd6302011-10-10 19:06:283387void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593388 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523389 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593390}
3391
[email protected]310ebd6302011-10-10 19:06:283392WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513393 return &cookie_jar_;
3394}
3395
[email protected]a9288f52011-11-17 05:18:163396void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073397 Send(new ViewHostMsg_MediaNotification(routing_id_,
3398 reinterpret_cast<int64>(player),
3399 player->hasVideo(),
3400 player->hasAudio(),
3401 true));
3402}
3403
[email protected]a9288f52011-11-17 05:18:163404void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073405 Send(new ViewHostMsg_MediaNotification(routing_id_,
3406 reinterpret_cast<int64>(player),
3407 player->hasVideo(),
3408 player->hasAudio(),
3409 false));
3410}
3411
[email protected]a9288f52011-11-17 05:18:163412void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073413 DidPause(player);
3414}
3415
[email protected]310ebd6302011-10-10 19:06:283416void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293417 if (!webview())
3418 return;
3419
[email protected]26aa0482009-09-30 16:55:273420 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173421 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293422 return;
[email protected]ca948a22009-06-25 19:36:173423
3424 Send(new ViewHostMsg_UpdateState(
3425 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293426}
3427
[email protected]310ebd6302011-10-10 19:06:283428void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363429 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003430 if (!frame)
3431 return;
[email protected]b781ff282011-08-20 06:19:363432
[email protected]b781ff282011-08-20 06:19:363433 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003434 if (!webview()->caretOrSelectionRange(&location, &length))
3435 return;
3436
3437 string16 text;
3438 size_t offset;
3439 ui::Range range(location, location + length);
3440
3441 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3442 // If current focused element is editable, we will send 100 more chars
3443 // before and after selection. It is for input method surrounding text
3444 // feature.
3445 if (location > kExtraCharsBeforeAndAfterSelection)
3446 offset = location - kExtraCharsBeforeAndAfterSelection;
3447 else
3448 offset = 0;
3449 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3450 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3451 if (!webrange.isNull())
3452 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3453 } else {
3454 offset = location;
3455 text = frame->selectionAsText();
[email protected]e8cdf3532011-10-29 00:50:523456 // http://crbug.com/101435
3457 // In some case, frame->selectionAsText() returned text's length is not
3458 // equal to the length returned from webview()->caretOrSelectionRange().
3459 // So we have to set the range according to text.length().
3460 range.set_end(range.start() + text.length());
[email protected]b781ff282011-08-20 06:19:363461 }
3462
[email protected]b781ff282011-08-20 06:19:363463 // Sometimes we get repeated didChangeSelection calls from webkit when
3464 // the selection hasn't actually changed. We don't want to report these
3465 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003466 if (selection_text_offset_ != offset ||
3467 selection_range_ != range ||
3468 selection_text_ != text) {
3469 selection_text_ = text;
3470 selection_text_offset_ = offset;
3471 selection_range_ = range;
3472 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3473 }
[email protected]b781ff282011-08-20 06:19:363474}
3475
[email protected]310ebd6302011-10-10 19:06:283476GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3477 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553478 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293479 // If the URL that failed was secure, then the embedding web page was not
3480 // expecting a network attacker to be able to manipulate its contents. As
3481 // we fetch alternate error pages over HTTP, we would be allowing a network
3482 // attacker to manipulate the contents of the response if we tried to use
3483 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153484 return GURL();
initial.commit09911bf2008-07-26 23:55:293485 }
3486
3487 // Grab the base URL from the browser process.
3488 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153489 return GURL();
initial.commit09911bf2008-07-26 23:55:293490
3491 // Strip query params from the failed URL.
3492 GURL::Replacements remove_params;
3493 remove_params.ClearUsername();
3494 remove_params.ClearPassword();
3495 remove_params.ClearQuery();
3496 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553497 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503498 std::string spec_to_send = url_to_send.spec();
3499 // Notify link doctor of the url truncation by sending of "?" at the end.
3500 if (failed_url.has_query())
3501 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293502
3503 // Construct the query params to send to link doctor.
3504 std::string params(alternate_error_page_url_.query());
3505 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023506 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293507 params.append("&sourceid=chrome");
3508 params.append("&error=");
3509 switch (error_type) {
3510 case DNS_ERROR:
3511 params.append("dnserror");
3512 break;
3513
3514 case HTTP_404:
3515 params.append("http404");
3516 break;
3517
[email protected]5df266ac2008-10-15 19:50:133518 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333519 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133520 break;
3521
initial.commit09911bf2008-07-26 23:55:293522 default:
3523 NOTREACHED() << "unknown ErrorPageType";
3524 }
3525
3526 // OK, build the final url to return.
3527 GURL::Replacements link_doctor_params;
3528 link_doctor_params.SetQueryStr(params);
3529 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3530 return url;
3531}
3532
[email protected]310ebd6302011-10-10 19:06:283533GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593534 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3535 return GURL();
3536 else
3537 return creator_url_;
3538}
3539
[email protected]310ebd6302011-10-10 19:06:283540WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273541 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313542 web_ui_bindings_.reset(new WebUIBindings(
3543 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463544 }
[email protected]c50008512011-02-03 01:17:273545 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463546}
3547
[email protected]310ebd6302011-10-10 19:06:283548WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013549 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493550}
3551
[email protected]310ebd6302011-10-10 19:06:283552void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3553 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273554 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493555
[email protected]872542532011-06-23 00:43:163556 // Check if the plugin still exists in the document.
3557 if (main_frame->document().isPluginDocument() &&
3558 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493559 if (options.findNext) {
3560 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013561 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493562 } else {
[email protected]afdbd142010-07-10 08:01:233563 if (GetWebPluginFromPluginDocument()->startFind(
3564 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493565 } else {
[email protected]e7c58a32010-08-13 19:47:113566 // Send "no results".
3567 Send(new ViewHostMsg_Find_Reply(routing_id_,
3568 request_id,
3569 0,
3570 gfx::Rect(),
3571 0,
3572 true));
[email protected]24a7f3c2010-03-25 08:26:493573 }
3574 }
3575 return;
3576 }
3577
[email protected]b4bb2502009-10-01 22:35:273578 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273579 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293580 WebFrame* search_frame = focused_frame; // start searching focused frame.
3581
3582 bool multi_frame = (frame_after_main != main_frame);
3583
3584 // If we have multiple frames, we don't want to wrap the search within the
3585 // frame, so we check here if we only have main_frame in the chain.
3586 bool wrap_within_frame = !multi_frame;
3587
[email protected]b3f2b912009-04-09 16:18:523588 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293589 bool result = false;
3590
[email protected]7830da3e2009-11-06 16:27:263591 // If something is selected when we start searching it means we cannot just
3592 // increment the current match ordinal; we need to re-generate it.
3593 WebRange current_selection = focused_frame->selectionRange();
3594
initial.commit09911bf2008-07-26 23:55:293595 do {
[email protected]dd7daa82009-08-10 05:46:453596 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593597 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293598
3599 if (!result) {
3600 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223601 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293602
3603 // Find the next frame, but skip the invisible ones.
3604 do {
3605 // What is the next frame to search? (we might be going backwards). Note
3606 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593607 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273608 search_frame->traverseNext(true) :
3609 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453610 } while (!search_frame->hasVisibleContent() &&
3611 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293612
[email protected]884db412008-11-24 23:46:503613 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223614 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293615
3616 // If we have multiple frames and we have wrapped back around to the
3617 // focused frame, we need to search it once more allowing wrap within
3618 // the frame, otherwise it will report 'no match' if the focused frame has
3619 // reported matches, but no frames after the focused_frame contain a
3620 // match for the search word(s).
3621 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453622 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593623 request_id, search_text, options, true, // Force wrapping.
3624 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293625 }
3626 }
3627
[email protected]26aa0482009-09-30 16:55:273628 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293629 } while (!result && search_frame != focused_frame);
3630
[email protected]7830da3e2009-11-06 16:27:263631 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293632 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453633 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293634 } else {
3635 // If nothing is found, set result to "0 of 0", otherwise, set it to
3636 // "-1 of 1" to indicate that we found at least one item, but we don't know
3637 // yet what is active.
3638 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3639 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293640
[email protected]4f3dc372009-02-24 00:10:293641 // If we find no matches then this will be our last status update.
3642 // Otherwise the scoping effort will send more results.
3643 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293644
[email protected]4f3dc372009-02-24 00:10:293645 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403646 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593647 request_id,
[email protected]4f3dc372009-02-24 00:10:293648 match_count,
3649 selection_rect,
3650 ordinal,
3651 final_status_update));
initial.commit09911bf2008-07-26 23:55:293652
initial.commit09911bf2008-07-26 23:55:293653 // Scoping effort begins, starting with the mainframe.
3654 search_frame = main_frame;
3655
[email protected]dd7daa82009-08-10 05:46:453656 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293657
3658 do {
3659 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453660 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293661
3662 // We don't start another scoping effort unless at least one match has
3663 // been found.
3664 if (result) {
3665 // Start new scoping request. If the scoping function determines that it
3666 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453667 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593668 search_text,
3669 options,
initial.commit09911bf2008-07-26 23:55:293670 true); // reset the tickmarks
3671 }
3672
3673 // Iterate to the next frame. The frame will not necessarily scope, for
3674 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273675 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293676 } while (search_frame != main_frame);
3677 }
3678}
3679
[email protected]815dd9872011-11-23 18:40:303680void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493681 WebView* view = webview();
3682 if (!view)
3683 return;
3684
3685 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163686 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013687 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493688 return;
3689 }
3690
[email protected]815dd9872011-11-23 18:40:303691 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493692 if (clear_selection)
3693 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3694
3695 WebFrame* frame = view->mainFrame();
3696 while (frame) {
3697 frame->stopFinding(clear_selection);
3698 frame = frame->traverseNext(false);
3699 }
3700
[email protected]815dd9872011-11-23 18:40:303701 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493702 WebFrame* focused_frame = view->focusedFrame();
3703 if (focused_frame) {
3704 WebDocument doc = focused_frame->document();
3705 if (!doc.isNull()) {
3706 WebNode node = doc.focusedNode();
3707 if (!node.isNull())
3708 node.simulateClick();
3709 }
3710 }
3711 }
3712}
3713
[email protected]310ebd6302011-10-10 19:06:283714void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493715 // Check if there is any queued up request waiting to be sent.
3716 if (queued_find_reply_message_.get()) {
3717 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423718 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493719 }
3720}
3721
[email protected]54087fe2011-10-28 22:02:483722void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513723 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3724 return;
3725
[email protected]258d31122010-05-09 10:59:413726 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103727
[email protected]b75b8292010-10-01 07:28:253728 double old_zoom_level = webview()->zoomLevel();
3729 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483730 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253731 zoom_level = 0;
3732 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3733 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483734 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253735 } else {
3736 // Either the user hit the zoom factor limit and thus the zoom level is now
3737 // not a whole number, or a plugin changed it to a custom value. We want
3738 // to go to the next whole number so that the user can always get back to
3739 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483740 if ((old_zoom_level > 1 && zoom > 0) ||
3741 (old_zoom_level < 1 && zoom < 0)) {
3742 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253743 } else {
3744 // We're going towards 100%, so first go to the next whole number.
3745 zoom_level = static_cast<int>(old_zoom_level);
3746 }
3747 }
[email protected]b75b8292010-10-01 07:28:253748 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413749 zoomLevelChanged();
3750}
3751
3752void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3753 int zoom_center_x, int zoom_center_y) {
3754 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3755 kScalingIncrementForGesture);
3756}
3757
3758void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3759 int zoom_center_x,
3760 int zoom_center_y,
3761 float scaling_increment) {
3762 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3763 return;
3764
[email protected]c514d6372011-08-16 22:54:443765 double old_page_scale_factor = webview()->pageScaleFactor();
3766 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:483767 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:443768 page_scale_factor = 1.0;
3769 } else {
3770 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:413771 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:443772 }
[email protected]47578fa02011-11-02 19:34:413773 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:093774 webview()->setPageScaleFactor(page_scale_factor,
3775 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:413776 }
[email protected]40bd6582009-12-04 23:49:513777}
3778
[email protected]310ebd6302011-10-10 19:06:283779void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173780 webview()->hidePopups();
3781 webview()->setZoomLevel(false, zoom_level);
3782 zoomLevelChanged();
3783}
3784
[email protected]310ebd6302011-10-10 19:06:283785void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3786 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543787 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293788}
3789
[email protected]310ebd6302011-10-10 19:06:283790void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273791 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293792}
3793
[email protected]310ebd6302011-10-10 19:06:283794void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273795 WebString no_encoding;
3796 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183797}
3798
[email protected]310ebd6302011-10-10 19:06:283799WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453800 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273801 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453802
3803 // xpath string can represent a frame deep down the tree (across multiple
3804 // frame DOMs).
3805 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3806 // should break into 2 xpaths
3807 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413808 std::vector<string16> xpaths;
3809 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453810
[email protected]26aa0482009-09-30 16:55:273811 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413812 for (std::vector<string16>::const_iterator i = xpaths.begin();
3813 frame && i != xpaths.end(); ++i) {
3814 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293815 }
3816
[email protected]dd7daa82009-08-10 05:46:453817 return frame;
initial.commit09911bf2008-07-26 23:55:293818}
3819
[email protected]310ebd6302011-10-10 19:06:283820void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
3821 const string16& jscript,
3822 int id,
3823 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:533824 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293825}
3826
[email protected]310ebd6302011-10-10 19:06:283827void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
3828 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413829 WebFrame* frame = GetChildFrame(frame_xpath);
3830 if (!frame)
[email protected]216813952011-05-19 22:21:263831 return;
[email protected]ae461542009-06-19 19:03:413832
[email protected]01cf589c2011-07-28 18:04:033833 frame->document().insertUserStyleSheet(
3834 WebString::fromUTF8(css),
3835 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483836}
3837
[email protected]310ebd6302011-10-10 19:06:283838void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:093839 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293840}
3841
[email protected]310ebd6302011-10-10 19:06:283842void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
3843 const std::string& value) {
[email protected]e091df82011-10-11 18:13:213844 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:273845 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293846}
3847
[email protected]310ebd6302011-10-10 19:06:283848void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
3849 const gfx::Point& client_point,
3850 const gfx::Point& screen_point,
3851 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553852 WebDragOperation operation = webview()->dragTargetDragEnter(
3853 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553854 client_point,
3855 screen_point,
3856 ops);
3857
3858 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3859}
3860
[email protected]310ebd6302011-10-10 19:06:283861void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
3862 const gfx::Point& screen_point,
3863 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553864 WebDragOperation operation = webview()->dragTargetDragOver(
3865 client_point,
3866 screen_point,
3867 ops);
3868
3869 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3870}
3871
[email protected]310ebd6302011-10-10 19:06:283872void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:553873 webview()->dragTargetDragLeave();
3874}
3875
[email protected]310ebd6302011-10-10 19:06:283876void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
3877 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:553878 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573879
3880 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553881}
3882
[email protected]310ebd6302011-10-10 19:06:283883void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3884 const gfx::Point& screen_point,
3885 bool ended,
3886 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033887 if (ended) {
[email protected]26aa0482009-09-30 16:55:273888 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203889 } else {
3890 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033891 }
initial.commit09911bf2008-07-26 23:55:293892}
3893
[email protected]310ebd6302011-10-10 19:06:283894void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273895 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293896}
3897
[email protected]310ebd6302011-10-10 19:06:283898void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593899 webkit_preferences_ = prefs;
3900 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293901}
3902
[email protected]310ebd6302011-10-10 19:06:283903void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:293904 alternate_error_page_url_ = url;
3905}
3906
[email protected]310ebd6302011-10-10 19:06:283907void RenderViewImpl::OnCustomContextMenuAction(
[email protected]b29aa74b2011-01-31 21:41:083908 const webkit_glue::CustomContextMenuContext& custom_context,
3909 unsigned action) {
3910 if (custom_context.is_pepper_menu)
3911 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3912 else
3913 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:583914 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3915 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:333916}
3917
[email protected]310ebd6302011-10-10 19:06:283918void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:513919 int id,
3920 const std::vector<FilePath>& paths) {
3921 if (!enumeration_completions_[id])
3922 return;
3923
3924 WebVector<WebString> ws_file_names(paths.size());
3925 for (size_t i = 0; i < paths.size(); ++i)
3926 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3927
3928 enumeration_completions_[id]->didChooseFile(ws_file_names);
3929 enumeration_completions_.erase(id);
3930}
3931
[email protected]310ebd6302011-10-10 19:06:283932void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363933 // This could happen if we navigated to a different page before the user
3934 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473935 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363936 return;
3937
[email protected]cdaf8d02010-03-30 19:52:473938 WebVector<WebString> ws_file_names(paths.size());
3939 for (size_t i = 0; i < paths.size(); ++i)
3940 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463941
[email protected]cdaf8d02010-03-30 19:52:473942 if (file_chooser_completions_.front()->completion)
3943 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3944 file_chooser_completions_.pop_front();
3945
3946 // If there are more pending file chooser requests, schedule one now.
3947 if (!file_chooser_completions_.empty()) {
3948 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3949 file_chooser_completions_.front()->params));
3950 }
initial.commit09911bf2008-07-26 23:55:293951}
3952
[email protected]244ac1892011-12-02 17:04:473953void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
3954 const gfx::Size& max_size) {
3955 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
3956 if (!webview())
3957 return;
3958 webview()->enableAutoResizeMode(true, min_size, max_size);
3959}
3960
[email protected]2bf834f2011-11-17 20:02:213961void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:243962 if (send_preferred_size_changes_)
3963 return;
[email protected]9fb325e2010-05-06 18:23:243964 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393965
[email protected]d812fd12011-05-27 23:05:073966 // Start off with an initial preferred size notification (in case
3967 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:593968 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:083969}
3970
[email protected]310ebd6302011-10-10 19:06:283971void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:103972 const gfx::Size& disable_scrollbar_size_limit) {
3973 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3974}
3975
[email protected]310ebd6302011-10-10 19:06:283976void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:313977 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:503978 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:513979 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373980 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133981#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413982 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3983 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463984 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513985 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343986 renderer_prefs.thumb_inactive_color,
3987 renderer_prefs.thumb_active_color,
3988 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323989
[email protected]644d77e2010-01-27 01:03:103990 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323991 webview()->setScrollbarColors(
3992 renderer_prefs.thumb_inactive_color,
3993 renderer_prefs.thumb_active_color,
3994 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103995 webview()->setSelectionColors(
3996 renderer_prefs.active_selection_bg_color,
3997 renderer_prefs.active_selection_fg_color,
3998 renderer_prefs.inactive_selection_bg_color,
3999 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464000 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104001 }
[email protected]7a74e102009-09-03 00:16:564002#endif
[email protected]d051d9a2011-12-10 02:02:504003 // If the zoom level for this page matches the old zoom default, and this
4004 // is not a plugin, update the zoom level to match the new default.
4005 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4006 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4007 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4008 zoomLevelChanged();
4009 }
[email protected]80d96fa2009-06-10 22:34:514010}
4011
[email protected]310ebd6302011-10-10 19:06:284012void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4013 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284014 if (webview())
4015 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564016}
4017
[email protected]81375e872012-01-11 21:40:364018void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4019 const WebPluginAction& action) {
4020 if (webview())
4021 webview()->performPluginAction(action, location);
4022}
4023
[email protected]310ebd6302011-10-10 19:06:284024void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194025 const GURL& page_url) {
4026 // Prepare list to storage all savable resource links.
4027 std::vector<GURL> resources_list;
4028 std::vector<GURL> referrers_list;
4029 std::vector<GURL> frames_list;
4030 webkit_glue::SavableResourcesResult result(&resources_list,
4031 &referrers_list,
4032 &frames_list);
4033
[email protected]445e1042011-12-03 21:03:154034 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4035 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194036 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4037 webview(),
4038 page_url,
4039 &result,
[email protected]2a80aee2011-10-07 16:06:034040 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194041 // If something is wrong when collecting all savable resource links,
4042 // send empty list to embedder(browser) to tell it failed.
4043 referrers_list.clear();
4044 resources_list.clear();
4045 frames_list.clear();
4046 }
4047
4048 // Send result of all savable resource links to embedder.
4049 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4050 resources_list,
4051 referrers_list,
4052 frames_list));
4053}
4054
[email protected]310ebd6302011-10-10 19:06:284055void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194056 const std::vector<GURL>& links,
4057 const std::vector<FilePath>& local_paths,
4058 const FilePath& local_directory_name) {
4059
4060 // Convert std::vector of GURLs to WebVector<WebURL>
4061 WebVector<WebURL> weburl_links(links);
4062
4063 // Convert std::vector of std::strings to WebVector<WebString>
4064 WebVector<WebString> webstring_paths(local_paths.size());
4065 for (size_t i = 0; i < local_paths.size(); i++)
4066 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4067
4068 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4069 webstring_paths,
4070 webkit_glue::FilePathToWebString(
4071 local_directory_name));
4072}
4073
[email protected]310ebd6302011-10-10 19:06:284074void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274075 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474076 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294077}
4078
[email protected]310ebd6302011-10-10 19:06:284079void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]992db4c2011-05-12 15:37:154080 if (is_swapped_out_)
4081 return;
4082
4083 // Swap this RenderView out so the tab can navigate to a page rendered by a
4084 // different process. This involves running the unload handler and clearing
4085 // the page. Once WasSwappedOut is called, we also allow this process to exit
4086 // if there are no other active RenderViews in it.
4087
4088 // Send an UpdateState message before we get swapped out.
4089 SyncNavigationState();
4090
4091 // Synchronously run the unload handler before sending the ACK.
4092 webview()->dispatchUnloadEvent();
4093
4094 // Swap out and stop sending any IPC messages that are not ACKs.
4095 SetSwappedOut(true);
4096
4097 // Replace the page with a blank dummy URL. The unload handler will not be
4098 // run a second time, thanks to a check in FrameLoader::stopLoading.
4099 // TODO(creis): Need to add a better way to do this that avoids running the
4100 // beforeunload handler. For now, we just run it a second time silently.
4101 webview()->mainFrame()->loadHTMLString(std::string(),
4102 GURL("about:swappedout"),
4103 GURL("about:swappedout"),
4104 false);
4105
4106 // Just echo back the params in the ACK.
4107 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4108}
4109
[email protected]310ebd6302011-10-10 19:06:284110void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374111 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294112 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4113 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4114 // in the onunload handler from appearing. For now, we're bypassing that and
4115 // calling the FrameLoader's CloseURL method directly. This should be
4116 // revisited to avoid having two ways to close a page. Having a single way
4117 // to close that can run onunload is also useful for fixing
4118 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274119 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294120
[email protected]992db4c2011-05-12 15:37:154121 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294122}
4123
[email protected]310ebd6302011-10-10 19:06:284124void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024125#if defined(USE_AURA)
4126 // Aura doesn't care if we switch themes.
4127#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164128 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464129 if (webview())
4130 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574131#else // defined(OS_WIN)
4132 // TODO(port): we don't support theming on non-Windows platforms yet
4133 NOTIMPLEMENTED();
4134#endif
initial.commit09911bf2008-07-26 23:55:294135}
4136
[email protected]310ebd6302011-10-10 19:06:284137void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084138 if (decrement_shared_popup_at_destruction_)
4139 shared_popup_counter_->data--;
4140 shared_popup_counter_ = new SharedRenderViewCounter(0);
4141 decrement_shared_popup_at_destruction_ = false;
4142}
4143
[email protected]310ebd6302011-10-10 19:06:284144bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4145 const WebURLError& error,
4146 bool replace) {
[email protected]15d79e12009-08-02 19:23:454147 // We only show alternate error pages in the main frame. They are
4148 // intended to assist the user when navigating, so there is not much
4149 // value in showing them for failed subframes. Ideally, we would be
4150 // able to use the TYPED transition type for this, but that flag is
4151 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454152 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454153 return false;
4154
4155 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374156 // connection failure.
[email protected]15d79e12009-08-02 19:23:454157 int ec = error.reason;
4158 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4159 ec != net::ERR_CONNECTION_FAILED &&
4160 ec != net::ERR_CONNECTION_REFUSED &&
4161 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374162 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454163 return false;
4164
4165 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554166 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454167 if (!error_page_url.is_valid())
4168 return false;
4169
4170 // Load an empty page first so there is an immediate response to the error,
4171 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454172 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364173 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454174 error.unreachableURL,
4175 replace);
4176
4177 // Now, create a fetcher for the error page and associate it with the data
4178 // source we just created via the LoadHTMLString call. That way if another
4179 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074180 DocumentState* document_state =
4181 DocumentState::FromDataSource(frame->provisionalDataSource());
4182 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454183 new AltErrorPageResourceFetcher(
4184 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084185 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4186 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454187 return true;
4188}
4189
[email protected]310ebd6302011-10-10 19:06:284190void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4191 const WebURLError& original_error,
4192 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454193 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094194 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554195 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094196 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454197}
4198
[email protected]310ebd6302011-10-10 19:06:284199void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004200 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474201 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004202}
4203
[email protected]310ebd6302011-10-10 19:06:284204void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094205 const gfx::Rect& resizer_rect,
4206 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104207 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474208 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104209 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204210 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314211 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104212 }
[email protected]dd6afca2011-08-13 03:44:314213 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104214 }
4215
[email protected]ee41e7d22011-10-14 19:34:094216 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004217}
[email protected]0aa477bd2009-03-23 22:21:434218
[email protected]310ebd6302011-10-10 19:06:284219void RenderViewImpl::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014220 // Notify the pepper plugins that we started painting.
4221 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284222}
4223
[email protected]310ebd6302011-10-10 19:06:284224void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284225 // Notify any pepper plugins that we painted. This will call into the plugin,
4226 // and we it may ask to close itself as a result. This will, in turn, modify
4227 // our set, possibly invalidating the iterator. So we iterate on a copy that
4228 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014229 pepper_delegate_.ViewFlushedPaint();
4230
[email protected]00c39612010-03-06 02:53:284231 WebFrame* main_frame = webview()->mainFrame();
4232
4233 // If we have a provisional frame we are between the start and commit stages
4234 // of loading and we don't want to save stats.
4235 if (!main_frame->provisionalDataSource()) {
4236 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074237 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284238
[email protected]05c8e502010-08-15 15:13:524239 // TODO(jar): The following code should all be inside a method, probably in
4240 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284241 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074242 if (document_state->first_paint_time().is_null()) {
4243 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284244 }
[email protected]007733c2011-11-17 00:34:074245 if (document_state->first_paint_after_load_time().is_null() &&
4246 !document_state->finish_load_time().is_null()) {
4247 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284248 }
4249 }
4250}
4251
[email protected]310ebd6302011-10-10 19:06:284252void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084253 RenderWidget::OnSwapBuffersPosted();
4254}
4255
[email protected]310ebd6302011-10-10 19:06:284256void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244257 RenderWidget::OnSwapBuffersComplete();
4258}
4259
[email protected]310ebd6302011-10-10 19:06:284260void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244261 RenderWidget::OnSwapBuffersAborted();
4262}
4263
[email protected]310ebd6302011-10-10 19:06:284264webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154265 const gfx::Rect& paint_bounds,
4266 TransportDIB** dib,
4267 gfx::Rect* location,
4268 gfx::Rect* clip) {
4269 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4270 paint_bounds, dib, location, clip);
4271}
4272
[email protected]310ebd6302011-10-10 19:06:284273gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074274 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434275 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524276}
4277
[email protected]310ebd6302011-10-10 19:06:284278void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164279 if (webview())
[email protected]26aa0482009-09-30 16:55:274280 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164281}
4282
[email protected]310ebd6302011-10-10 19:06:284283void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144284 if (webview())
[email protected]b4bb2502009-10-01 22:35:274285 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144286
4287 SetBackground(background);
4288}
4289
[email protected]310ebd6302011-10-10 19:06:284290void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344291 if (webview())
[email protected]b4bb2502009-10-01 22:35:274292 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264293
4294#if defined(OS_MACOSX)
4295 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4296 for (plugin_it = plugin_delegates_.begin();
4297 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4298 (*plugin_it)->SetWindowFocus(active);
4299 }
4300#endif
[email protected]8c66c5a2009-07-22 17:26:344301}
4302
[email protected]6ce7abc52010-02-02 18:40:144303#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284304void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144305 // Inform plugins that their container has changed visibility.
4306 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4307 for (plugin_it = plugin_delegates_.begin();
4308 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4309 (*plugin_it)->SetContainerVisibility(visible);
4310 }
4311}
[email protected]1e6e3c992010-02-08 15:52:134312
[email protected]310ebd6302011-10-10 19:06:284313void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4314 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134315 // Inform plugins that their window's frame has changed.
4316 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4317 for (plugin_it = plugin_delegates_.begin();
4318 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4319 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4320 }
4321}
[email protected]935d63d2010-10-15 23:31:554322
[email protected]310ebd6302011-10-10 19:06:284323void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4324 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134325 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554326 // applies to it or not, so inform all the delegates.
4327 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4328 for (plugin_it = plugin_delegates_.begin();
4329 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134330 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554331 }
4332}
[email protected]6ce7abc52010-02-02 18:40:144333#endif // OS_MACOSX
4334
[email protected]310ebd6302011-10-10 19:06:284335void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484336 const EditCommands& edit_commands) {
4337 edit_commands_ = edit_commands;
4338}
4339
[email protected]310ebd6302011-10-10 19:06:284340void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594341 // We need to grab a pointer to the doomed WebView before we destroy it.
4342 WebView* doomed = webview();
4343 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494344 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594345}
4346
[email protected]310ebd6302011-10-10 19:06:284347void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484348 edit_commands_.clear();
4349}
4350
[email protected]310ebd6302011-10-10 19:06:284351bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]b993705a2011-10-09 23:00:244352 return pepper_delegate_.HandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374353}
4354
[email protected]310ebd6302011-10-10 19:06:284355void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514356 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064357}
4358
[email protected]310ebd6302011-10-10 19:06:284359void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244360 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4361}
4362
[email protected]310ebd6302011-10-10 19:06:284363void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434364 RenderWidget::OnWasHidden();
4365
[email protected]a6939ca42011-02-18 17:58:074366 if (webview()) {
4367 webview()->settings()->setMinimumTimerInterval(
4368 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444369 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074370 }
4371
[email protected]204f1df2012-01-04 20:21:134372 // Inform PPAPI plugins that their page is no longer visible.
4373 pepper_delegate_.PageVisibilityChanged(false);
4374
[email protected]a6939ca42011-02-18 17:58:074375#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134376 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434377 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4378 for (plugin_it = plugin_delegates_.begin();
4379 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4380 (*plugin_it)->SetContainerVisibility(false);
4381 }
[email protected]a6939ca42011-02-18 17:58:074382#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434383}
4384
[email protected]310ebd6302011-10-10 19:06:284385void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434386 RenderWidget::OnWasRestored(needs_repainting);
4387
[email protected]a6939ca42011-02-18 17:58:074388 if (webview()) {
4389 webview()->settings()->setMinimumTimerInterval(
4390 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444391 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074392 }
4393
[email protected]204f1df2012-01-04 20:21:134394 // Inform PPAPI plugins that their page is visible.
4395 pepper_delegate_.PageVisibilityChanged(true);
4396
[email protected]a6939ca42011-02-18 17:58:074397#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134398 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434399 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4400 for (plugin_it = plugin_delegates_.begin();
4401 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4402 (*plugin_it)->SetContainerVisibility(true);
4403 }
[email protected]784ea1ab2010-09-18 00:02:344404#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074405}
[email protected]1e6e3c992010-02-08 15:52:134406
[email protected]310ebd6302011-10-10 19:06:284407bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384408 if (WebWidgetHandlesCompositorScheduling())
4409 return false;
4410
[email protected]65225772011-05-12 21:10:244411 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4412 if (!context)
4413 return false;
4414 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4415 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4416 std::string::npos;
4417}
4418
[email protected]310ebd6302011-10-10 19:06:284419void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134420 RenderWidget::OnSetFocus(enable);
4421
[email protected]7d3c02c2010-05-05 23:10:314422 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074423 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134424 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4425 for (plugin_it = plugin_delegates_.begin();
4426 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344427#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314428 // RenderWidget's call to setFocus can cause the underlying webview's
4429 // activation state to change just like a call to setIsActive.
4430 if (enable)
4431 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344432#endif
[email protected]7d3c02c2010-05-05 23:10:314433 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134434 }
[email protected]589621b2010-09-23 22:01:074435
4436 // Notify all Pepper plugins.
4437 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134438 }
4439}
[email protected]941e4552010-02-01 21:23:434440
[email protected]310ebd6302011-10-10 19:06:284441void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004442 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504443 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574444}
4445
[email protected]73bf95812011-10-12 11:38:324446void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004447 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324448}
4449
[email protected]3f783362011-10-21 22:40:504450void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4451 UpdateSelectionBounds();
4452}
4453
[email protected]b25b3ee2012-01-13 05:19:544454bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4455 if (!pepper_delegate_.IsPluginFocused())
4456 return false;
4457 *rect = pepper_delegate_.GetCaretBounds();
4458 return true;
4459}
4460
[email protected]73bf95812011-10-12 11:38:324461void RenderViewImpl::PpapiPluginCancelComposition() {
4462 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4463 ui::Range range(ui::Range::InvalidRange());
4464 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4465}
4466
[email protected]310ebd6302011-10-10 19:06:284467void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574468 const string16& text,
4469 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4470 int selection_start,
4471 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324472 if (pepper_delegate_.IsPluginFocused()) {
4473 // When a PPAPI plugin has focus, we bypass WebKit.
4474 pepper_delegate_.OnImeSetComposition(text,
4475 underlines,
4476 selection_start,
4477 selection_end);
4478 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234479#if defined(OS_WIN)
4480 // When a plug-in has focus, we create platform-specific IME data used by
4481 // our IME emulator and send it directly to the focused plug-in, i.e. we
4482 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4483 // instance ID is the same one as the specified ID.)
4484 if (focused_plugin_id_ >= 0) {
4485 std::vector<int> clauses;
4486 std::vector<int> target;
4487 for (size_t i = 0; i < underlines.size(); ++i) {
4488 clauses.push_back(underlines[i].startOffset);
4489 clauses.push_back(underlines[i].endOffset);
4490 if (underlines[i].thick) {
4491 target.clear();
4492 target.push_back(underlines[i].startOffset);
4493 target.push_back(underlines[i].endOffset);
4494 }
4495 }
4496 std::set<WebPluginDelegateProxy*>::iterator it;
4497 for (it = plugin_delegates_.begin();
4498 it != plugin_delegates_.end(); ++it) {
4499 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4500 focused_plugin_id_);
4501 }
4502 return;
4503 }
4504#endif
[email protected]56ea1a62011-05-30 07:05:574505 RenderWidget::OnImeSetComposition(text,
4506 underlines,
4507 selection_start,
4508 selection_end);
4509 }
4510}
4511
[email protected]4de6d1692011-10-12 08:45:444512void RenderViewImpl::OnImeConfirmComposition(
4513 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574514 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324515 // When a PPAPI plugin has focus, we bypass WebKit.
4516 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574517 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234518#if defined(OS_WIN)
4519 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4520 // plug-ins. When we send IME text directly to plug-ins, we should not send
4521 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444522 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234523 if (focused_plugin_id_ >= 0) {
4524 std::set<WebPluginDelegateProxy*>::iterator it;
4525 for (it = plugin_delegates_.begin();
4526 it != plugin_delegates_.end(); ++it) {
4527 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4528 }
4529 return;
4530 }
4531#endif
[email protected]ebd28ac2011-10-13 18:49:054532 if (replacement_range.IsValid() && webview()) {
4533 // Select the text in |replacement_range|, it will then be replaced by
4534 // text added by the call to RenderWidget::OnImeConfirmComposition().
4535 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164536 WebRange webrange = WebRange::fromDocumentRange(
4537 frame, replacement_range.start(), replacement_range.length());
4538 if (!webrange.isNull())
4539 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054540 }
4541 }
[email protected]4de6d1692011-10-12 08:45:444542 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574543 }
4544}
4545
[email protected]310ebd6302011-10-10 19:06:284546ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324547 return pepper_delegate_.IsPluginFocused() ?
4548 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4549}
4550
[email protected]3f783362011-10-21 22:40:504551void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4552 if (pepper_delegate_.IsPluginFocused()) {
4553 // TODO(kinaba) http://crbug.com/101101
4554 // Current Pepper IME API does not handle selection bounds. So we simply
4555 // use the caret position as an empty range for now. It will be updated
4556 // after Pepper API equips features related to surrounding text retrieval.
4557 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4558 *start = caret;
4559 *end = caret;
4560 return;
4561 }
4562 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454563}
4564
[email protected]310ebd6302011-10-10 19:06:284565bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324566 return pepper_delegate_.IsPluginFocused() ?
4567 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574568}
4569
[email protected]e6ae0f6c2011-10-04 10:39:234570#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284571void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234572 if (focused)
4573 focused_plugin_id_ = plugin_id;
4574 else
4575 focused_plugin_id_ = -1;
4576}
4577#endif
4578
[email protected]43f28f832010-02-03 02:28:484579#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284580void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134581 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4582 focused, plugin_id);
4583 Send(msg);
4584}
4585
[email protected]310ebd6302011-10-10 19:06:284586void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134587 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554588 // This message can be sent during event-handling, and needs to be delivered
4589 // within that context.
4590 msg->set_unblock(true);
4591 Send(msg);
4592}
4593
[email protected]310ebd6302011-10-10 19:06:284594gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234595 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484596 gfx::PluginWindowHandle window = NULL;
4597 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234598 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114599 if (window) {
4600 fake_plugin_window_handles_.insert(window);
4601 }
[email protected]43f28f832010-02-03 02:28:484602 return window;
4603}
4604
[email protected]310ebd6302011-10-10 19:06:284605void RenderViewImpl::DestroyFakePluginWindowHandle(
4606 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114607 if (window && fake_plugin_window_handles_.find(window) !=
4608 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484609 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114610 fake_plugin_window_handles_.erase(window);
4611 }
[email protected]43f28f832010-02-03 02:28:484612}
4613
[email protected]310ebd6302011-10-10 19:06:284614void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4615 gfx::PluginWindowHandle window,
4616 int32 width,
4617 int32 height,
4618 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334619 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484620 routing_id(), window, width, height, io_surface_identifier));
4621}
4622
[email protected]310ebd6302011-10-10 19:06:284623void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334624 gfx::PluginWindowHandle window,
4625 int32 width,
4626 int32 height,
4627 TransportDIB::Handle transport_dib) {
4628 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074629 routing_id(), window, width, height, transport_dib));
4630}
4631
[email protected]310ebd6302011-10-10 19:06:284632TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334633 size_t size) {
[email protected]1aef98132010-02-23 18:00:074634 TransportDIB::Handle dib_handle;
4635 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384636 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074637 return dib_handle;
4638 // Return an invalid handle if Send() fails.
4639 return TransportDIB::DefaultHandleValue();
4640}
4641
[email protected]310ebd6302011-10-10 19:06:284642void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4643 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074644 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4645}
4646
[email protected]310ebd6302011-10-10 19:06:284647void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144648 gfx::PluginWindowHandle window, uint64 surface_id) {
4649 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4650 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484651}
4652#endif
[email protected]58c321d2010-02-19 12:11:284653
[email protected]310ebd6302011-10-10 19:06:284654bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234655 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474656 WebFileChooserCompletion* completion) {
4657 static const size_t kMaximumPendingFileChooseRequests = 4;
4658 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4659 // This sanity check prevents too many file choose requests from getting
4660 // queued which could DoS the user. Getting these is most likely a
4661 // programming error (there are many ways to DoS the user so it's not
4662 // considered a "real" security check), either in JS requesting many file
4663 // choosers to pop up, or in a plugin.
4664 //
4665 // TODO(brettw) we might possibly want to require a user gesture to open
4666 // a file picker, which will address this issue in a better way.
4667 return false;
4668 }
4669
4670 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4671 new PendingFileChooser(params, completion)));
4672 if (file_chooser_completions_.size() == 1) {
4673 // Actually show the browse dialog when this is the first request.
4674 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4675 }
4676 return true;
4677}
4678
[email protected]310ebd6302011-10-10 19:06:284679WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514680 if (!geolocation_dispatcher_)
4681 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4682 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254683}
[email protected]61c9f032010-03-31 23:04:194684
[email protected]310ebd6302011-10-10 19:06:284685WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114686 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224687#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514688 if (!speech_input_dispatcher_)
4689 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224690#endif
[email protected]676126f72011-01-15 00:03:514691 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114692}
4693
[email protected]310ebd6302011-10-10 19:06:284694WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514695 if (!device_orientation_dispatcher_)
4696 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4697 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534698}
4699
[email protected]310ebd6302011-10-10 19:06:284700void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4701 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254702 // For now, don't remember plugin zoom values. We don't want to mix them with
4703 // normal web content (i.e. a fixed layout plugin would usually want them
4704 // different).
4705 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4706
[email protected]b75b8292010-10-01 07:28:254707 int minimum_percent = static_cast<int>(
4708 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4709 int maximum_percent = static_cast<int>(
4710 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254711
4712 Send(new ViewHostMsg_UpdateZoomLimits(
4713 routing_id_, minimum_percent, maximum_percent, remember));
4714}
4715
[email protected]310ebd6302011-10-10 19:06:284716void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254717 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084718 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:254719 // Tell the browser which url got zoomed so it can update the menu and the
4720 // saved values if necessary
4721 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084722 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414723 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254724}
4725
[email protected]310ebd6302011-10-10 19:06:284726void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4727 const WebString& base_url,
4728 const WebString& url,
4729 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484730 GURL base(base_url);
4731 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4732 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4733 return;
4734 }
[email protected]f1a29a02011-10-06 23:08:444735 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4736 UTF16ToUTF8(scheme),
4737 absolute_url,
4738 title));
[email protected]a6d36cc2011-02-23 00:39:484739}
4740
[email protected]310ebd6302011-10-10 19:06:284741WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444742 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4743 WebKit::WebPageVisibilityStateHidden :
4744 WebKit::WebPageVisibilityStateVisible;
4745 WebKit::WebPageVisibilityState override_state = current_state;
4746 if (content::GetContentClient()->renderer()->
4747 ShouldOverridePageVisibilityState(this,
4748 &override_state))
4749 return override_state;
4750 return current_state;
[email protected]94dec932011-05-26 20:04:214751}
4752
[email protected]273558fb2012-01-12 15:03:514753WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
4754 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
4755 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
4756 return NULL;
4757 EnsureMediaStreamImpl();
4758 return media_stream_impl_;
4759}
4760
[email protected]310ebd6302011-10-10 19:06:284761bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194762 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454763 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194764 if (frame->parent() != NULL)
4765 return false;
4766
[email protected]f0a3d0b2010-08-06 22:51:534767 // Navigations initiated within Webkit are not sent out to the external host
4768 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274769 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134770 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534771 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134772 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334773 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534774 return false;
4775
[email protected]2fc22d12010-12-02 23:08:164776 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324777 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014778 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164779 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014780 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324781 // The opener relationship between the new window and the parent allows the
4782 // new window to script the parent and vice versa. This is not allowed if
4783 // the origins of the two domains are different. This can be treated as a
4784 // top level navigation and routed back to the host.
4785 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274786 if (!opener) {
[email protected]86965362011-04-21 18:42:514787 return true;
[email protected]d19ea342011-04-20 20:31:134788 } else {
[email protected]b6cb3a842011-06-24 18:28:414789 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324790 return true;
4791 }
4792 }
[email protected]61c9f032010-03-31 23:04:194793 return false;
4794}
[email protected]2b06a992010-08-21 05:48:224795
[email protected]310ebd6302011-10-10 19:06:284796void RenderViewImpl::OnAsyncFileOpened(
4797 base::PlatformFileError error_code,
4798 IPC::PlatformFileForTransit file_for_transit,
4799 int message_id) {
[email protected]27a9ef32010-09-10 04:06:244800 pepper_delegate_.OnAsyncFileOpened(
4801 error_code,
4802 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4803 message_id);
4804}
[email protected]caf706f2010-10-26 17:54:084805
[email protected]310ebd6302011-10-10 19:06:284806void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:474807 int request_id,
4808 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434809 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474810 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4811 broker_process_handle,
4812 handle);
[email protected]eb415bf0e2011-04-14 02:45:424813}
4814
[email protected]caf706f2010-10-26 17:54:084815#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284816void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154817 if (external_popup_menu_ == NULL) {
4818 // Crash reports from the field indicate that we can be notified with a
4819 // NULL external popup menu (we probably get notified twice).
4820 // If you hit this please file a bug against jcivelli and include the page
4821 // and steps to repro.
4822 NOTREACHED();
4823 return;
4824 }
[email protected]caf706f2010-10-26 17:54:084825 external_popup_menu_->DidSelectItem(selected_index);
4826 external_popup_menu_.reset();
4827}
4828#endif
[email protected]bb461532010-11-26 21:50:234829
[email protected]1b4209f2011-01-07 00:25:404830#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:284831void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:404832 int request_id,
4833 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:494834 const PP_NetAddress_Private& local_addr,
4835 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:404836 pepper_delegate_.OnConnectTcpACK(
4837 request_id,
4838 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4839 local_addr,
4840 remote_addr);
4841}
4842#endif
[email protected]a6097f42011-01-10 08:50:514843
[email protected]310ebd6302011-10-10 19:06:284844void RenderViewImpl::OnContextMenuClosed(
[email protected]b29aa74b2011-01-31 21:41:084845 const webkit_glue::CustomContextMenuContext& custom_context) {
4846 if (custom_context.is_pepper_menu)
4847 pepper_delegate_.OnContextMenuClosed(custom_context);
4848 else
4849 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104850}
[email protected]5a7b15a2011-08-22 22:48:184851
[email protected]310ebd6302011-10-10 19:06:284852void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:184853 if (!webview())
4854 return;
4855 WebFrame* main_frame = webview()->mainFrame();
4856 if (!main_frame)
4857 return;
4858 main_frame->enableViewSourceMode(true);
4859}
[email protected]67bfb83f2011-09-22 03:36:374860
[email protected]310ebd6302011-10-10 19:06:284861void RenderViewImpl::OnLockMouseACK(bool succeeded) {
[email protected]57e02be2011-10-11 19:00:534862 // Mouse Lock removes the system cursor and provides all mouse motion as
4863 // .movementX/Y values on events all sent to a fixed target. This requires
4864 // content to specifically request the mode to be entered.
4865 // Mouse Capture is implicitly given for the duration of a drag event, and
4866 // sends all mouse events to the initial target of the drag.
4867 // If Lock is entered it supercedes any in progress Capture.
4868 if (succeeded)
4869 OnMouseCaptureLost();
4870
[email protected]67bfb83f2011-09-22 03:36:374871 pepper_delegate_.OnLockMouseACK(succeeded);
4872}
4873
[email protected]310ebd6302011-10-10 19:06:284874void RenderViewImpl::OnMouseLockLost() {
[email protected]67bfb83f2011-09-22 03:36:374875 pepper_delegate_.OnMouseLockLost();
4876}
[email protected]c3d45532011-10-07 19:20:404877
[email protected]310ebd6302011-10-10 19:06:284878bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:084879 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:404880}
[email protected]7f3c7af2011-10-20 22:52:514881
[email protected]64d0e192011-12-09 14:44:204882void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:514883 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:184884#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:204885 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:184886#endif
[email protected]7f3c7af2011-10-20 22:52:514887}