blob: 8692f3b320361d79e639a4c15ba9acf8257b613d [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]d19ea342011-04-20 20:31:132089 if (is_content_initiated &&
2090 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:452091 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]445e1042011-12-03 21:03:152092 Referrer referrer(
2093 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2094 getReferrerPolicyFromRequest(request));
[email protected]a58db8b2010-08-24 01:51:232095 // Reset these counters as the RenderView could be reused for the next
2096 // navigation.
2097 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232098 last_page_id_sent_to_browser_ = -1;
[email protected]ae5184d62011-10-06 19:25:582099 OpenURL(frame, url, referrer, default_policy);
[email protected]61c9f032010-03-31 23:04:192100 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172101 }
2102
[email protected]6101c342010-12-16 22:44:372103 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552104 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572105 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372106 // opening a new window). But we sometimes navigate to about:blank to clear a
2107 // tab, and we want to still allow that.
2108 //
[email protected]8f4da8c2011-02-09 19:49:572109 // Note: we do this only for GET requests because our mechanism for switching
2110 // processes only issues GET requests. In particular, POST requests don't
2111 // work, because this mechanism does not preserve form POST data. If it
2112 // becomes necessary to support process switching for POST requests, we will
2113 // need to send the request's httpBody data up to the browser process, and
2114 // issue a special POST navigation in WebKit (via
2115 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2116 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222117 if (!frame->parent() && is_content_initiated &&
[email protected]6101c342010-12-16 22:44:372118 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2119 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2120 bool send_referrer = false;
2121 bool should_fork =
[email protected]e091df82011-10-11 18:13:212122 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172123 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372124 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112125
[email protected]e48869a2011-04-01 19:56:032126 if (!should_fork) {
2127 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362128 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032129 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362130 frame, url, is_content_initiated, is_initial_navigation,
2131 &send_referrer);
[email protected]6101c342010-12-16 22:44:372132 }
2133
2134 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152135 Referrer referrer(
2136 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2137 getReferrerPolicyFromRequest(request));
2138 OpenURL(
2139 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112140 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2141 }
[email protected]3d9689372009-09-10 04:29:172142 }
2143
[email protected]43763f982011-08-26 18:33:402144 // Use the frame's original request's URL rather than the document's URL for
2145 // this check. For a popup, the document's URL may become the opener window's
2146 // URL if the opener has called document.write. See http://crbug.com/93517.
2147 GURL old_url(frame->dataSource()->request().url());
2148
[email protected]3d9689372009-09-10 04:29:172149 // Detect when a page is "forking" a new tab that can be safely rendered in
2150 // its own process. This is done by sites like Gmail that try to open links
2151 // in new windows without script connections back to the original page. We
2152 // treat such cases as browser navigations (in which we will create a new
2153 // renderer for a cross-site navigation), rather than WebKit navigations.
2154 //
2155 // We use the following heuristic to decide whether to fork a new page in its
2156 // own process:
2157 // The parent page must open a new tab to about:blank, set the new tab's
2158 // window.opener to null, and then redirect the tab to a cross-site URL using
2159 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462160 //
2161 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2162 // (see below).
[email protected]3d9689372009-09-10 04:29:172163 bool is_fork =
2164 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582165 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172166 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522167 historyBackListCount() < 1 &&
2168 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172169 // The parent page must have set the child's window.opener to null before
2170 // redirecting to the desired URL.
2171 frame->opener() == NULL &&
2172 // Must be a top-level frame.
2173 frame->parent() == NULL &&
2174 // Must not have issued the request from this page.
2175 is_content_initiated &&
2176 // Must be targeted at the current tab.
2177 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2178 // Must be a JavaScript navigation, which appears as "other".
2179 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462180
2181 // Recognize if this navigation is from a link with rel=noreferrer and
2182 // target=_blank attributes, in which case the opener will be suppressed. If
2183 // so, it is safe to load cross-site pages in a separate process, so we
2184 // should let the browser handle it.
2185 bool is_noreferrer_and_blank_target =
2186 // Frame should be top level and not yet navigated.
2187 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412188 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462189 historyBackListCount() < 1 &&
2190 historyForwardListCount() < 1 &&
2191 // Links with rel=noreferrer will have no Referer field, and their
2192 // resulting frame will have its window.opener suppressed.
2193 // TODO(creis): should add a request.httpReferrer() method to help avoid
2194 // typos on the unusual spelling of Referer.
2195 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2196 opener_suppressed_ &&
2197 frame->opener() == NULL &&
2198 // Links with target=_blank will have no name.
2199 frame->name().isNull() &&
2200 // Another frame (with a non-empty creator) should have initiated the
2201 // request, targeted at this frame.
2202 !creator_url_.is_empty() &&
2203 is_content_initiated &&
2204 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2205 type == WebKit::WebNavigationTypeOther;
2206
2207 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172208 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152209 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172210 return WebKit::WebNavigationPolicyIgnore;
2211 }
2212
2213 return default_policy;
2214}
2215
[email protected]310ebd6302011-10-10 19:06:282216bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492217 WebFrame* frame, const WebURLRequest& request) {
2218 // We allow WebKit to think that everything can be handled even though
2219 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342220 return true;
2221}
2222
[email protected]310ebd6302011-10-10 19:06:282223WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492224 WebFrame* frame, const WebURLRequest& request) {
2225 NOTREACHED(); // Since we said we can handle all requests.
2226 return WebURLError();
2227}
2228
[email protected]310ebd6302011-10-10 19:06:282229WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492230 WebFrame* frame, const WebURLRequest& request) {
2231 WebURLError error;
2232 error.domain = WebString::fromUTF8(net::kErrorDomain);
2233 error.reason = net::ERR_ABORTED;
2234 error.unreachableURL = request.url();
2235 return error;
[email protected]7b7a7dc2009-10-19 02:23:342236}
2237
[email protected]310ebd6302011-10-10 19:06:282238void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492239 WebFrame*, const WebURLError&) {
2240 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342241}
2242
[email protected]310ebd6302011-10-10 19:06:282243void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432244 const WebKit::WebFormElement& form) {
2245 // Some login forms have onSubmit handlers that put a hash of the password
2246 // into a hidden field and then clear the password. (Issue 28910.)
2247 // This method gets called before any of those handlers run, so save away
2248 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072249 DocumentState* document_state =
2250 DocumentState::FromDataSource(frame->dataSource());
2251 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432252 PasswordFormDomManager::CreatePasswordForm(form));
2253}
2254
[email protected]310ebd6302011-10-10 19:06:282255void RenderViewImpl::willSubmitForm(WebFrame* frame,
2256 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072257 DocumentState* document_state =
2258 DocumentState::FromDataSource(frame->provisionalDataSource());
2259 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172260
[email protected]2905f742011-10-13 03:51:582261 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2262 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172263
2264 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352265 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072266 document_state->set_searchable_form_url(web_searchable_form_data.url());
2267 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212268 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432269 PasswordForm* password_form_data =
2270 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072271 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432272
[email protected]098c95cb2011-04-28 16:49:012273 // In order to save the password that the user actually typed and not one
2274 // that may have gotten transformed by the site prior to submit, recover it
2275 // from the form contents already stored by |willSendSubmitEvent| into the
2276 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2277 // which is what we're storing into now.)
2278 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072279 DocumentState* old_document_state =
2280 DocumentState::FromDataSource(frame->dataSource());
2281 if (old_document_state) {
2282 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432283 if (old_form_data && old_form_data->action == password_form_data->action)
2284 password_form_data->password_value = old_form_data->password_value;
2285 }
2286 }
[email protected]3d9689372009-09-10 04:29:172287
[email protected]2a5b1732011-04-01 23:55:552288 FOR_EACH_OBSERVER(
2289 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172290}
2291
[email protected]310ebd6302011-10-10 19:06:282292void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172293 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2294 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382295 FOR_EACH_OBSERVER(
2296 RenderViewObserver, observers_,
2297 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172298}
2299
[email protected]310ebd6302011-10-10 19:06:282300void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382301 FOR_EACH_OBSERVER(
2302 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172303}
2304
[email protected]310ebd6302011-10-10 19:06:282305void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172306 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152307 if (!frame->parent()) {
2308 WebDataSource* ds = frame->provisionalDataSource();
2309 // If there's no provisional data source, it's a reference fragment
2310 // navigation.
2311 completed_client_redirect_src_ = Referrer(
2312 from, ds ? getReferrerPolicyFromRequest(ds->request()) :
2313 frame->referrerPolicy());
2314 }
[email protected]eb0bff942011-04-07 22:08:382315 FOR_EACH_OBSERVER(
2316 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172317}
2318
[email protected]310ebd6302011-10-10 19:06:282319void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072320 DocumentState* document_state = DocumentState::FromDataSource(ds);
2321 if (!document_state) {
2322 document_state = new DocumentState;
2323 ds->setExtraData(document_state);
2324 }
2325
[email protected]3d9689372009-09-10 04:29:172326 // The rest of RenderView assumes that a WebDataSource will always have a
2327 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072328 bool content_initiated = !pending_navigation_params_.get();
2329 if (content_initiated)
2330 document_state->set_navigation_state(
2331 NavigationState::CreateContentInitiated());
2332 else
2333 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512334
[email protected]007733c2011-11-17 00:34:072335 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512336 // navigating from a page that used prefetching using a link on that
2337 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072338 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512339 // this value appropriately.
2340 // TODO(gavinp): catch the important case of navigation in a new
2341 // renderer process.
2342 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302343 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522344 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512345 const GURL referrer(
2346 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2347 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072348 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512349 old_frame->dataSource())->was_prefetcher()) {
2350 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2351 WebDataSource* old_frame_ds = old_frame->dataSource();
2352 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072353 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512354 break;
2355 }
2356 }
2357 }
2358 }
2359 }
2360
[email protected]4c1b6f0b2010-02-07 16:38:182361 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522362 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512363 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182364 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072365 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182366 break;
2367 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072368 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182369 break;
2370 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072371 document_state->set_load_type(
2372 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182373 break;
2374 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072375 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182376 break;
2377 }
2378 }
[email protected]fa7b6b542009-11-03 05:02:302379
[email protected]946a0032011-03-31 18:42:282380 FOR_EACH_OBSERVER(
2381 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172382}
2383
[email protected]007733c2011-11-17 00:34:072384void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2385 DocumentState* document_state) {
2386 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2387
2388 if (document_state->request_time().is_null())
2389 document_state->set_request_time(params.request_time);
2390
2391 // A navigation resulting from loading a javascript URL should not be treated
2392 // as a browser initiated event. Instead, we want it to look as if the page
2393 // initiated any load resulting from JS execution.
2394 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2395 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2396 params.page_id,
2397 params.pending_history_list_offset,
2398 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482399 navigation_state->set_transferred_request_child_id(
2400 params.transferred_request_child_id);
2401 navigation_state->set_transferred_request_request_id(
2402 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072403 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2404 // We're doing a load of a page that was restored from the last session.
2405 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2406 // which can result in stale data for pages that are set to expire. We
2407 // explicitly override that by setting the policy here so that as
2408 // necessary we load from the network.
2409 document_state->set_cache_policy_override(
2410 WebURLRequest::UseProtocolCachePolicy);
2411 }
2412 document_state->set_navigation_state(navigation_state);
2413 } else {
2414 document_state->set_navigation_state(
2415 NavigationState::CreateContentInitiated());
2416 }
2417
2418 if (IsReload(params))
2419 document_state->set_load_type(DocumentState::RELOAD);
2420 else if (!params.state.empty())
2421 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2422 else
2423 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2424
2425 pending_navigation_params_.reset();
2426}
2427
[email protected]310ebd6302011-10-10 19:06:282428void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172429 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072430 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172431
[email protected]3d9689372009-09-10 04:29:172432 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072433 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172434 double event_time = ds->triggeringEventTime();
2435 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072436 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172437 }
2438
[email protected]05c8e502010-08-15 15:13:522439 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072440 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522441
[email protected]3d9689372009-09-10 04:29:172442 bool is_top_most = !frame->parent();
2443 if (is_top_most) {
2444 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132445 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172446
2447 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152448 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172449 } else if (frame->parent()->isLoading()) {
2450 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002451 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072452 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582453 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172454 }
2455
[email protected]28685da92011-02-07 21:49:172456 FOR_EACH_OBSERVER(
2457 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2458
[email protected]3d9689372009-09-10 04:29:172459 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592460 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262461 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172462}
2463
[email protected]310ebd6302011-10-10 19:06:282464void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2465 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172466 if (frame->parent())
2467 return;
2468 // Received a redirect on the main frame.
2469 WebDataSource* data_source = frame->provisionalDataSource();
2470 if (!data_source) {
2471 // Should only be invoked when we have a data source.
2472 NOTREACHED();
2473 return;
2474 }
2475 std::vector<GURL> redirects;
2476 GetRedirectChain(data_source, &redirects);
2477 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512478 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592479 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172480 }
2481}
2482
[email protected]310ebd6302011-10-10 19:06:282483void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2484 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172485 // Notify the browser that we failed a provisional load with an error.
2486 //
2487 // Note: It is important this notification occur before DidStopLoading so the
2488 // SSL manager can react to the provisional load failure before being
2489 // notified the load stopped.
2490 //
2491 WebDataSource* ds = frame->provisionalDataSource();
2492 DCHECK(ds);
2493
2494 const WebURLRequest& failed_request = ds->request();
2495
[email protected]28685da92011-02-07 21:49:172496 FOR_EACH_OBSERVER(
2497 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2498
[email protected]3d9689372009-09-10 04:29:172499 bool show_repost_interstitial =
2500 (error.reason == net::ERR_CACHE_MISS &&
2501 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582502
2503 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2504 params.frame_id = frame->identifier();
2505 params.is_main_frame = !frame->parent();
2506 params.error_code = error.reason;
2507 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2508 failed_request,
2509 error,
2510 NULL,
2511 &params.error_description);
2512 params.url = error.unreachableURL;
2513 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172514 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582515 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172516
2517 // Don't display an error page if this is simply a cancelled load. Aside
2518 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2519 if (error.reason == net::ERR_ABORTED)
2520 return;
[email protected]b553edd52012-01-10 12:15:232521 // Don't display an error message if the request was handled by an
2522 // external protocol handler.
2523 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2524 return;
[email protected]3d9689372009-09-10 04:29:172525
2526 // Make sure we never show errors in view source mode.
2527 frame->enableViewSourceMode(false);
2528
[email protected]007733c2011-11-17 00:34:072529 DocumentState* document_state = DocumentState::FromDataSource(ds);
2530 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172531
2532 // If this is a failed back/forward/reload navigation, then we need to do a
2533 // 'replace' load. This is necessary to avoid messing up session history.
2534 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2535 // as session history is concerned.
2536 //
2537 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2538 // the page id.
2539 //
2540 bool replace =
2541 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582542 navigation_state->transition_type() ==
2543 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172544
2545 // If we failed on a browser initiated request, then make sure that our error
2546 // page load is regarded as the same browser initiated request.
2547 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072548 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2549 pending_navigation_params_->page_id =
2550 navigation_state->pending_page_id();
2551 pending_navigation_params_->pending_history_list_offset =
2552 navigation_state->pending_history_list_offset();
2553 pending_navigation_params_->transition =
2554 navigation_state->transition_type();
2555 pending_navigation_params_->request_time =
2556 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172557 }
2558
2559 // Provide the user with a more helpful error page?
2560 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2561 return;
2562
2563 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082564 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172565}
2566
[email protected]310ebd6302011-10-10 19:06:282567void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172568 WebFrame* frame, const char* data, size_t data_len,
2569 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072570 DocumentState* document_state =
2571 DocumentState::FromDataSource(frame->dataSource());
2572 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172573}
2574
[email protected]310ebd6302011-10-10 19:06:282575void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2576 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072577 DocumentState* document_state =
2578 DocumentState::FromDataSource(frame->dataSource());
2579 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172580
[email protected]007733c2011-11-17 00:34:072581 if (document_state->commit_load_time().is_null())
2582 document_state->set_commit_load_time(Time::Now());
2583
[email protected]3d9689372009-09-10 04:29:172584 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202585 // When we perform a new navigation, we need to update the last committed
2586 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172587 UpdateSessionHistory(frame);
2588
2589 // We bump our Page ID to correspond with the new session history entry.
2590 page_id_ = next_page_id_++;
2591
[email protected]3cc72b12010-03-18 23:03:002592 // Advance our offset in session history, applying the length limit. There
2593 // is now no forward history.
2594 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102595 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2596 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002597 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032598 history_page_ids_.resize(history_list_length_, -1);
2599 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172600 } else {
2601 // Inspect the navigation_state on this frame to see if the navigation
2602 // corresponds to a session history navigation... Note: |frame| may or
2603 // may not be the toplevel frame, but for the case of capturing session
2604 // history, the first committed frame suffices. We keep track of whether
2605 // we've seen this commit before so that only capture session history once
2606 // per navigation.
2607 //
2608 // Note that we need to check if the page ID changed. In the case of a
2609 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2610 // previous URL and the current page ID, which would be wrong.
2611 if (navigation_state->pending_page_id() != -1 &&
2612 navigation_state->pending_page_id() != page_id_ &&
2613 !navigation_state->request_committed()) {
2614 // This is a successful session history navigation!
2615 UpdateSessionHistory(frame);
2616 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002617
2618 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032619
2620 // If the history list is valid, our list of page IDs should be correct.
2621 DCHECK(history_list_length_ <= 0 ||
2622 history_list_offset_ < 0 ||
2623 history_list_offset_ >= history_list_length_ ||
2624 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172625 }
2626 }
2627
[email protected]28685da92011-02-07 21:49:172628 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2629 DidCommitProvisionalLoad(frame, is_new_navigation));
2630
[email protected]3d9689372009-09-10 04:29:172631 // Remember that we've already processed this request, so we don't update
2632 // the session history again. We do this regardless of whether this is
2633 // a session history navigation, because if we attempted a session history
2634 // navigation without valid HistoryItem state, WebCore will think it is a
2635 // new navigation.
2636 navigation_state->set_request_committed(true);
2637
2638 UpdateURL(frame);
2639
2640 // If this committed load was initiated by a client redirect, we're
2641 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152642 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172643
2644 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272645 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172646}
2647
[email protected]310ebd6302011-10-10 19:06:282648void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102649 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2650 DidClearWindowObject(frame));
2651
[email protected]b6cb3a842011-06-24 18:28:412652 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212653 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252654 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2655 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272656 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172657 }
[email protected]3d9689372009-09-10 04:29:172658}
2659
[email protected]310ebd6302011-10-10 19:06:282660void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172661 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412662 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252663 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272664 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172665 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2666 }
[email protected]e48869a2011-04-01 19:56:032667
2668 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2669 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172670}
2671
[email protected]310ebd6302011-10-10 19:06:282672void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2673 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462674 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172675
2676 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272677 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172678}
2679
[email protected]310ebd6302011-10-10 19:06:282680void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132681 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2682 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582683}
2684
[email protected]310ebd6302011-10-10 19:06:282685void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172686 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072687 DocumentState* document_state = DocumentState::FromDataSource(ds);
2688 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172689
[email protected]622474d2010-11-04 09:21:082690 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172691
[email protected]28685da92011-02-07 21:49:172692 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2693 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172694
2695 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272696 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172697}
2698
[email protected]310ebd6302011-10-10 19:06:282699void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082700 if (webview()->mainFrame() == frame) {
2701 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2702 page_id_));
2703 }
[email protected]3d9689372009-09-10 04:29:172704}
2705
[email protected]310ebd6302011-10-10 19:06:282706void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312707 WebDataSource* ds = frame->dataSource();
2708 DCHECK(ds);
2709
2710
[email protected]28685da92011-02-07 21:49:172711 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312712
2713 const WebURLRequest& failed_request = ds->request();
2714 string16 error_description;
2715 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2716 failed_request,
2717 error,
2718 NULL,
2719 &error_description);
2720 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2721 frame->identifier(),
2722 failed_request.url(),
2723 !frame->parent(),
2724 error.reason,
2725 error_description));
[email protected]3d9689372009-09-10 04:29:172726}
2727
[email protected]310ebd6302011-10-10 19:06:282728void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172729 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072730 DocumentState* document_state = DocumentState::FromDataSource(ds);
2731 if (document_state->finish_load_time().is_null())
2732 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412733
[email protected]676126f72011-01-15 00:03:512734 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172735
[email protected]1a55c5be2011-11-29 11:36:312736 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2737 frame->identifier(),
2738 ds->request().url(),
2739 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172740}
2741
[email protected]310ebd6302011-10-10 19:06:282742void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172743 WebFrame* frame, bool is_new_navigation) {
2744 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072745 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172746 // update the ExtraData on the datasource so that others who read the
2747 // ExtraData will get the new NavigationState. Similarly, if we did not
2748 // initiate this navigation, then we need to take care to reset any pre-
2749 // existing navigation state to a content-initiated navigation state.
2750 // DidCreateDataSource conveniently takes care of this for us.
2751 didCreateDataSource(frame, frame->dataSource());
2752
[email protected]007733c2011-11-17 00:34:072753 DocumentState* document_state =
2754 DocumentState::FromDataSource(frame->dataSource());
2755 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092756 new_state->set_was_within_same_page(true);
2757
[email protected]3d9689372009-09-10 04:29:172758 didCommitProvisionalLoad(frame, is_new_navigation);
2759
[email protected]750fcf872011-08-03 23:10:472760 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2761 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172762}
2763
[email protected]310ebd6302011-10-10 19:06:282764void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312765 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592766}
2767
[email protected]310ebd6302011-10-10 19:06:282768void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172769 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2770 // Ignore
2771}
2772
[email protected]310ebd6302011-10-10 19:06:282773void RenderViewImpl::willSendRequest(WebFrame* frame,
2774 unsigned identifier,
2775 WebURLRequest& request,
2776 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302777 WebFrame* top_frame = frame->top();
2778 if (!top_frame)
2779 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512780 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2781 WebDataSource* top_data_source = top_frame->dataSource();
2782 WebDataSource* data_source =
2783 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222784
[email protected]78d5cfe2011-02-04 08:43:222785 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032786 GURL new_url;
2787 if (content::GetContentClient()->renderer()->WillSendRequest(
2788 frame, request_url, &new_url)) {
2789 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222790 }
2791
[email protected]2905f742011-10-13 03:51:582792 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072793 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2794 NavigationState* navigation_state = document_state->navigation_state();
2795 if (document_state) {
2796 if (document_state->is_cache_policy_override_set())
2797 request.setCachePolicy(document_state->cache_policy_override());
2798 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:302799 }
[email protected]8a3125a712010-08-09 18:58:512800
[email protected]91043a8232011-11-04 16:41:192801 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:062802 new RequestExtraData(frame->referrerPolicy(),
2803 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:192804 frame->identifier(),
2805 frame->parent() == top_frame,
2806 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:482807 transition_type,
2808 navigation_state->transferred_request_child_id(),
2809 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:572810
[email protected]007733c2011-11-17 00:34:072811 DocumentState* top_document_state =
2812 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:572813 // TODO(gavinp): separate out prefetching and prerender field trials
2814 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:072815 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:572816 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2817 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:072818 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512819
[email protected]3d9689372009-09-10 04:29:172820 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132821 request.setHasUserGesture(frame->isProcessingUserGesture());
2822
[email protected]0a8db0d2011-04-13 15:15:402823 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132824 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172825}
2826
[email protected]310ebd6302011-10-10 19:06:282827void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:172828 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492829
[email protected]3d9689372009-09-10 04:29:172830 // Only do this for responses that correspond to a provisional data source
2831 // of the top-most frame. If we have a provisional data source, then we
2832 // can't have any sub-resources yet, so we know that this response must
2833 // correspond to a frame load.
2834 if (!frame->provisionalDataSource() || frame->parent())
2835 return;
2836
2837 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082838 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172839 if (frame->isViewSourceModeEnabled())
2840 return;
2841
[email protected]007733c2011-11-17 00:34:072842 DocumentState* document_state =
2843 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:082844 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532845
[email protected]972ebdff2010-06-10 22:59:072846 // Record page load flags.
[email protected]007733c2011-11-17 00:34:072847 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2848 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
2849 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:572850 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:072851 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
2852 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092853 // Whether or not the http status code actually corresponds to an error is
2854 // only checked when the page is done loading, if |use_error_page| is
2855 // still true.
[email protected]007733c2011-11-17 00:34:072856 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172857}
2858
[email protected]310ebd6302011-10-10 19:06:282859void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:172860 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:072861 DocumentState* document_state =
2862 DocumentState::FromDataSource(frame->dataSource());
2863 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172864 return;
2865
[email protected]7bfc153f2011-09-23 22:00:202866 // Do not show error page when DevTools is attached.
2867 if (devtools_agent_->IsAttached())
2868 return;
2869
[email protected]06333afe2011-02-24 14:55:092870 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:072871 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:082872 if (http_status_code == 404) {
2873 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412874 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172875
[email protected]b6cb3a842011-06-24 18:28:412876 const GURL& error_page_url =
2877 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092878 if (error_page_url.is_valid()) {
2879 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472880 original_error.domain = "http";
2881 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412882 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172883
[email protected]007733c2011-11-17 00:34:072884 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:092885 new AltErrorPageResourceFetcher(
2886 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:082887 base::Bind(&RenderViewImpl::AltErrorPageFinished,
2888 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:092889 return;
2890 }
2891 }
[email protected]3d9689372009-09-10 04:29:172892
[email protected]e6a2ce52011-10-08 01:40:132893 std::string error_domain;
2894 if (content::GetContentClient()->renderer()->HasErrorPage(
2895 http_status_code, &error_domain)) {
2896 WebURLError error;
2897 error.unreachableURL = frame->document().url();
2898 error.domain = WebString::fromUTF8(error_domain);
2899 error.reason = http_status_code;
2900
2901 LoadNavigationErrorPage(
2902 frame, frame->dataSource()->request(), error, std::string(), true);
2903 }
[email protected]3d9689372009-09-10 04:29:172904}
2905
[email protected]310ebd6302011-10-10 19:06:282906void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:172907 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2908 // Ignore
2909}
2910
[email protected]310ebd6302011-10-10 19:06:282911void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:172912 WebFrame* frame, const WebURLRequest& request,
2913 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:002914 // The recipients of this message have no use for data: URLs: they don't
2915 // affect the page's insecure content list and are not in the disk cache. To
2916 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
2917 // filter them out here.
2918 GURL url(request.url());
2919 if (url.SchemeIs("data"))
2920 return;
2921
[email protected]3d9689372009-09-10 04:29:172922 // Let the browser know we loaded a resource from the memory cache. This
2923 // message is needed to display the correct SSL indicators.
2924 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2925 routing_id_,
[email protected]84703292011-10-28 20:44:002926 url,
[email protected]70435962011-08-02 20:13:282927 response.securityInfo(),
2928 request.httpMethod().utf8(),
2929 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172930}
2931
[email protected]310ebd6302011-10-10 19:06:282932void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292933 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2934}
2935
[email protected]310ebd6302011-10-10 19:06:282936void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:022937 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292938 Send(new ViewHostMsg_DidRunInsecureContent(
2939 routing_id_,
[email protected]92771112011-01-20 00:13:022940 origin.toString().utf8(),
2941 target));
[email protected]e3d60e5d2009-09-25 21:08:292942}
2943
[email protected]310ebd6302011-10-10 19:06:282944void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:032945 webkit_glue::WebURLLoaderImpl* loader_impl =
2946 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2947 loader_impl->UpdateRoutingId(routing_id_);
2948}
2949
[email protected]310ebd6302011-10-10 19:06:282950void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172951 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2952}
2953
[email protected]310ebd6302011-10-10 19:06:282954void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
2955 v8::Handle<v8::Context> context,
2956 int world_id) {
[email protected]5bc10932011-09-21 21:03:302957 content::GetContentClient()->renderer()->DidCreateScriptContext(
2958 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282959}
2960
[email protected]310ebd6302011-10-10 19:06:282961void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
2962 v8::Handle<v8::Context> context,
2963 int world_id) {
[email protected]5bc10932011-09-21 21:03:302964 content::GetContentClient()->renderer()->WillReleaseScriptContext(
2965 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282966}
2967
[email protected]310ebd6302011-10-10 19:06:282968void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:072969 // We don't always want to send the change messages over IPC, only if we've
2970 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2971 // message.
2972 if (!send_preferred_size_changes_ || !webview())
2973 return;
2974
[email protected]705243f2010-05-05 19:58:072975 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2976 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532977
2978 // In the presence of zoom, these sizes are still reported as if unzoomed,
2979 // so we need to adjust.
2980 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2981 size.set_width(static_cast<int>(size.width() * zoom_factor));
2982 size.set_height(static_cast<int>(size.height() * zoom_factor));
2983
[email protected]6b5576cb2011-12-05 08:23:002984 if (!size.height())
2985 size.set_height(preferred_size_.height());
2986
[email protected]705243f2010-05-05 19:58:072987 if (size == preferred_size_)
2988 return;
[email protected]c27324b2009-11-19 22:44:292989
[email protected]705243f2010-05-05 19:58:072990 preferred_size_ = size;
2991 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2992 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172993}
2994
[email protected]273558fb2012-01-12 15:03:512995void RenderViewImpl::EnsureMediaStreamImpl() {
2996#if defined(ENABLE_P2P_APIS)
2997 if (!p2p_socket_dispatcher_)
2998 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
2999#endif
3000
3001 if (!media_stream_dispatcher_)
3002 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3003
3004 if (!media_stream_impl_.get()) {
3005 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3006 media_stream_impl_ = new MediaStreamImpl(
3007 media_stream_dispatcher_,
3008 p2p_socket_dispatcher_,
3009 RenderThreadImpl::current()->video_capture_impl_manager(),
3010 factory);
3011 }
3012}
3013
[email protected]310ebd6302011-10-10 19:06:283014void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3015 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313016 if (webview()->mainFrame() != frame)
3017 return;
3018 WebView* frameView = frame->view();
3019 if (!frameView)
3020 return;
3021
3022 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3023 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3024
3025 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3026 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3027 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3028 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3029
3030 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3031 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3032 }
3033}
3034
[email protected]310ebd6302011-10-10 19:06:283035void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313036 WebSize offset = frame->scrollOffset();
3037 WebSize minimum_offset = frame->minimumScrollOffset();
3038 WebSize maximum_offset = frame->maximumScrollOffset();
3039
3040 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3041 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3042
3043 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3044 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3045 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3046 routing_id_, is_pinned_to_left, is_pinned_to_right));
3047
3048 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3049 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3050 }
3051}
3052
[email protected]310ebd6302011-10-10 19:06:283053void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493054 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313055
3056 if (webview()->mainFrame() == frame)
3057 UpdateScrollState(frame);
3058}
3059
[email protected]310ebd6302011-10-10 19:06:283060void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313061 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493062}
3063
[email protected]310ebd6302011-10-10 19:06:283064void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3065 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113066 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3067 if (!count)
3068 active_match_ordinal = 0;
3069
3070 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3071 routing_id_,
3072 request_id,
3073 count,
3074 gfx::Rect(),
3075 active_match_ordinal,
3076 final_update);
3077
[email protected]8922e1f2009-10-03 05:01:263078 // If we have a message that has been queued up, then we should just replace
3079 // it. The ACK from the browser will make sure it gets sent when the browser
3080 // wants it.
3081 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263082 queued_find_reply_message_.reset(msg);
3083 } else {
3084 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113085 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263086 }
3087}
3088
[email protected]310ebd6302011-10-10 19:06:283089void RenderViewImpl::reportFindInPageSelection(int request_id,
3090 int active_match_ordinal,
3091 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263092 // Send the search result over to the browser process.
3093 Send(new ViewHostMsg_Find_Reply(routing_id_,
3094 request_id,
3095 -1,
3096 selection_rect,
3097 active_match_ordinal,
3098 false));
3099}
3100
[email protected]310ebd6302011-10-10 19:06:283101void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223102 WebFrame* frame,
3103 WebFileSystem::Type type,
3104 long long size,
[email protected]d275d7a2010-11-03 01:34:493105 bool create,
[email protected]2b06a992010-08-21 05:48:223106 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083107 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223108
[email protected]b6cb3a842011-06-24 18:28:413109 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563110 if (origin.isUnique()) {
3111 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083112 callbacks->didFail(WebKit::WebFileErrorAbort);
3113 return;
3114 }
[email protected]2b06a992010-08-21 05:48:223115
[email protected]c5a272d2010-09-27 18:37:083116 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3117 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493118 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223119}
3120
[email protected]310ebd6302011-10-10 19:06:283121void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403122 WebFrame* frame,
3123 WebStorageQuotaType type,
3124 WebStorageQuotaCallbacks* callbacks) {
3125 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413126 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563127 if (origin.isUnique()) {
3128 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403129 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3130 return;
3131 }
3132 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533133 GURL(origin.toString()),
3134 static_cast<quota::StorageType>(type),
3135 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403136}
3137
[email protected]310ebd6302011-10-10 19:06:283138void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403139 WebFrame* frame,
3140 WebStorageQuotaType type,
3141 unsigned long long requested_size,
3142 WebStorageQuotaCallbacks* callbacks) {
3143 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413144 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563145 if (origin.isUnique()) {
3146 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403147 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3148 return;
3149 }
3150 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533151 routing_id(), GURL(origin.toString()),
3152 static_cast<quota::StorageType>(type), requested_size,
3153 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403154}
3155
[email protected]8b5af492011-11-28 21:50:583156void RenderViewImpl::registerIntentService(
3157 WebKit::WebFrame* frame, const WebKit::WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063158 string16 title = service.title();
3159 if (title.empty())
3160 title = webview()->mainFrame()->document().title();
3161
[email protected]8b5af492011-11-28 21:50:583162 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3163 service.action(),
3164 service.type(),
3165 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063166 title,
[email protected]8b5af492011-11-28 21:50:583167 service.disposition()));
3168}
3169
3170void RenderViewImpl::dispatchIntent(WebKit::WebFrame* frame,
3171 const WebKit::WebIntent& intent) {
[email protected]678105012011-12-09 04:01:213172 webkit_glue::WebIntentData intent_data(intent);
[email protected]8b5af492011-11-28 21:50:583173 Send(new IntentsHostMsg_WebIntentDispatch(
3174 routing_id_, intent_data, intent.identifier()));
3175}
3176
[email protected]18d5be92011-07-25 18:00:193177// WebKit::WebPageSerializerClient implementation ------------------------------
3178
[email protected]310ebd6302011-10-10 19:06:283179void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193180 const WebURL& frame_url,
3181 const WebCString& data,
3182 WebPageSerializerClient::PageSerializationStatus status) {
3183 Send(new ViewHostMsg_SendSerializedHtmlData(
3184 routing_id(),
3185 frame_url,
3186 data.data(),
3187 static_cast<int32>(status)));
3188}
3189
[email protected]a2ef54c2011-10-10 16:20:313190// content::RenderView implementation ------------------------------------------
3191
[email protected]310ebd6302011-10-10 19:06:283192bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313193 return RenderWidget::Send(message);
3194}
3195
[email protected]310ebd6302011-10-10 19:06:283196int RenderViewImpl::GetRoutingId() const {
[email protected]a2ef54c2011-10-10 16:20:313197 return routing_id_;
3198}
3199
[email protected]310ebd6302011-10-10 19:06:283200int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313201 return page_id_;
3202}
3203
[email protected]310ebd6302011-10-10 19:06:283204gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313205 return size();
3206}
3207
[email protected]310ebd6302011-10-10 19:06:283208gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313209 return host_window();
3210}
3211
[email protected]310ebd6302011-10-10 19:06:283212WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313213 return webkit_preferences_;
3214}
3215
[email protected]310ebd6302011-10-10 19:06:283216WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313217 return webview();
3218}
3219
[email protected]310ebd6302011-10-10 19:06:283220WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313221 if (!webview())
3222 return WebNode();
3223 WebFrame* focused_frame = webview()->focusedFrame();
3224 if (focused_frame) {
3225 WebDocument doc = focused_frame->document();
3226 if (!doc.isNull())
3227 return doc.focusedNode();
3228 }
3229
3230 return WebNode();
3231}
3232
[email protected]310ebd6302011-10-10 19:06:283233WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313234 return context_menu_node_;
3235}
3236
[email protected]310ebd6302011-10-10 19:06:283237bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313238 bool is_editable_node = false;
3239 if (!node.isNull()) {
3240 if (node.isContentEditable()) {
3241 is_editable_node = true;
3242 } else if (node.isElementNode()) {
3243 is_editable_node =
3244 node.toConst<WebElement>().isTextFormControlElement();
3245 }
3246 }
3247 return is_editable_node;
3248}
3249
[email protected]310ebd6302011-10-10 19:06:283250WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313251 WebKit::WebFrame* frame,
3252 const webkit::WebPluginInfo& info,
3253 const WebKit::WebPluginParams& params) {
3254 bool pepper_plugin_was_registered = false;
3255 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3256 pepper_delegate_.CreatePepperPluginModule(info,
3257 &pepper_plugin_was_registered));
3258 if (pepper_plugin_was_registered) {
3259 if (!pepper_module)
3260 return NULL;
3261 return new webkit::ppapi::WebPluginImpl(
3262 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3263 }
3264
3265 return new webkit::npapi::WebPluginImpl(
3266 frame, params, info.path, AsWeakPtr());
3267}
3268
[email protected]310ebd6302011-10-10 19:06:283269void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3270 const string16& jscript,
3271 int id,
3272 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313273 v8::Handle<v8::Value> result;
3274 WebFrame* web_frame = GetChildFrame(frame_xpath);
3275 if (web_frame)
3276 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3277 if (notify_result) {
3278 ListValue list;
3279 if (!result.IsEmpty() && web_frame) {
3280 v8::HandleScope handle_scope;
3281 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3282 v8::Context::Scope context_scope(context);
3283 V8ValueConverterImpl converter;
3284 converter.set_allow_date(true);
3285 converter.set_allow_regexp(true);
3286 list.Set(0, converter.FromV8Value(result, context));
3287 } else {
3288 list.Set(0, Value::CreateNullValue());
3289 }
3290 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3291 }
3292}
3293
[email protected]310ebd6302011-10-10 19:06:283294bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313295 return (!send_preferred_size_changes_ ||
3296 (disable_scrollbars_size_limit_.width() <= width ||
3297 disable_scrollbars_size_limit_.height() <= height));
3298}
3299
[email protected]310ebd6302011-10-10 19:06:283300int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313301 return enabled_bindings_;
3302}
3303
[email protected]310ebd6302011-10-10 19:06:283304void RenderViewImpl::SetEnabledBindings(int enabled_bindings) {
[email protected]a2ef54c2011-10-10 16:20:313305 enabled_bindings_ = enabled_bindings;
3306}
3307
[email protected]310ebd6302011-10-10 19:06:283308bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313309 return send_content_state_immediately_;
3310}
3311
[email protected]310ebd6302011-10-10 19:06:283312float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313313 return filtered_time_per_frame();
3314}
3315
[email protected]310ebd6302011-10-10 19:06:283316void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3317 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313318 showContextMenu(frame, data);
3319}
3320
[email protected]310ebd6302011-10-10 19:06:283321WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313322 return visibilityState();
3323}
3324
[email protected]310ebd6302011-10-10 19:06:283325void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3326 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313327 return runModalAlertDialog(frame, message);
3328}
3329
[email protected]310ebd6302011-10-10 19:06:283330void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313331 WebKit::WebFrame* frame,
3332 const WebKit::WebURLRequest& request,
3333 WebKit::WebNavigationPolicy policy) {
3334 loadURLExternally(frame, request, policy);
3335}
3336
3337// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513338
[email protected]310ebd6302011-10-10 19:06:283339webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533340 const FilePath& file_path,
3341 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593342 if (!PluginChannelHost::IsListening())
3343 return NULL;
3344
[email protected]00c39612010-03-06 02:53:283345 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463346 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323347#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223348 return webkit::npapi::WebPluginDelegateImpl::Create(
3349 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093350#else
[email protected]7398dcc2011-09-06 21:40:323351 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223352 NOTIMPLEMENTED();
3353 return NULL;
[email protected]7b6616f2010-01-14 18:07:553354#endif
[email protected]f103ab72009-09-02 17:10:593355 }
3356
[email protected]4e0616e2010-05-28 14:55:533357 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593358}
3359
[email protected]310ebd6302011-10-10 19:06:283360void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033361#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273362 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593363#endif
3364}
3365
[email protected]310ebd6302011-10-10 19:06:283366void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033367#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273368 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593369#endif
3370 CleanupWindowInPluginMoves(window);
3371}
3372
[email protected]310ebd6302011-10-10 19:06:283373void RenderViewImpl::DidMovePlugin(
3374 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593375 SchedulePluginMove(move);
3376}
3377
[email protected]310ebd6302011-10-10 19:06:283378void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593379 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523380 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593381}
3382
[email protected]310ebd6302011-10-10 19:06:283383void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593384 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523385 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593386}
3387
[email protected]310ebd6302011-10-10 19:06:283388WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513389 return &cookie_jar_;
3390}
3391
[email protected]a9288f52011-11-17 05:18:163392void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073393 Send(new ViewHostMsg_MediaNotification(routing_id_,
3394 reinterpret_cast<int64>(player),
3395 player->hasVideo(),
3396 player->hasAudio(),
3397 true));
3398}
3399
[email protected]a9288f52011-11-17 05:18:163400void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073401 Send(new ViewHostMsg_MediaNotification(routing_id_,
3402 reinterpret_cast<int64>(player),
3403 player->hasVideo(),
3404 player->hasAudio(),
3405 false));
3406}
3407
[email protected]a9288f52011-11-17 05:18:163408void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073409 DidPause(player);
3410}
3411
[email protected]310ebd6302011-10-10 19:06:283412void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293413 if (!webview())
3414 return;
3415
[email protected]26aa0482009-09-30 16:55:273416 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173417 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293418 return;
[email protected]ca948a22009-06-25 19:36:173419
3420 Send(new ViewHostMsg_UpdateState(
3421 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293422}
3423
[email protected]310ebd6302011-10-10 19:06:283424void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363425 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003426 if (!frame)
3427 return;
[email protected]b781ff282011-08-20 06:19:363428
[email protected]b781ff282011-08-20 06:19:363429 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003430 if (!webview()->caretOrSelectionRange(&location, &length))
3431 return;
3432
3433 string16 text;
3434 size_t offset;
3435 ui::Range range(location, location + length);
3436
3437 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3438 // If current focused element is editable, we will send 100 more chars
3439 // before and after selection. It is for input method surrounding text
3440 // feature.
3441 if (location > kExtraCharsBeforeAndAfterSelection)
3442 offset = location - kExtraCharsBeforeAndAfterSelection;
3443 else
3444 offset = 0;
3445 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3446 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3447 if (!webrange.isNull())
3448 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3449 } else {
3450 offset = location;
3451 text = frame->selectionAsText();
[email protected]e8cdf3532011-10-29 00:50:523452 // http://crbug.com/101435
3453 // In some case, frame->selectionAsText() returned text's length is not
3454 // equal to the length returned from webview()->caretOrSelectionRange().
3455 // So we have to set the range according to text.length().
3456 range.set_end(range.start() + text.length());
[email protected]b781ff282011-08-20 06:19:363457 }
3458
[email protected]b781ff282011-08-20 06:19:363459 // Sometimes we get repeated didChangeSelection calls from webkit when
3460 // the selection hasn't actually changed. We don't want to report these
3461 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003462 if (selection_text_offset_ != offset ||
3463 selection_range_ != range ||
3464 selection_text_ != text) {
3465 selection_text_ = text;
3466 selection_text_offset_ = offset;
3467 selection_range_ = range;
3468 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3469 }
[email protected]b781ff282011-08-20 06:19:363470}
3471
[email protected]310ebd6302011-10-10 19:06:283472GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3473 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553474 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293475 // If the URL that failed was secure, then the embedding web page was not
3476 // expecting a network attacker to be able to manipulate its contents. As
3477 // we fetch alternate error pages over HTTP, we would be allowing a network
3478 // attacker to manipulate the contents of the response if we tried to use
3479 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153480 return GURL();
initial.commit09911bf2008-07-26 23:55:293481 }
3482
3483 // Grab the base URL from the browser process.
3484 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153485 return GURL();
initial.commit09911bf2008-07-26 23:55:293486
3487 // Strip query params from the failed URL.
3488 GURL::Replacements remove_params;
3489 remove_params.ClearUsername();
3490 remove_params.ClearPassword();
3491 remove_params.ClearQuery();
3492 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553493 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503494 std::string spec_to_send = url_to_send.spec();
3495 // Notify link doctor of the url truncation by sending of "?" at the end.
3496 if (failed_url.has_query())
3497 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293498
3499 // Construct the query params to send to link doctor.
3500 std::string params(alternate_error_page_url_.query());
3501 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023502 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293503 params.append("&sourceid=chrome");
3504 params.append("&error=");
3505 switch (error_type) {
3506 case DNS_ERROR:
3507 params.append("dnserror");
3508 break;
3509
3510 case HTTP_404:
3511 params.append("http404");
3512 break;
3513
[email protected]5df266ac2008-10-15 19:50:133514 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333515 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133516 break;
3517
initial.commit09911bf2008-07-26 23:55:293518 default:
3519 NOTREACHED() << "unknown ErrorPageType";
3520 }
3521
3522 // OK, build the final url to return.
3523 GURL::Replacements link_doctor_params;
3524 link_doctor_params.SetQueryStr(params);
3525 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3526 return url;
3527}
3528
[email protected]310ebd6302011-10-10 19:06:283529GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593530 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3531 return GURL();
3532 else
3533 return creator_url_;
3534}
3535
[email protected]310ebd6302011-10-10 19:06:283536WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273537 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313538 web_ui_bindings_.reset(new WebUIBindings(
3539 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463540 }
[email protected]c50008512011-02-03 01:17:273541 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463542}
3543
[email protected]310ebd6302011-10-10 19:06:283544WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013545 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493546}
3547
[email protected]310ebd6302011-10-10 19:06:283548void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3549 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273550 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493551
[email protected]872542532011-06-23 00:43:163552 // Check if the plugin still exists in the document.
3553 if (main_frame->document().isPluginDocument() &&
3554 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493555 if (options.findNext) {
3556 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013557 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493558 } else {
[email protected]afdbd142010-07-10 08:01:233559 if (GetWebPluginFromPluginDocument()->startFind(
3560 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493561 } else {
[email protected]e7c58a32010-08-13 19:47:113562 // Send "no results".
3563 Send(new ViewHostMsg_Find_Reply(routing_id_,
3564 request_id,
3565 0,
3566 gfx::Rect(),
3567 0,
3568 true));
[email protected]24a7f3c2010-03-25 08:26:493569 }
3570 }
3571 return;
3572 }
3573
[email protected]b4bb2502009-10-01 22:35:273574 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273575 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293576 WebFrame* search_frame = focused_frame; // start searching focused frame.
3577
3578 bool multi_frame = (frame_after_main != main_frame);
3579
3580 // If we have multiple frames, we don't want to wrap the search within the
3581 // frame, so we check here if we only have main_frame in the chain.
3582 bool wrap_within_frame = !multi_frame;
3583
[email protected]b3f2b912009-04-09 16:18:523584 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293585 bool result = false;
3586
[email protected]7830da3e2009-11-06 16:27:263587 // If something is selected when we start searching it means we cannot just
3588 // increment the current match ordinal; we need to re-generate it.
3589 WebRange current_selection = focused_frame->selectionRange();
3590
initial.commit09911bf2008-07-26 23:55:293591 do {
[email protected]dd7daa82009-08-10 05:46:453592 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593593 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293594
3595 if (!result) {
3596 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223597 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293598
3599 // Find the next frame, but skip the invisible ones.
3600 do {
3601 // What is the next frame to search? (we might be going backwards). Note
3602 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593603 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273604 search_frame->traverseNext(true) :
3605 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453606 } while (!search_frame->hasVisibleContent() &&
3607 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293608
[email protected]884db412008-11-24 23:46:503609 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223610 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293611
3612 // If we have multiple frames and we have wrapped back around to the
3613 // focused frame, we need to search it once more allowing wrap within
3614 // the frame, otherwise it will report 'no match' if the focused frame has
3615 // reported matches, but no frames after the focused_frame contain a
3616 // match for the search word(s).
3617 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453618 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593619 request_id, search_text, options, true, // Force wrapping.
3620 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293621 }
3622 }
3623
[email protected]26aa0482009-09-30 16:55:273624 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293625 } while (!result && search_frame != focused_frame);
3626
[email protected]7830da3e2009-11-06 16:27:263627 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293628 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453629 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293630 } else {
3631 // If nothing is found, set result to "0 of 0", otherwise, set it to
3632 // "-1 of 1" to indicate that we found at least one item, but we don't know
3633 // yet what is active.
3634 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3635 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293636
[email protected]4f3dc372009-02-24 00:10:293637 // If we find no matches then this will be our last status update.
3638 // Otherwise the scoping effort will send more results.
3639 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293640
[email protected]4f3dc372009-02-24 00:10:293641 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403642 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593643 request_id,
[email protected]4f3dc372009-02-24 00:10:293644 match_count,
3645 selection_rect,
3646 ordinal,
3647 final_status_update));
initial.commit09911bf2008-07-26 23:55:293648
initial.commit09911bf2008-07-26 23:55:293649 // Scoping effort begins, starting with the mainframe.
3650 search_frame = main_frame;
3651
[email protected]dd7daa82009-08-10 05:46:453652 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293653
3654 do {
3655 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453656 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293657
3658 // We don't start another scoping effort unless at least one match has
3659 // been found.
3660 if (result) {
3661 // Start new scoping request. If the scoping function determines that it
3662 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453663 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593664 search_text,
3665 options,
initial.commit09911bf2008-07-26 23:55:293666 true); // reset the tickmarks
3667 }
3668
3669 // Iterate to the next frame. The frame will not necessarily scope, for
3670 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273671 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293672 } while (search_frame != main_frame);
3673 }
3674}
3675
[email protected]815dd9872011-11-23 18:40:303676void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493677 WebView* view = webview();
3678 if (!view)
3679 return;
3680
3681 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163682 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013683 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493684 return;
3685 }
3686
[email protected]815dd9872011-11-23 18:40:303687 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493688 if (clear_selection)
3689 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3690
3691 WebFrame* frame = view->mainFrame();
3692 while (frame) {
3693 frame->stopFinding(clear_selection);
3694 frame = frame->traverseNext(false);
3695 }
3696
[email protected]815dd9872011-11-23 18:40:303697 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493698 WebFrame* focused_frame = view->focusedFrame();
3699 if (focused_frame) {
3700 WebDocument doc = focused_frame->document();
3701 if (!doc.isNull()) {
3702 WebNode node = doc.focusedNode();
3703 if (!node.isNull())
3704 node.simulateClick();
3705 }
3706 }
3707 }
3708}
3709
[email protected]310ebd6302011-10-10 19:06:283710void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493711 // Check if there is any queued up request waiting to be sent.
3712 if (queued_find_reply_message_.get()) {
3713 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423714 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493715 }
3716}
3717
[email protected]54087fe2011-10-28 22:02:483718void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513719 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3720 return;
3721
[email protected]258d31122010-05-09 10:59:413722 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103723
[email protected]b75b8292010-10-01 07:28:253724 double old_zoom_level = webview()->zoomLevel();
3725 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483726 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253727 zoom_level = 0;
3728 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3729 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483730 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253731 } else {
3732 // Either the user hit the zoom factor limit and thus the zoom level is now
3733 // not a whole number, or a plugin changed it to a custom value. We want
3734 // to go to the next whole number so that the user can always get back to
3735 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483736 if ((old_zoom_level > 1 && zoom > 0) ||
3737 (old_zoom_level < 1 && zoom < 0)) {
3738 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253739 } else {
3740 // We're going towards 100%, so first go to the next whole number.
3741 zoom_level = static_cast<int>(old_zoom_level);
3742 }
3743 }
[email protected]b75b8292010-10-01 07:28:253744 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413745 zoomLevelChanged();
3746}
3747
3748void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3749 int zoom_center_x, int zoom_center_y) {
3750 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3751 kScalingIncrementForGesture);
3752}
3753
3754void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3755 int zoom_center_x,
3756 int zoom_center_y,
3757 float scaling_increment) {
3758 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3759 return;
3760
[email protected]c514d6372011-08-16 22:54:443761 double old_page_scale_factor = webview()->pageScaleFactor();
3762 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:483763 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:443764 page_scale_factor = 1.0;
3765 } else {
3766 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:413767 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:443768 }
[email protected]47578fa02011-11-02 19:34:413769 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:093770 webview()->setPageScaleFactor(page_scale_factor,
3771 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:413772 }
[email protected]40bd6582009-12-04 23:49:513773}
3774
[email protected]310ebd6302011-10-10 19:06:283775void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173776 webview()->hidePopups();
3777 webview()->setZoomLevel(false, zoom_level);
3778 zoomLevelChanged();
3779}
3780
[email protected]310ebd6302011-10-10 19:06:283781void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3782 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543783 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293784}
3785
[email protected]310ebd6302011-10-10 19:06:283786void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273787 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293788}
3789
[email protected]310ebd6302011-10-10 19:06:283790void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273791 WebString no_encoding;
3792 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183793}
3794
[email protected]310ebd6302011-10-10 19:06:283795WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453796 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273797 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453798
3799 // xpath string can represent a frame deep down the tree (across multiple
3800 // frame DOMs).
3801 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3802 // should break into 2 xpaths
3803 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413804 std::vector<string16> xpaths;
3805 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453806
[email protected]26aa0482009-09-30 16:55:273807 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413808 for (std::vector<string16>::const_iterator i = xpaths.begin();
3809 frame && i != xpaths.end(); ++i) {
3810 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293811 }
3812
[email protected]dd7daa82009-08-10 05:46:453813 return frame;
initial.commit09911bf2008-07-26 23:55:293814}
3815
[email protected]310ebd6302011-10-10 19:06:283816void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
3817 const string16& jscript,
3818 int id,
3819 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:533820 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293821}
3822
[email protected]310ebd6302011-10-10 19:06:283823void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
3824 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413825 WebFrame* frame = GetChildFrame(frame_xpath);
3826 if (!frame)
[email protected]216813952011-05-19 22:21:263827 return;
[email protected]ae461542009-06-19 19:03:413828
[email protected]01cf589c2011-07-28 18:04:033829 frame->document().insertUserStyleSheet(
3830 WebString::fromUTF8(css),
3831 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483832}
3833
[email protected]310ebd6302011-10-10 19:06:283834void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:093835 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293836}
3837
[email protected]310ebd6302011-10-10 19:06:283838void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
3839 const std::string& value) {
[email protected]e091df82011-10-11 18:13:213840 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:273841 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293842}
3843
[email protected]310ebd6302011-10-10 19:06:283844void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
3845 const gfx::Point& client_point,
3846 const gfx::Point& screen_point,
3847 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553848 WebDragOperation operation = webview()->dragTargetDragEnter(
3849 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553850 client_point,
3851 screen_point,
3852 ops);
3853
3854 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3855}
3856
[email protected]310ebd6302011-10-10 19:06:283857void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
3858 const gfx::Point& screen_point,
3859 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553860 WebDragOperation operation = webview()->dragTargetDragOver(
3861 client_point,
3862 screen_point,
3863 ops);
3864
3865 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3866}
3867
[email protected]310ebd6302011-10-10 19:06:283868void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:553869 webview()->dragTargetDragLeave();
3870}
3871
[email protected]310ebd6302011-10-10 19:06:283872void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
3873 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:553874 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573875
3876 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553877}
3878
[email protected]310ebd6302011-10-10 19:06:283879void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3880 const gfx::Point& screen_point,
3881 bool ended,
3882 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033883 if (ended) {
[email protected]26aa0482009-09-30 16:55:273884 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203885 } else {
3886 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033887 }
initial.commit09911bf2008-07-26 23:55:293888}
3889
[email protected]310ebd6302011-10-10 19:06:283890void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273891 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293892}
3893
[email protected]310ebd6302011-10-10 19:06:283894void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593895 webkit_preferences_ = prefs;
3896 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293897}
3898
[email protected]310ebd6302011-10-10 19:06:283899void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:293900 alternate_error_page_url_ = url;
3901}
3902
[email protected]310ebd6302011-10-10 19:06:283903void RenderViewImpl::OnCustomContextMenuAction(
[email protected]b29aa74b2011-01-31 21:41:083904 const webkit_glue::CustomContextMenuContext& custom_context,
3905 unsigned action) {
3906 if (custom_context.is_pepper_menu)
3907 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3908 else
3909 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:583910 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3911 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:333912}
3913
[email protected]310ebd6302011-10-10 19:06:283914void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:513915 int id,
3916 const std::vector<FilePath>& paths) {
3917 if (!enumeration_completions_[id])
3918 return;
3919
3920 WebVector<WebString> ws_file_names(paths.size());
3921 for (size_t i = 0; i < paths.size(); ++i)
3922 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3923
3924 enumeration_completions_[id]->didChooseFile(ws_file_names);
3925 enumeration_completions_.erase(id);
3926}
3927
[email protected]310ebd6302011-10-10 19:06:283928void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363929 // This could happen if we navigated to a different page before the user
3930 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473931 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363932 return;
3933
[email protected]cdaf8d02010-03-30 19:52:473934 WebVector<WebString> ws_file_names(paths.size());
3935 for (size_t i = 0; i < paths.size(); ++i)
3936 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463937
[email protected]cdaf8d02010-03-30 19:52:473938 if (file_chooser_completions_.front()->completion)
3939 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3940 file_chooser_completions_.pop_front();
3941
3942 // If there are more pending file chooser requests, schedule one now.
3943 if (!file_chooser_completions_.empty()) {
3944 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3945 file_chooser_completions_.front()->params));
3946 }
initial.commit09911bf2008-07-26 23:55:293947}
3948
[email protected]244ac1892011-12-02 17:04:473949void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
3950 const gfx::Size& max_size) {
3951 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
3952 if (!webview())
3953 return;
3954 webview()->enableAutoResizeMode(true, min_size, max_size);
3955}
3956
[email protected]2bf834f2011-11-17 20:02:213957void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:243958 if (send_preferred_size_changes_)
3959 return;
[email protected]9fb325e2010-05-06 18:23:243960 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393961
[email protected]d812fd12011-05-27 23:05:073962 // Start off with an initial preferred size notification (in case
3963 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:593964 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:083965}
3966
[email protected]310ebd6302011-10-10 19:06:283967void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:103968 const gfx::Size& disable_scrollbar_size_limit) {
3969 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3970}
3971
[email protected]310ebd6302011-10-10 19:06:283972void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:313973 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:503974 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:513975 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373976 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133977#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413978 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3979 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463980 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513981 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343982 renderer_prefs.thumb_inactive_color,
3983 renderer_prefs.thumb_active_color,
3984 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323985
[email protected]644d77e2010-01-27 01:03:103986 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323987 webview()->setScrollbarColors(
3988 renderer_prefs.thumb_inactive_color,
3989 renderer_prefs.thumb_active_color,
3990 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103991 webview()->setSelectionColors(
3992 renderer_prefs.active_selection_bg_color,
3993 renderer_prefs.active_selection_fg_color,
3994 renderer_prefs.inactive_selection_bg_color,
3995 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463996 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103997 }
[email protected]7a74e102009-09-03 00:16:563998#endif
[email protected]d051d9a2011-12-10 02:02:503999 // If the zoom level for this page matches the old zoom default, and this
4000 // is not a plugin, update the zoom level to match the new default.
4001 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4002 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4003 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4004 zoomLevelChanged();
4005 }
[email protected]80d96fa2009-06-10 22:34:514006}
4007
[email protected]310ebd6302011-10-10 19:06:284008void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4009 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284010 if (webview())
4011 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564012}
4013
[email protected]81375e872012-01-11 21:40:364014void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4015 const WebPluginAction& action) {
4016 if (webview())
4017 webview()->performPluginAction(action, location);
4018}
4019
[email protected]310ebd6302011-10-10 19:06:284020void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194021 const GURL& page_url) {
4022 // Prepare list to storage all savable resource links.
4023 std::vector<GURL> resources_list;
4024 std::vector<GURL> referrers_list;
4025 std::vector<GURL> frames_list;
4026 webkit_glue::SavableResourcesResult result(&resources_list,
4027 &referrers_list,
4028 &frames_list);
4029
[email protected]445e1042011-12-03 21:03:154030 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4031 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194032 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4033 webview(),
4034 page_url,
4035 &result,
[email protected]2a80aee2011-10-07 16:06:034036 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194037 // If something is wrong when collecting all savable resource links,
4038 // send empty list to embedder(browser) to tell it failed.
4039 referrers_list.clear();
4040 resources_list.clear();
4041 frames_list.clear();
4042 }
4043
4044 // Send result of all savable resource links to embedder.
4045 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4046 resources_list,
4047 referrers_list,
4048 frames_list));
4049}
4050
[email protected]310ebd6302011-10-10 19:06:284051void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194052 const std::vector<GURL>& links,
4053 const std::vector<FilePath>& local_paths,
4054 const FilePath& local_directory_name) {
4055
4056 // Convert std::vector of GURLs to WebVector<WebURL>
4057 WebVector<WebURL> weburl_links(links);
4058
4059 // Convert std::vector of std::strings to WebVector<WebString>
4060 WebVector<WebString> webstring_paths(local_paths.size());
4061 for (size_t i = 0; i < local_paths.size(); i++)
4062 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4063
4064 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4065 webstring_paths,
4066 webkit_glue::FilePathToWebString(
4067 local_directory_name));
4068}
4069
[email protected]310ebd6302011-10-10 19:06:284070void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274071 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474072 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294073}
4074
[email protected]310ebd6302011-10-10 19:06:284075void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]992db4c2011-05-12 15:37:154076 if (is_swapped_out_)
4077 return;
4078
4079 // Swap this RenderView out so the tab can navigate to a page rendered by a
4080 // different process. This involves running the unload handler and clearing
4081 // the page. Once WasSwappedOut is called, we also allow this process to exit
4082 // if there are no other active RenderViews in it.
4083
4084 // Send an UpdateState message before we get swapped out.
4085 SyncNavigationState();
4086
4087 // Synchronously run the unload handler before sending the ACK.
4088 webview()->dispatchUnloadEvent();
4089
4090 // Swap out and stop sending any IPC messages that are not ACKs.
4091 SetSwappedOut(true);
4092
4093 // Replace the page with a blank dummy URL. The unload handler will not be
4094 // run a second time, thanks to a check in FrameLoader::stopLoading.
4095 // TODO(creis): Need to add a better way to do this that avoids running the
4096 // beforeunload handler. For now, we just run it a second time silently.
4097 webview()->mainFrame()->loadHTMLString(std::string(),
4098 GURL("about:swappedout"),
4099 GURL("about:swappedout"),
4100 false);
4101
4102 // Just echo back the params in the ACK.
4103 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4104}
4105
[email protected]310ebd6302011-10-10 19:06:284106void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374107 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294108 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4109 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4110 // in the onunload handler from appearing. For now, we're bypassing that and
4111 // calling the FrameLoader's CloseURL method directly. This should be
4112 // revisited to avoid having two ways to close a page. Having a single way
4113 // to close that can run onunload is also useful for fixing
4114 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274115 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294116
[email protected]992db4c2011-05-12 15:37:154117 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294118}
4119
[email protected]310ebd6302011-10-10 19:06:284120void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024121#if defined(USE_AURA)
4122 // Aura doesn't care if we switch themes.
4123#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164124 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464125 if (webview())
4126 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574127#else // defined(OS_WIN)
4128 // TODO(port): we don't support theming on non-Windows platforms yet
4129 NOTIMPLEMENTED();
4130#endif
initial.commit09911bf2008-07-26 23:55:294131}
4132
[email protected]310ebd6302011-10-10 19:06:284133void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084134 if (decrement_shared_popup_at_destruction_)
4135 shared_popup_counter_->data--;
4136 shared_popup_counter_ = new SharedRenderViewCounter(0);
4137 decrement_shared_popup_at_destruction_ = false;
4138}
4139
[email protected]310ebd6302011-10-10 19:06:284140bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4141 const WebURLError& error,
4142 bool replace) {
[email protected]15d79e12009-08-02 19:23:454143 // We only show alternate error pages in the main frame. They are
4144 // intended to assist the user when navigating, so there is not much
4145 // value in showing them for failed subframes. Ideally, we would be
4146 // able to use the TYPED transition type for this, but that flag is
4147 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454148 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454149 return false;
4150
4151 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374152 // connection failure.
[email protected]15d79e12009-08-02 19:23:454153 int ec = error.reason;
4154 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4155 ec != net::ERR_CONNECTION_FAILED &&
4156 ec != net::ERR_CONNECTION_REFUSED &&
4157 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374158 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454159 return false;
4160
4161 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554162 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454163 if (!error_page_url.is_valid())
4164 return false;
4165
4166 // Load an empty page first so there is an immediate response to the error,
4167 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454168 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364169 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454170 error.unreachableURL,
4171 replace);
4172
4173 // Now, create a fetcher for the error page and associate it with the data
4174 // source we just created via the LoadHTMLString call. That way if another
4175 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074176 DocumentState* document_state =
4177 DocumentState::FromDataSource(frame->provisionalDataSource());
4178 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454179 new AltErrorPageResourceFetcher(
4180 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084181 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4182 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454183 return true;
4184}
4185
[email protected]310ebd6302011-10-10 19:06:284186void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4187 const WebURLError& original_error,
4188 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454189 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094190 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554191 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094192 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454193}
4194
[email protected]310ebd6302011-10-10 19:06:284195void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004196 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474197 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004198}
4199
[email protected]310ebd6302011-10-10 19:06:284200void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094201 const gfx::Rect& resizer_rect,
4202 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104203 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474204 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104205 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204206 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314207 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104208 }
[email protected]dd6afca2011-08-13 03:44:314209 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104210 }
4211
[email protected]ee41e7d22011-10-14 19:34:094212 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004213}
[email protected]0aa477bd2009-03-23 22:21:434214
[email protected]310ebd6302011-10-10 19:06:284215void RenderViewImpl::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014216 // Notify the pepper plugins that we started painting.
4217 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284218}
4219
[email protected]310ebd6302011-10-10 19:06:284220void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284221 // Notify any pepper plugins that we painted. This will call into the plugin,
4222 // and we it may ask to close itself as a result. This will, in turn, modify
4223 // our set, possibly invalidating the iterator. So we iterate on a copy that
4224 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014225 pepper_delegate_.ViewFlushedPaint();
4226
[email protected]00c39612010-03-06 02:53:284227 WebFrame* main_frame = webview()->mainFrame();
4228
4229 // If we have a provisional frame we are between the start and commit stages
4230 // of loading and we don't want to save stats.
4231 if (!main_frame->provisionalDataSource()) {
4232 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074233 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284234
[email protected]05c8e502010-08-15 15:13:524235 // TODO(jar): The following code should all be inside a method, probably in
4236 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284237 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074238 if (document_state->first_paint_time().is_null()) {
4239 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284240 }
[email protected]007733c2011-11-17 00:34:074241 if (document_state->first_paint_after_load_time().is_null() &&
4242 !document_state->finish_load_time().is_null()) {
4243 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284244 }
4245 }
4246}
4247
[email protected]310ebd6302011-10-10 19:06:284248void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084249 RenderWidget::OnSwapBuffersPosted();
4250}
4251
[email protected]310ebd6302011-10-10 19:06:284252void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244253 RenderWidget::OnSwapBuffersComplete();
4254}
4255
[email protected]310ebd6302011-10-10 19:06:284256void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244257 RenderWidget::OnSwapBuffersAborted();
4258}
4259
[email protected]310ebd6302011-10-10 19:06:284260webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154261 const gfx::Rect& paint_bounds,
4262 TransportDIB** dib,
4263 gfx::Rect* location,
4264 gfx::Rect* clip) {
4265 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4266 paint_bounds, dib, location, clip);
4267}
4268
[email protected]310ebd6302011-10-10 19:06:284269gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074270 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434271 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524272}
4273
[email protected]310ebd6302011-10-10 19:06:284274void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164275 if (webview())
[email protected]26aa0482009-09-30 16:55:274276 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164277}
4278
[email protected]310ebd6302011-10-10 19:06:284279void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144280 if (webview())
[email protected]b4bb2502009-10-01 22:35:274281 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144282
4283 SetBackground(background);
4284}
4285
[email protected]310ebd6302011-10-10 19:06:284286void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344287 if (webview())
[email protected]b4bb2502009-10-01 22:35:274288 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264289
4290#if defined(OS_MACOSX)
4291 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4292 for (plugin_it = plugin_delegates_.begin();
4293 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4294 (*plugin_it)->SetWindowFocus(active);
4295 }
4296#endif
[email protected]8c66c5a2009-07-22 17:26:344297}
4298
[email protected]6ce7abc52010-02-02 18:40:144299#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284300void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144301 // Inform plugins that their container has changed visibility.
4302 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4303 for (plugin_it = plugin_delegates_.begin();
4304 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4305 (*plugin_it)->SetContainerVisibility(visible);
4306 }
4307}
[email protected]1e6e3c992010-02-08 15:52:134308
[email protected]310ebd6302011-10-10 19:06:284309void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4310 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134311 // Inform plugins that their window's frame has changed.
4312 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4313 for (plugin_it = plugin_delegates_.begin();
4314 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4315 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4316 }
4317}
[email protected]935d63d2010-10-15 23:31:554318
[email protected]310ebd6302011-10-10 19:06:284319void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4320 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134321 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554322 // applies to it or not, so inform all the delegates.
4323 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4324 for (plugin_it = plugin_delegates_.begin();
4325 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134326 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554327 }
4328}
[email protected]6ce7abc52010-02-02 18:40:144329#endif // OS_MACOSX
4330
[email protected]310ebd6302011-10-10 19:06:284331void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484332 const EditCommands& edit_commands) {
4333 edit_commands_ = edit_commands;
4334}
4335
[email protected]310ebd6302011-10-10 19:06:284336void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594337 // We need to grab a pointer to the doomed WebView before we destroy it.
4338 WebView* doomed = webview();
4339 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494340 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594341}
4342
[email protected]310ebd6302011-10-10 19:06:284343void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484344 edit_commands_.clear();
4345}
4346
[email protected]310ebd6302011-10-10 19:06:284347bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]b993705a2011-10-09 23:00:244348 return pepper_delegate_.HandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374349}
4350
[email protected]310ebd6302011-10-10 19:06:284351void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514352 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064353}
4354
[email protected]310ebd6302011-10-10 19:06:284355void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244356 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4357}
4358
[email protected]310ebd6302011-10-10 19:06:284359void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434360 RenderWidget::OnWasHidden();
4361
[email protected]a6939ca42011-02-18 17:58:074362 if (webview()) {
4363 webview()->settings()->setMinimumTimerInterval(
4364 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444365 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074366 }
4367
[email protected]204f1df2012-01-04 20:21:134368 // Inform PPAPI plugins that their page is no longer visible.
4369 pepper_delegate_.PageVisibilityChanged(false);
4370
[email protected]a6939ca42011-02-18 17:58:074371#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134372 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434373 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4374 for (plugin_it = plugin_delegates_.begin();
4375 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4376 (*plugin_it)->SetContainerVisibility(false);
4377 }
[email protected]a6939ca42011-02-18 17:58:074378#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434379}
4380
[email protected]310ebd6302011-10-10 19:06:284381void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434382 RenderWidget::OnWasRestored(needs_repainting);
4383
[email protected]a6939ca42011-02-18 17:58:074384 if (webview()) {
4385 webview()->settings()->setMinimumTimerInterval(
4386 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444387 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074388 }
4389
[email protected]204f1df2012-01-04 20:21:134390 // Inform PPAPI plugins that their page is visible.
4391 pepper_delegate_.PageVisibilityChanged(true);
4392
[email protected]a6939ca42011-02-18 17:58:074393#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134394 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434395 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4396 for (plugin_it = plugin_delegates_.begin();
4397 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4398 (*plugin_it)->SetContainerVisibility(true);
4399 }
[email protected]784ea1ab2010-09-18 00:02:344400#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074401}
[email protected]1e6e3c992010-02-08 15:52:134402
[email protected]310ebd6302011-10-10 19:06:284403bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384404 if (WebWidgetHandlesCompositorScheduling())
4405 return false;
4406
[email protected]65225772011-05-12 21:10:244407 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4408 if (!context)
4409 return false;
4410 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4411 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4412 std::string::npos;
4413}
4414
[email protected]310ebd6302011-10-10 19:06:284415void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134416 RenderWidget::OnSetFocus(enable);
4417
[email protected]7d3c02c2010-05-05 23:10:314418 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074419 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134420 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4421 for (plugin_it = plugin_delegates_.begin();
4422 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344423#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314424 // RenderWidget's call to setFocus can cause the underlying webview's
4425 // activation state to change just like a call to setIsActive.
4426 if (enable)
4427 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344428#endif
[email protected]7d3c02c2010-05-05 23:10:314429 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134430 }
[email protected]589621b2010-09-23 22:01:074431
4432 // Notify all Pepper plugins.
4433 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134434 }
4435}
[email protected]941e4552010-02-01 21:23:434436
[email protected]310ebd6302011-10-10 19:06:284437void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004438 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504439 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574440}
4441
[email protected]73bf95812011-10-12 11:38:324442void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004443 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324444}
4445
[email protected]3f783362011-10-21 22:40:504446void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4447 UpdateSelectionBounds();
4448}
4449
[email protected]b25b3ee2012-01-13 05:19:544450bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4451 if (!pepper_delegate_.IsPluginFocused())
4452 return false;
4453 *rect = pepper_delegate_.GetCaretBounds();
4454 return true;
4455}
4456
[email protected]73bf95812011-10-12 11:38:324457void RenderViewImpl::PpapiPluginCancelComposition() {
4458 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4459 ui::Range range(ui::Range::InvalidRange());
4460 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4461}
4462
[email protected]310ebd6302011-10-10 19:06:284463void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574464 const string16& text,
4465 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4466 int selection_start,
4467 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324468 if (pepper_delegate_.IsPluginFocused()) {
4469 // When a PPAPI plugin has focus, we bypass WebKit.
4470 pepper_delegate_.OnImeSetComposition(text,
4471 underlines,
4472 selection_start,
4473 selection_end);
4474 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234475#if defined(OS_WIN)
4476 // When a plug-in has focus, we create platform-specific IME data used by
4477 // our IME emulator and send it directly to the focused plug-in, i.e. we
4478 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4479 // instance ID is the same one as the specified ID.)
4480 if (focused_plugin_id_ >= 0) {
4481 std::vector<int> clauses;
4482 std::vector<int> target;
4483 for (size_t i = 0; i < underlines.size(); ++i) {
4484 clauses.push_back(underlines[i].startOffset);
4485 clauses.push_back(underlines[i].endOffset);
4486 if (underlines[i].thick) {
4487 target.clear();
4488 target.push_back(underlines[i].startOffset);
4489 target.push_back(underlines[i].endOffset);
4490 }
4491 }
4492 std::set<WebPluginDelegateProxy*>::iterator it;
4493 for (it = plugin_delegates_.begin();
4494 it != plugin_delegates_.end(); ++it) {
4495 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4496 focused_plugin_id_);
4497 }
4498 return;
4499 }
4500#endif
[email protected]56ea1a62011-05-30 07:05:574501 RenderWidget::OnImeSetComposition(text,
4502 underlines,
4503 selection_start,
4504 selection_end);
4505 }
4506}
4507
[email protected]4de6d1692011-10-12 08:45:444508void RenderViewImpl::OnImeConfirmComposition(
4509 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574510 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324511 // When a PPAPI plugin has focus, we bypass WebKit.
4512 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574513 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234514#if defined(OS_WIN)
4515 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4516 // plug-ins. When we send IME text directly to plug-ins, we should not send
4517 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444518 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234519 if (focused_plugin_id_ >= 0) {
4520 std::set<WebPluginDelegateProxy*>::iterator it;
4521 for (it = plugin_delegates_.begin();
4522 it != plugin_delegates_.end(); ++it) {
4523 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4524 }
4525 return;
4526 }
4527#endif
[email protected]ebd28ac2011-10-13 18:49:054528 if (replacement_range.IsValid() && webview()) {
4529 // Select the text in |replacement_range|, it will then be replaced by
4530 // text added by the call to RenderWidget::OnImeConfirmComposition().
4531 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164532 WebRange webrange = WebRange::fromDocumentRange(
4533 frame, replacement_range.start(), replacement_range.length());
4534 if (!webrange.isNull())
4535 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054536 }
4537 }
[email protected]4de6d1692011-10-12 08:45:444538 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574539 }
4540}
4541
[email protected]310ebd6302011-10-10 19:06:284542ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324543 return pepper_delegate_.IsPluginFocused() ?
4544 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4545}
4546
[email protected]3f783362011-10-21 22:40:504547void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4548 if (pepper_delegate_.IsPluginFocused()) {
4549 // TODO(kinaba) http://crbug.com/101101
4550 // Current Pepper IME API does not handle selection bounds. So we simply
4551 // use the caret position as an empty range for now. It will be updated
4552 // after Pepper API equips features related to surrounding text retrieval.
4553 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4554 *start = caret;
4555 *end = caret;
4556 return;
4557 }
4558 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454559}
4560
[email protected]310ebd6302011-10-10 19:06:284561bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324562 return pepper_delegate_.IsPluginFocused() ?
4563 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574564}
4565
[email protected]e6ae0f6c2011-10-04 10:39:234566#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284567void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234568 if (focused)
4569 focused_plugin_id_ = plugin_id;
4570 else
4571 focused_plugin_id_ = -1;
4572}
4573#endif
4574
[email protected]43f28f832010-02-03 02:28:484575#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284576void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134577 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4578 focused, plugin_id);
4579 Send(msg);
4580}
4581
[email protected]310ebd6302011-10-10 19:06:284582void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134583 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554584 // This message can be sent during event-handling, and needs to be delivered
4585 // within that context.
4586 msg->set_unblock(true);
4587 Send(msg);
4588}
4589
[email protected]310ebd6302011-10-10 19:06:284590gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234591 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484592 gfx::PluginWindowHandle window = NULL;
4593 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234594 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114595 if (window) {
4596 fake_plugin_window_handles_.insert(window);
4597 }
[email protected]43f28f832010-02-03 02:28:484598 return window;
4599}
4600
[email protected]310ebd6302011-10-10 19:06:284601void RenderViewImpl::DestroyFakePluginWindowHandle(
4602 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114603 if (window && fake_plugin_window_handles_.find(window) !=
4604 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484605 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114606 fake_plugin_window_handles_.erase(window);
4607 }
[email protected]43f28f832010-02-03 02:28:484608}
4609
[email protected]310ebd6302011-10-10 19:06:284610void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4611 gfx::PluginWindowHandle window,
4612 int32 width,
4613 int32 height,
4614 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334615 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484616 routing_id(), window, width, height, io_surface_identifier));
4617}
4618
[email protected]310ebd6302011-10-10 19:06:284619void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334620 gfx::PluginWindowHandle window,
4621 int32 width,
4622 int32 height,
4623 TransportDIB::Handle transport_dib) {
4624 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074625 routing_id(), window, width, height, transport_dib));
4626}
4627
[email protected]310ebd6302011-10-10 19:06:284628TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334629 size_t size) {
[email protected]1aef98132010-02-23 18:00:074630 TransportDIB::Handle dib_handle;
4631 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384632 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074633 return dib_handle;
4634 // Return an invalid handle if Send() fails.
4635 return TransportDIB::DefaultHandleValue();
4636}
4637
[email protected]310ebd6302011-10-10 19:06:284638void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4639 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074640 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4641}
4642
[email protected]310ebd6302011-10-10 19:06:284643void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144644 gfx::PluginWindowHandle window, uint64 surface_id) {
4645 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4646 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484647}
4648#endif
[email protected]58c321d2010-02-19 12:11:284649
[email protected]310ebd6302011-10-10 19:06:284650bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234651 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474652 WebFileChooserCompletion* completion) {
4653 static const size_t kMaximumPendingFileChooseRequests = 4;
4654 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4655 // This sanity check prevents too many file choose requests from getting
4656 // queued which could DoS the user. Getting these is most likely a
4657 // programming error (there are many ways to DoS the user so it's not
4658 // considered a "real" security check), either in JS requesting many file
4659 // choosers to pop up, or in a plugin.
4660 //
4661 // TODO(brettw) we might possibly want to require a user gesture to open
4662 // a file picker, which will address this issue in a better way.
4663 return false;
4664 }
4665
4666 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4667 new PendingFileChooser(params, completion)));
4668 if (file_chooser_completions_.size() == 1) {
4669 // Actually show the browse dialog when this is the first request.
4670 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4671 }
4672 return true;
4673}
4674
[email protected]310ebd6302011-10-10 19:06:284675WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514676 if (!geolocation_dispatcher_)
4677 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4678 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254679}
[email protected]61c9f032010-03-31 23:04:194680
[email protected]310ebd6302011-10-10 19:06:284681WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114682 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224683#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514684 if (!speech_input_dispatcher_)
4685 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224686#endif
[email protected]676126f72011-01-15 00:03:514687 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114688}
4689
[email protected]310ebd6302011-10-10 19:06:284690WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514691 if (!device_orientation_dispatcher_)
4692 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4693 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534694}
4695
[email protected]310ebd6302011-10-10 19:06:284696void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4697 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254698 // For now, don't remember plugin zoom values. We don't want to mix them with
4699 // normal web content (i.e. a fixed layout plugin would usually want them
4700 // different).
4701 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4702
[email protected]b75b8292010-10-01 07:28:254703 int minimum_percent = static_cast<int>(
4704 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4705 int maximum_percent = static_cast<int>(
4706 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254707
4708 Send(new ViewHostMsg_UpdateZoomLimits(
4709 routing_id_, minimum_percent, maximum_percent, remember));
4710}
4711
[email protected]310ebd6302011-10-10 19:06:284712void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254713 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084714 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:254715 // Tell the browser which url got zoomed so it can update the menu and the
4716 // saved values if necessary
4717 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084718 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414719 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254720}
4721
[email protected]310ebd6302011-10-10 19:06:284722void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4723 const WebString& base_url,
4724 const WebString& url,
4725 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484726 GURL base(base_url);
4727 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4728 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4729 return;
4730 }
[email protected]f1a29a02011-10-06 23:08:444731 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4732 UTF16ToUTF8(scheme),
4733 absolute_url,
4734 title));
[email protected]a6d36cc2011-02-23 00:39:484735}
4736
[email protected]310ebd6302011-10-10 19:06:284737WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444738 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4739 WebKit::WebPageVisibilityStateHidden :
4740 WebKit::WebPageVisibilityStateVisible;
4741 WebKit::WebPageVisibilityState override_state = current_state;
4742 if (content::GetContentClient()->renderer()->
4743 ShouldOverridePageVisibilityState(this,
4744 &override_state))
4745 return override_state;
4746 return current_state;
[email protected]94dec932011-05-26 20:04:214747}
4748
[email protected]273558fb2012-01-12 15:03:514749WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
4750 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
4751 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
4752 return NULL;
4753 EnsureMediaStreamImpl();
4754 return media_stream_impl_;
4755}
4756
[email protected]310ebd6302011-10-10 19:06:284757bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194758 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454759 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194760 if (frame->parent() != NULL)
4761 return false;
4762
[email protected]f0a3d0b2010-08-06 22:51:534763 // Navigations initiated within Webkit are not sent out to the external host
4764 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274765 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134766 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534767 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134768 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334769 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534770 return false;
4771
[email protected]2fc22d12010-12-02 23:08:164772 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324773 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014774 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164775 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014776 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324777 // The opener relationship between the new window and the parent allows the
4778 // new window to script the parent and vice versa. This is not allowed if
4779 // the origins of the two domains are different. This can be treated as a
4780 // top level navigation and routed back to the host.
4781 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274782 if (!opener) {
[email protected]86965362011-04-21 18:42:514783 return true;
[email protected]d19ea342011-04-20 20:31:134784 } else {
[email protected]b6cb3a842011-06-24 18:28:414785 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324786 return true;
4787 }
4788 }
[email protected]61c9f032010-03-31 23:04:194789 return false;
4790}
[email protected]2b06a992010-08-21 05:48:224791
[email protected]310ebd6302011-10-10 19:06:284792void RenderViewImpl::OnAsyncFileOpened(
4793 base::PlatformFileError error_code,
4794 IPC::PlatformFileForTransit file_for_transit,
4795 int message_id) {
[email protected]27a9ef32010-09-10 04:06:244796 pepper_delegate_.OnAsyncFileOpened(
4797 error_code,
4798 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4799 message_id);
4800}
[email protected]caf706f2010-10-26 17:54:084801
[email protected]310ebd6302011-10-10 19:06:284802void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:474803 int request_id,
4804 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434805 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474806 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4807 broker_process_handle,
4808 handle);
[email protected]eb415bf0e2011-04-14 02:45:424809}
4810
[email protected]caf706f2010-10-26 17:54:084811#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284812void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154813 if (external_popup_menu_ == NULL) {
4814 // Crash reports from the field indicate that we can be notified with a
4815 // NULL external popup menu (we probably get notified twice).
4816 // If you hit this please file a bug against jcivelli and include the page
4817 // and steps to repro.
4818 NOTREACHED();
4819 return;
4820 }
[email protected]caf706f2010-10-26 17:54:084821 external_popup_menu_->DidSelectItem(selected_index);
4822 external_popup_menu_.reset();
4823}
4824#endif
[email protected]bb461532010-11-26 21:50:234825
[email protected]1b4209f2011-01-07 00:25:404826#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:284827void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:404828 int request_id,
4829 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:494830 const PP_NetAddress_Private& local_addr,
4831 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:404832 pepper_delegate_.OnConnectTcpACK(
4833 request_id,
4834 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4835 local_addr,
4836 remote_addr);
4837}
4838#endif
[email protected]a6097f42011-01-10 08:50:514839
[email protected]310ebd6302011-10-10 19:06:284840void RenderViewImpl::OnContextMenuClosed(
[email protected]b29aa74b2011-01-31 21:41:084841 const webkit_glue::CustomContextMenuContext& custom_context) {
4842 if (custom_context.is_pepper_menu)
4843 pepper_delegate_.OnContextMenuClosed(custom_context);
4844 else
4845 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104846}
[email protected]5a7b15a2011-08-22 22:48:184847
[email protected]310ebd6302011-10-10 19:06:284848void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:184849 if (!webview())
4850 return;
4851 WebFrame* main_frame = webview()->mainFrame();
4852 if (!main_frame)
4853 return;
4854 main_frame->enableViewSourceMode(true);
4855}
[email protected]67bfb83f2011-09-22 03:36:374856
[email protected]310ebd6302011-10-10 19:06:284857void RenderViewImpl::OnLockMouseACK(bool succeeded) {
[email protected]57e02be2011-10-11 19:00:534858 // Mouse Lock removes the system cursor and provides all mouse motion as
4859 // .movementX/Y values on events all sent to a fixed target. This requires
4860 // content to specifically request the mode to be entered.
4861 // Mouse Capture is implicitly given for the duration of a drag event, and
4862 // sends all mouse events to the initial target of the drag.
4863 // If Lock is entered it supercedes any in progress Capture.
4864 if (succeeded)
4865 OnMouseCaptureLost();
4866
[email protected]67bfb83f2011-09-22 03:36:374867 pepper_delegate_.OnLockMouseACK(succeeded);
4868}
4869
[email protected]310ebd6302011-10-10 19:06:284870void RenderViewImpl::OnMouseLockLost() {
[email protected]67bfb83f2011-09-22 03:36:374871 pepper_delegate_.OnMouseLockLost();
4872}
[email protected]c3d45532011-10-07 19:20:404873
[email protected]310ebd6302011-10-10 19:06:284874bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:084875 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:404876}
[email protected]7f3c7af2011-10-20 22:52:514877
[email protected]64d0e192011-12-09 14:44:204878void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:514879 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:184880#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:204881 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:184882#endif
[email protected]7f3c7af2011-10-20 22:52:514883}