blob: 4e4759d65c03b8d230f9563c85d6a4de75b94f87 [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"
[email protected]592e20b2012-01-20 05:53:44106#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58107#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14108#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37109#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19110#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37111#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36112#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37113#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
114#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
115#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37117#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17120#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37121#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37122#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40123#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51124#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08125#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]273558fb2012-01-12 15:03:51131#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08133#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]e6e90dc2011-12-03 00:01:37136#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26142#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47143#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38144#include "ui/gfx/native_widget_types.h"
145#include "ui/gfx/point.h"
146#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55147#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04148#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]9c4bf232011-12-15 02:25:08149#include "webkit/forms/form_data.h"
150#include "webkit/forms/form_field.h"
151#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43152#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24153#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19154#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24155#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29156#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07157#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29158#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03159#include "webkit/glue/weburlloader_impl.h"
[email protected]a9288f52011-11-17 05:18:16160#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50161#include "webkit/plugins/npapi/plugin_list.h"
162#include "webkit/plugins/npapi/webplugin_delegate.h"
163#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
164#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52165#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29166
[email protected]6c8afae52009-01-22 02:24:57167#if defined(OS_WIN)
168// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57169// * theming
[email protected]08397d52011-02-05 01:53:38170#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03171#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37172#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51173#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33174#elif defined(OS_MACOSX)
175#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57176#endif
177
[email protected]9892b472010-09-16 00:23:42178using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08179using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21180using WebKit::WebApplicationCacheHost;
181using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26182using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41183using WebKit::WebColor;
184using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59185using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44186using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51187using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55188using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28189using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00190using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58191using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25192using WebKit::WebDragOperation;
193using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51194using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51195using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08196using WebKit::WebExternalPopupMenu;
197using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47198using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22199using WebKit::WebFileSystem;
200using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49201using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59202using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48203using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45204using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17205using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13206using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41207using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50208using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17209using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28210using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17211using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28212using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28213using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51214using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19215using WebKit::WebPageSerializer;
216using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17217using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36218using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40219using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49220using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09221using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52222using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59223using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51224using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52225using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15226using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40227using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35228using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29229using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17230using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59231using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42232using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02233using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34234using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40235using WebKit::WebStorageQuotaCallbacks;
236using WebKit::WebStorageQuotaError;
237using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28238using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51239using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52240using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24241using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28242using WebKit::WebURL;
243using WebKit::WebURLError;
244using WebKit::WebURLRequest;
245using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28246using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03247using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28248using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26249using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26250using appcache::WebApplicationCacheHostImpl;
251using base::Time;
252using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07253using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32254using content::NavigationState;
[email protected]380244092011-10-07 17:26:27255using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44256using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36257using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15258using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19259using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08260using webkit::forms::FormField;
261using webkit::forms::PasswordForm;
262using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26263using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23264using webkit_glue::ResourceFetcher;
[email protected]e1acf6f2008-10-27 20:43:33265
initial.commit09911bf2008-07-26 23:55:29266//-----------------------------------------------------------------------------
267
[email protected]310ebd6302011-10-10 19:06:28268typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49269static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02270
[email protected]882daa92009-11-05 16:31:31271// Time, in seconds, we delay before sending content state changes (such as form
272// state and scroll position) to the browser. We delay sending changes to avoid
273// spamming the browser.
274// To avoid having tab/session restore require sending a message to get the
275// current content state during tab closing we use a shorter timeout for the
276// foreground renderer. This means there is a small window of time from which
277// content state is modified and not sent to session restore, but this is
278// better than having to wake up all renderers during shutdown.
279static const int kDelaySecondsForContentStateSyncHidden = 5;
280static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29281
[email protected]e99ef6f2011-10-16 01:13:00282static const size_t kExtraCharsBeforeAndAfterSelection = 100;
283
[email protected]0aa55312008-10-17 21:53:08284// The maximum number of popups that can be spawned from one page.
285static const int kMaximumNumberOfUnacknowledgedPopups = 25;
286
[email protected]c514d6372011-08-16 22:54:44287static const float kScalingIncrement = 0.1f;
288
[email protected]47578fa02011-11-02 19:34:41289static const float kScalingIncrementForGesture = 0.01f;
290
[email protected]726985e22009-06-18 21:09:28291static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
292 WebVector<WebURL> urls;
293 ds->redirectChain(urls);
294 result->reserve(urls.size());
295 for (size_t i = 0; i < urls.size(); ++i)
296 result->push_back(urls[i]);
297}
298
[email protected]007733c2011-11-17 00:34:07299// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44300// the AltErrorPageResourceFetcher is reset.
301static void StopAltErrorPageFetcher(WebDataSource* data_source) {
302 if (data_source) {
[email protected]007733c2011-11-17 00:34:07303 DocumentState* document_state = DocumentState::FromDataSource(data_source);
304 if (document_state)
305 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44306 }
307}
308
[email protected]007733c2011-11-17 00:34:07309static bool IsReload(const ViewMsg_Navigate_Params& params) {
310 return
311 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
312 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
313}
314
[email protected]445e1042011-12-03 21:03:15315static WebReferrerPolicy getReferrerPolicyFromRequest(
316 const WebURLRequest& request) {
317 return request.extraData() ?
318 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
319 WebKit::WebReferrerPolicyDefault;
320}
321
initial.commit09911bf2008-07-26 23:55:29322///////////////////////////////////////////////////////////////////////////////
323
[email protected]310ebd6302011-10-10 19:06:28324struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23325 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47326 WebFileChooserCompletion* c)
327 : params(p),
328 completion(c) {
329 }
[email protected]8caadeb2011-11-22 02:45:23330 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47331 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
332};
333
[email protected]daf82f82011-10-31 22:35:31334RenderViewImpl::RenderViewImpl(
335 gfx::NativeViewId parent_hwnd,
336 int32 opener_id,
337 const content::RendererPreferences& renderer_prefs,
338 const WebPreferences& webkit_prefs,
339 SharedRenderViewCounter* counter,
340 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56341 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31342 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46343 const string16& frame_name,
344 int32 next_page_id)
[email protected]380244092011-10-07 17:26:27345 : RenderWidget(WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51346 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02347 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09348 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02349 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24350 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21351 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02352 opened_by_user_gesture_(true),
353 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24354 page_id_(-1),
355 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46356 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00357 history_list_offset_(-1),
358 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02359 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55360 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31361 cached_is_main_frame_pinned_to_left_(false),
362 cached_is_main_frame_pinned_to_right_(false),
363 cached_has_main_frame_horizontal_scrollbar_(false),
364 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]3354d3e2010-06-10 19:53:02365 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51366 geolocation_dispatcher_(NULL),
367 speech_input_dispatcher_(NULL),
368 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51369 media_stream_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18370 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41371 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32372 renderer_accessibility_(NULL),
[email protected]4fb60142011-08-09 02:22:08373 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18374 handling_select_range_(false),
375#if defined(OS_WIN)
376 focused_plugin_id_(-1),
377#endif
378 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51379 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56380 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51381 if (opener_id != MSG_ROUTING_NONE)
382 opener_id_ = opener_id;
383
[email protected]74ce1ad2011-12-16 21:51:46384 // Ensure we start with a valid next_page_id_ from the browser.
385 DCHECK_GE(next_page_id_, 0);
386
[email protected]21b3a6ae2011-11-30 00:45:29387#if defined(ENABLE_NOTIFICATIONS)
388 notification_provider_ = new NotificationProvider(this);
389#else
390 notification_provider_ = NULL;
391#endif
392
[email protected]11fee2332011-03-29 20:36:35393 webwidget_ = WebView::create(this);
394
[email protected]676126f72011-01-15 00:03:51395 if (counter) {
396 shared_popup_counter_ = counter;
397 shared_popup_counter_->data++;
398 decrement_shared_popup_at_destruction_ = true;
399 } else {
400 shared_popup_counter_ = new SharedRenderViewCounter(0);
401 decrement_shared_popup_at_destruction_ = false;
402 }
403
[email protected]0d9989d2011-12-21 20:26:00404 intents_host_ = new WebIntentsHost(this);
[email protected]7cce3232011-10-28 10:41:57405
[email protected]380244092011-10-07 17:26:27406 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51407 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47408 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51409 AddRef();
410
411 // If this is a popup, we must wait for the CreatingNew_ACK message before
412 // completing initialization. Otherwise, we can finish it now.
413 if (opener_id == MSG_ROUTING_NONE) {
414 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55415 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51416 }
417
[email protected]34c61bd52011-05-02 19:38:33418 g_view_map.Get().insert(std::make_pair(webview(), this));
419 webkit_preferences_.Apply(webview());
420 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35421 if (!frame_name.empty())
422 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33423 webview()->settings()->setMinimumTimerInterval(
424 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
425 webkit_glue::kForegroundTabTimerInterval);
426
427 OnSetRendererPrefs(renderer_prefs);
428
[email protected]676126f72011-01-15 00:03:51429 host_window_ = parent_hwnd;
430
[email protected]a026daa2011-04-20 15:49:51431#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51432 if (!p2p_socket_dispatcher_)
433 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51434#endif
[email protected]cae8c8492011-03-03 11:12:18435
[email protected]8f6a3b852011-07-19 16:48:56436 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32437#if defined(OS_MACOSX)
438 new TextInputClientObserver(this);
439#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56440
[email protected]c5c1d6d2011-07-28 18:42:41441 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20442
[email protected]063afcb2011-09-29 07:54:32443 renderer_accessibility_ = new RendererAccessibility(this);
444
[email protected]1784b2f2011-11-24 10:53:48445 new IdleUserDetector(this);
446
[email protected]e48869a2011-04-01 19:56:03447 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29448}
449
[email protected]310ebd6302011-10-10 19:06:28450RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03451 history_page_ids_.clear();
452
[email protected]0aa55312008-10-17 21:53:08453 if (decrement_shared_popup_at_destruction_)
454 shared_popup_counter_->data--;
455
[email protected]a1128322009-10-06 18:38:46456 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47457 while (!file_chooser_completions_.empty()) {
458 if (file_chooser_completions_.front()->completion) {
459 file_chooser_completions_.front()->completion->didChooseFile(
460 WebVector<WebString>());
461 }
462 file_chooser_completions_.pop_front();
463 }
[email protected]a1128322009-10-06 18:38:46464
[email protected]83dde542009-09-11 20:59:55465#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11466 // Destroy all fake plugin window handles on the browser side.
467 while (!fake_plugin_window_handles_.empty()) {
468 // Make sure no NULL plugin window handles were inserted into this list.
469 DCHECK(*fake_plugin_window_handles_.begin());
470 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
471 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
472 }
[email protected]83dde542009-09-11 20:59:55473#endif
[email protected]98324892009-09-09 21:16:05474
[email protected]60c42a8c72009-10-09 04:08:59475#ifndef NDEBUG
476 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49477 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59478 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
479 DCHECK_NE(this, it->second) << "Failed to call Close?";
480#endif
[email protected]676126f72011-01-15 00:03:51481
[email protected]273558fb2012-01-12 15:03:51482 // MediaStreamImpl holds weak references to RenderViewObserver objects,
483 // ensure it's deleted before the observers.
484 media_stream_impl_ = NULL;
485
[email protected]310ebd6302011-10-10 19:06:28486 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51487 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59488}
489
490/*static*/
[email protected]310ebd6302011-10-10 19:06:28491RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31492 ViewMap* views = g_view_map.Pointer();
493 ViewMap::iterator it = views->find(webview);
494 return it == views->end() ? NULL : it->second;
495}
496
497/*static*/
498content::RenderView*
499 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28500 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31501}
502
503/*static*/
504void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49505 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59506 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
507 if (!visitor->Visit(it->second))
508 return;
509 }
510}
511
512/*static*/
[email protected]310ebd6302011-10-10 19:06:28513RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15514 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08515 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31516 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08517 const WebPreferences& webkit_prefs,
518 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34519 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56520 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26521 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46522 const string16& frame_name,
523 int32 next_page_id) {
initial.commit09911bf2008-07-26 23:55:29524 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28525 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51526 parent_hwnd,
527 opener_id,
528 renderer_prefs,
529 webkit_prefs,
530 counter,
531 routing_id,
[email protected]9f4f3322012-01-18 22:29:56532 surface_id,
[email protected]676126f72011-01-15 00:03:51533 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46534 frame_name,
535 next_page_id); // adds reference
initial.commit09911bf2008-07-26 23:55:29536}
537
[email protected]273558fb2012-01-12 15:03:51538WebKit::WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
539 WebKit::WebPeerConnectionHandlerClient* client) {
540 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
541 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
542 return NULL;
543 EnsureMediaStreamImpl();
544 return media_stream_impl_->CreatePeerConnectionHandler(client);
545}
546
[email protected]310ebd6302011-10-10 19:06:28547void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51548 observers_.AddObserver(observer);
549}
550
[email protected]310ebd6302011-10-10 19:06:28551void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
552 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51553 observers_.RemoveObserver(observer);
554}
555
[email protected]310ebd6302011-10-10 19:06:28556WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26557 return static_cast<WebKit::WebView*>(webwidget());
558}
559
[email protected]310ebd6302011-10-10 19:06:28560void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40561 if (!enabled) {
562 load_progress_tracker_.reset(NULL);
563 return;
564 }
565 if (load_progress_tracker_ == NULL)
566 load_progress_tracker_.reset(new LoadProgressTracker(this));
567}
568
[email protected]310ebd6302011-10-10 19:06:28569void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51570 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29571}
572
[email protected]310ebd6302011-10-10 19:06:28573void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26574 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30575 // If the renderer is visible, set initial visibility and focus state.
576 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34577#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30578 delegate->SetContainerVisibility(true);
579 if (webview() && webview()->isActive())
580 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34581#endif
[email protected]49232292010-09-03 19:07:30582 }
[email protected]784ea1ab2010-09-18 00:02:34583 // Plugins start assuming the content has focus (so that they work in
584 // environments where RenderView isn't hosting them), so we always have to
585 // set the initial state. See webplugin_delegate_impl.h for details.
586 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26587}
588
[email protected]310ebd6302011-10-10 19:06:28589void RenderViewImpl::UnregisterPluginDelegate(
590 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26591 plugin_delegates_.erase(delegate);
592}
[email protected]d8fd6fa2010-02-01 15:54:26593
[email protected]310ebd6302011-10-10 19:06:28594bool RenderViewImpl::GetPluginInfo(const GURL& url,
595 const GURL& page_url,
596 const std::string& mime_type,
597 webkit::WebPluginInfo* plugin_info,
598 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08599 bool found = false;
600 Send(new ViewHostMsg_GetPluginInfo(
601 routing_id_, url, page_url, mime_type, &found, plugin_info,
602 actual_mime_type));
603 return found;
604}
605
[email protected]310ebd6302011-10-10 19:06:28606bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27607 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27608 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41609 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26610
[email protected]676126f72011-01-15 00:03:51611 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
612 RenderViewObserver* observer;
613 while ((observer = it.GetNext()) != NULL)
614 if (observer->OnMessageReceived(message))
615 return true;
[email protected]b2abac72009-02-26 12:39:28616
[email protected]a95986a82010-12-24 06:19:28617 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40618 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28619 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29620 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
621 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56622 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29623 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
624 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
625 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
626 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27627#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35628 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27629#endif
initial.commit09911bf2008-07-26 23:55:29630 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15631 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29632 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
633 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
634 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08635 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29636 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15637 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29638 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49639 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
640 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17641 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17642 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41643 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54644 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
645 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29646 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18647 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
648 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29649 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48650 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55651 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
652 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
653 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
654 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
655 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
656 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
657 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45658 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40659 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29660 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19661 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
662 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29663 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
664 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
665 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51666 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
667 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29668 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04669 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15670 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29671 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
672 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08673 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
674 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00675 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16676 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14677 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25678 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
679 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47680 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]cda45c02010-02-25 19:28:10681 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
682 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51683 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56684 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36685 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34686 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14687#if defined(OS_MACOSX)
688 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13689 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13690 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
691 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14692#endif
[email protected]446705872009-09-10 07:22:48693 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33694 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33695 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
696 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24697 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42698 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
699 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19700 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
701 OnGetAllSavableResourceLinksForCurrentPage)
702 IPC_MESSAGE_HANDLER(
703 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
704 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08705#if defined(OS_MACOSX)
706 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
707#endif
[email protected]521b2482011-01-15 00:10:10708 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51709 // TODO(viettrungluu): Move to a separate message filter.
710#if defined(ENABLE_FLAPPER_HACKS)
711 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
712#endif
[email protected]54ca3ca892011-06-07 21:14:54713#if defined(OS_MACOSX)
714 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
715#endif
[email protected]9e1ad4b2011-08-14 16:49:19716 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
717 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18718 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]67bfb83f2011-09-22 03:36:37719 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
720 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
[email protected]7f3c7af2011-10-20 22:52:51721 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19722
initial.commit09911bf2008-07-26 23:55:29723 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28724 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29725 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40726
727 if (!msg_is_ok) {
728 // The message had a handler, but its deserialization failed.
729 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28730 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40731 }
732
[email protected]a95986a82010-12-24 06:19:28733 return handled;
initial.commit09911bf2008-07-26 23:55:29734}
735
[email protected]310ebd6302011-10-10 19:06:28736void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
initial.commit09911bf2008-07-26 23:55:29737 if (!webview())
738 return;
739
[email protected]440a0e52011-09-13 17:38:58740 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
741
[email protected]007733c2011-11-17 00:34:07742 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03743
744 // If this is a stale back/forward (due to a recent navigation the browser
745 // didn't know about), ignore it.
746 if (IsBackForwardToStaleEntry(params, is_reload))
747 return;
748
[email protected]992db4c2011-05-12 15:37:15749 // Swap this renderer back in if necessary.
750 if (is_swapped_out_)
751 SetSwappedOut(false);
752
[email protected]3cc72b12010-03-18 23:03:00753 history_list_offset_ = params.current_history_list_offset;
754 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03755 if (history_list_length_ >= 0)
756 history_page_ids_.resize(history_list_length_, -1);
757 if (params.pending_history_list_offset >= 0 &&
758 params.pending_history_list_offset < history_list_length_)
759 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00760
[email protected]38b592902011-04-16 02:08:42761 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29762
[email protected]26aa0482009-09-30 16:55:27763 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45764 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29765 // We cannot reload if we do not have any history state. This happens, for
766 // example, when recovering from a crash. Our workaround here is a bit of
767 // a hack since it means that reload after a crashed tab does not cause an
768 // end-to-end cache validation.
769 is_reload = false;
770 }
771
[email protected]007733c2011-11-17 00:34:07772 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
773 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50774
[email protected]04d3c6e2009-05-22 17:00:13775 // If we are reloading, then WebKit will use the history state of the current
776 // page, so we should just ignore any given history state. Otherwise, if we
777 // have history state, then we need to navigate to it, which corresponds to a
778 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55779 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29780 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02781 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29782 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55783 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13784 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58785 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45786 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17787 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13788 } else {
789 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28790 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29791
[email protected]e6f546c32009-07-01 17:12:55792 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23793 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13794
[email protected]dd7daa82009-08-10 05:46:45795 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55796 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13797
[email protected]445e1042011-12-03 21:03:15798 if (params.referrer.url.is_valid()) {
799 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
800 params.referrer.policy,
801 params.url,
802 WebString::fromUTF8(params.referrer.url.spec()));
803 if (!referrer.isEmpty())
804 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28805 }
[email protected]04d3c6e2009-05-22 17:00:13806
[email protected]52c68652010-12-07 17:47:04807 if (!params.extra_headers.empty()) {
808 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
809 params.extra_headers.end(), "\n");
810 i.GetNext(); ) {
811 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
812 WebString::fromUTF8(i.values()));
813 }
814 }
815
[email protected]dd7daa82009-08-10 05:46:45816 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50817 }
818
[email protected]77f17a82009-05-21 04:42:54819 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07820 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29821}
822
[email protected]310ebd6302011-10-10 19:06:28823bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03824 const ViewMsg_Navigate_Params& params,
825 bool is_reload) {
826 // Make sure this isn't a back/forward to an entry we have already cropped
827 // or replaced from our history, before the browser knew about it. If so,
828 // a new navigation has committed in the mean time, and we can ignore this.
829 bool is_back_forward = !is_reload && !params.state.empty();
830
831 // Note: if the history_list_length_ is 0 for a back/forward, we must be
832 // restoring from a previous session. We'll update our state in OnNavigate.
833 if (!is_back_forward || history_list_length_ <= 0)
834 return false;
835
836 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
837
838 // Check for whether the forward history has been cropped due to a recent
839 // navigation the browser didn't know about.
840 if (params.pending_history_list_offset >= history_list_length_)
841 return true;
842
843 // Check for whether this entry has been replaced with a new one.
844 int expected_page_id =
845 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44846 if (expected_page_id > 0 && params.page_id != expected_page_id) {
847 if (params.page_id < expected_page_id)
848 return true;
849
850 // Otherwise we've removed an earlier entry and should have shifted all
851 // entries left. For now, it's ok to lazily update the list.
852 // TODO(creis): Notify all live renderers when we remove entries from
853 // the front of the list, so that we don't hit this case.
854 history_page_ids_[params.pending_history_list_offset] = params.page_id;
855 }
[email protected]d466b8a2011-07-15 21:48:03856
857 return false;
858}
859
initial.commit09911bf2008-07-26 23:55:29860// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28861void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44862 if (webview()) {
863 WebFrame* main_frame = webview()->mainFrame();
864 // Stop the alt error page fetcher. If we let it continue it may complete
865 // and cause RenderViewHostManager to swap to this RenderView, even though
866 // it may no longer be active.
867 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
868 StopAltErrorPageFetcher(main_frame->dataSource());
869 main_frame->stopLoading();
870 }
initial.commit09911bf2008-07-26 23:55:29871}
872
[email protected]ecbf10d2010-02-18 13:03:29873// Reload current focused frame.
874// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28875void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29876 if (webview() && webview()->focusedFrame()) {
877 // We always obey the cache (ignore_cache=false) here.
878 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
879 // a cache-ignoring reload of the frame.
880 webview()->focusedFrame()->reload(false);
881 }
[email protected]1dda4022010-01-28 18:24:56882}
883
[email protected]310ebd6302011-10-10 19:06:28884void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27885 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29886}
887
[email protected]310ebd6302011-10-10 19:06:28888void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:25889 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27890 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25891 return;
892
[email protected]26aa0482009-09-30 16:55:27893 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45894 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25895}
896
[email protected]310ebd6302011-10-10 19:06:28897void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:29898 // Check if there is a targeturl waiting to be sent.
899 if (target_url_status_ == TARGET_PENDING) {
900 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
901 pending_target_url_));
902 }
903
904 target_url_status_ = TARGET_NONE;
905}
906
[email protected]310ebd6302011-10-10 19:06:28907void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:29908 if (!webview())
909 return;
910
[email protected]26aa0482009-09-30 16:55:27911 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29912}
913
[email protected]310ebd6302011-10-10 19:06:28914void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:29915 if (!webview())
916 return;
917
[email protected]26aa0482009-09-30 16:55:27918 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29919}
920
[email protected]310ebd6302011-10-10 19:06:28921void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:29922 if (!webview())
923 return;
924
[email protected]26aa0482009-09-30 16:55:27925 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29926}
927
[email protected]310ebd6302011-10-10 19:06:28928void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:29929 if (!webview())
930 return;
931
[email protected]f6b1856b2011-06-29 22:02:53932 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
933 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29934}
935
[email protected]c0cc3092009-09-12 08:27:27936#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:28937void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:35938 if (!webview())
939 return;
940
941 // Since the find pasteboard supports only plain text, this can be simpler
942 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27943 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35944 if (frame->hasSelection()) {
945 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:27946 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:17947 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35948 }
[email protected]a954bf72009-09-12 07:30:35949}
[email protected]c0cc3092009-09-12 08:27:27950#endif
[email protected]a954bf72009-09-12 07:30:35951
[email protected]310ebd6302011-10-10 19:06:28952void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:29953 if (!webview())
954 return;
955
[email protected]26aa0482009-09-30 16:55:27956 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29957}
958
[email protected]44bf7002011-10-16 02:46:15959void RenderViewImpl::OnPasteAndMatchStyle() {
960 if (!webview())
961 return;
962
963 webview()->focusedFrame()->executeCommand(
964 WebString::fromUTF8("PasteAndMatchStyle"));
965}
966
[email protected]310ebd6302011-10-10 19:06:28967void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29968 if (!webview())
969 return;
970
[email protected]1ff7a032010-02-03 02:46:03971 WebFrame* frame = webview()->focusedFrame();
972 if (!frame->hasSelection())
973 frame->selectWordAroundCaret();
974 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29975}
976
[email protected]310ebd6302011-10-10 19:06:28977void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:29978 if (!webview())
979 return;
980
[email protected]26aa0482009-09-30 16:55:27981 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29982}
983
[email protected]310ebd6302011-10-10 19:06:28984void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:29985 if (!webview())
986 return;
987
[email protected]26aa0482009-09-30 16:55:27988 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22989 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29990}
991
[email protected]310ebd6302011-10-10 19:06:28992void RenderViewImpl::OnSelectRange(const gfx::Point& start,
993 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:08994 if (!webview())
995 return;
996
997 handling_select_range_ = true;
998 webview()->focusedFrame()->selectRange(start, end);
999 handling_select_range_ = false;
1000}
1001
[email protected]310ebd6302011-10-10 19:06:281002void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1003 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191004 DCHECK(history_length >= 0);
1005 DCHECK(history_list_offset_ == history_list_length_ - 1);
1006 DCHECK(minimum_page_id >= -1);
1007
1008 // Generate the new list.
1009 std::vector<int32> new_history_page_ids(history_length, -1);
1010 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1011 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1012 continue;
1013 new_history_page_ids.push_back(history_page_ids_[i]);
1014 }
1015 new_history_page_ids.swap(history_page_ids_);
1016
1017 // Update indexes.
1018 history_list_length_ = history_page_ids_.size();
1019 history_list_offset_ = history_list_length_ - 1;
1020}
1021
1022
[email protected]310ebd6302011-10-10 19:06:281023void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291024 if (!webview())
1025 return;
[email protected]26aa0482009-09-30 16:55:271026 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291027}
1028
[email protected]54ca3ca892011-06-07 21:14:541029#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281030void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331031 if (!webview())
1032 return;
1033 if (in_live_resize)
1034 webview()->willStartLiveResize();
1035 else
1036 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541037}
1038#endif
1039
[email protected]310ebd6302011-10-10 19:06:281040void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1041 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091042 WebKit::WebNode node = GetFocusedNode();
1043 if (!node.isNull()) {
1044 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191045 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511046 }
1047}
1048
initial.commit09911bf2008-07-26 23:55:291049///////////////////////////////////////////////////////////////////////////////
1050
1051// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281052void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451053 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291054 DCHECK(ds);
1055
[email protected]726985e22009-06-18 21:09:281056 const WebURLRequest& request = ds->request();
1057 const WebURLRequest& original_request = ds->originalRequest();
1058 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291059
[email protected]007733c2011-11-17 00:34:071060 DocumentState* document_state = DocumentState::FromDataSource(ds);
1061 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291062
1063 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281064 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291065 params.is_post = false;
1066 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071067 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191068 params.socket_address.set_host(response.remoteIPAddress().utf8());
1069 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031070 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091071 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071072 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291073 // SSL state specified in the request takes precedence over the one in the
1074 // response.
1075 // So far this is only intended for error pages that are not expected to be
1076 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281077 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071078 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291079 } else {
[email protected]726985e22009-06-18 21:09:281080 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291081 }
1082
1083 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281084 if (ds->hasUnreachableURL()) {
1085 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291086 } else {
[email protected]726985e22009-06-18 21:09:281087 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291088 }
1089
[email protected]5f9b8712011-11-23 08:55:571090 if (frame->document().baseURL() != params.url)
1091 params.base_url = frame->document().baseURL();
1092
[email protected]726985e22009-06-18 21:09:281093 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241094 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041095 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291096
[email protected]007733c2011-11-17 00:34:071097 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351098 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071099 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291100
1101 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071102 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291103 if (password_form_data)
1104 params.password_form = *password_form_data;
1105
1106 params.gesture = navigation_gesture_;
1107 navigation_gesture_ = NavigationGestureUnknown;
1108
[email protected]0f38dc4552011-02-25 11:24:001109 // Make navigation state a part of the FrameNavigate message so that commited
1110 // entry had it at all times.
1111 const WebHistoryItem& item = frame->currentHistoryItem();
1112 if (!item.isNull()) {
1113 params.content_state = webkit_glue::HistoryItemToString(item);
1114 } else {
1115 params.content_state =
1116 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1117 }
1118
[email protected]dd7daa82009-08-10 05:46:451119 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291120 // Top-level navigation.
1121
[email protected]b75b8292010-10-01 07:28:251122 // Set zoom level, but don't do it for full-page plugin since they don't use
1123 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011124 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541125 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251126 if (webview()->mainFrame()->document().isPluginDocument()) {
1127 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251128 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251129 } else {
1130 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251131 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251132 }
1133
[email protected]f85f0702010-01-30 09:31:011134 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511135 // This zoom level was merely recorded transiently for this load. We can
1136 // erase it now. If at some point we reload this page, the browser will
1137 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011138 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511139 }
1140
[email protected]b75b8292010-10-01 07:28:251141 // Reset the zoom limits in case a plugin had changed them previously. This
1142 // will also call us back which will cause us to send a message to
1143 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251144 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011145 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1146 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251147
initial.commit09911bf2008-07-26 23:55:291148 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551149 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291150
[email protected]daa8c58e2009-06-15 17:21:101151 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581152 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291153 // If the main frame does a load, it should not be reported as a subframe
1154 // navigation. This can occur in the following case:
1155 // 1. You're on a site with frames.
1156 // 2. You do a subframe navigation. This is stored with transition type
1157 // MANUAL_SUBFRAME.
1158 // 3. You navigate to some non-frame site, say, google.com.
1159 // 4. You navigate back to the page from step 2. Since it was initially
1160 // MANUAL_SUBFRAME, it will be that same transition type here.
1161 // We don't want that, because any navigation that changes the toplevel
1162 // frame should be tracked as a toplevel navigation (this allows us to
1163 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581164 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291165 }
1166
initial.commit09911bf2008-07-26 23:55:291167 // If we have a valid consumed client redirect source,
1168 // the page contained a client redirect (meta refresh, document.loc...),
1169 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151170 if (completed_client_redirect_src_.url.is_valid()) {
1171 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291172 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581173 params.transition = static_cast<content::PageTransition>(
1174 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291175 } else {
1176 // Bug 654101: the referrer will be empty on https->http transitions. It
1177 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151178 params.referrer = Referrer(GURL(
1179 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
1180 getReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291181 }
1182
[email protected]726985e22009-06-18 21:09:281183 string16 method = request.httpMethod();
1184 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291185 params.is_post = true;
1186
[email protected]c2a797d2009-09-21 16:46:321187 // Save some histogram data so we can compute the average memory used per
1188 // page load of the glyphs.
1189 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1190 webkit_glue::GetGlyphPageCount());
1191
[email protected]15cf526b2010-02-12 06:33:491192 // This message needs to be sent before any of allowScripts(),
1193 // allowImages(), allowPlugins() is called for the new page, so that when
1194 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1195 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291196 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1197 } else {
1198 // Subframe navigation: the type depends on whether this navigation
1199 // generated a new session history entry. When they do generate a session
1200 // history entry, it means the user initiated the navigation and we should
1201 // mark it as such. This test checks if this is the first time UpdateURL
1202 // has been called since WillNavigateToURL was called to initiate the load.
1203 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581204 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291205 else
[email protected]2905f742011-10-13 03:51:581206 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291207
initial.commit09911bf2008-07-26 23:55:291208 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1209 }
1210
1211 last_page_id_sent_to_browser_ =
1212 std::max(last_page_id_sent_to_browser_, page_id_);
1213
1214 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101215 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581216 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291217}
1218
1219// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281220void RenderViewImpl::UpdateTitle(WebFrame* frame,
1221 const string16& title,
1222 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461223 // Ignore all but top level navigations.
1224 if (frame->parent())
1225 return;
1226
1227 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1228 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1229 title_direction));
initial.commit09911bf2008-07-26 23:55:291230}
1231
[email protected]310ebd6302011-10-10 19:06:281232void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1233 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291234 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271235 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291236 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301237 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291238 last_encoding_name_ = encoding_name;
1239
[email protected]e38f40152008-09-12 23:08:301240 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291241 }
1242}
1243
[email protected]e15f680732010-11-23 22:30:201244// Sends the last committed session history state to the browser so it will be
1245// saved before we navigate to a new page. This must be called *before* the
1246// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281247void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291248 // If we have a valid page ID at this point, then it corresponds to the page
1249 // we are navigating away from. Otherwise, this is the first navigation, so
1250 // there is no past session history to record.
1251 if (page_id_ == -1)
1252 return;
1253
[email protected]ca948a22009-06-25 19:36:171254 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271255 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171256 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291257 return;
[email protected]ca948a22009-06-25 19:36:171258
1259 Send(new ViewHostMsg_UpdateState(
1260 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291261}
1262
[email protected]310ebd6302011-10-10 19:06:281263void RenderViewImpl::OpenURL(WebFrame* frame,
1264 const GURL& url,
[email protected]445e1042011-12-03 21:03:151265 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281266 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171267 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581268 routing_id_,
1269 url,
1270 referrer,
1271 NavigationPolicyToDisposition(policy),
1272 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171273}
1274
[email protected]79dbc662009-09-04 05:42:511275// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291276
[email protected]310ebd6302011-10-10 19:06:281277void RenderViewImpl::LoadNavigationErrorPage(
1278 WebFrame* frame,
1279 const WebURLRequest& failed_request,
1280 const WebURLError& error,
1281 const std::string& html,
1282 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581283 std::string alt_html;
1284 const std::string* error_html;
1285
1286 if (!html.empty()) {
1287 error_html = &html;
1288 } else {
1289 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1290 failed_request, error, &alt_html, NULL);
1291 error_html = &alt_html;
1292 }
1293
1294 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361295 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251296 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551297 replace);
initial.commit09911bf2008-07-26 23:55:291298}
1299
[email protected]269f86d2011-12-07 02:43:471300bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281301 const string16& message,
1302 const string16& default_value,
1303 const GURL& frame_url,
1304 string16* result) {
initial.commit09911bf2008-07-26 23:55:291305 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411306 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291307 if (!result)
1308 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291309
[email protected]12636df2009-09-28 22:32:211310 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1311 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291312 return success;
1313}
1314
[email protected]310ebd6302011-10-10 19:06:281315bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571316 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1317 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1318 // it is particularly important that we do not call willEnterModalLoop as
1319 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441320 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1321 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571322
1323 message->EnableMessagePumping(); // Runs a nested message loop.
1324 return Send(message);
1325}
1326
[email protected]48c9cf2d2009-09-16 16:47:521327// WebKit::WebViewClient ------------------------------------------------------
1328
[email protected]310ebd6302011-10-10 19:06:281329WebView* RenderViewImpl::createView(
[email protected]844acf372011-01-14 10:49:271330 WebFrame* creator,
1331 const WebURLRequest& request,
1332 const WebWindowFeatures& features,
1333 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521334 // Check to make sure we aren't overloading on popups.
1335 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1336 return NULL;
1337
[email protected]8ab04652010-06-12 02:47:261338 ViewHostMsg_CreateWindow_Params params;
1339 params.opener_id = routing_id_;
1340 params.user_gesture = creator->isProcessingUserGesture();
1341 params.window_container_type = WindowFeaturesToContainerType(features);
1342 params.session_storage_namespace_id = session_storage_namespace_id_;
1343 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111344 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411345 params.opener_url = creator->document().url();
1346 params.opener_security_origin =
1347 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111348 if (!request.isNull())
1349 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261350
[email protected]48c9cf2d2009-09-16 16:47:521351 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561352 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341353 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261354 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521355
[email protected]380244092011-10-07 17:26:271356 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261357 new ViewHostMsg_CreateWindow(params,
1358 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561359 &surface_id,
[email protected]8ab04652010-06-12 02:47:261360 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211361 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521362 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521363
[email protected]310ebd6302011-10-10 19:06:281364 RenderViewImpl* view = RenderViewImpl::Create(
1365 0,
1366 routing_id_,
1367 renderer_preferences_,
1368 webkit_preferences_,
1369 shared_popup_counter_,
1370 routing_id,
[email protected]9f4f3322012-01-18 22:29:561371 surface_id,
[email protected]310ebd6302011-10-10 19:06:281372 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461373 frame_name,
1374 1);
[email protected]8ab04652010-06-12 02:47:261375 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521376
[email protected]007a848b2009-10-26 15:55:461377 // Record whether the creator frame is trying to suppress the opener field.
1378 view->opener_suppressed_ = opener_suppressed;
1379
[email protected]48c9cf2d2009-09-16 16:47:521380 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411381 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521382 if (!creator_url.is_valid() || !creator_url.IsStandard())
1383 creator_url = GURL();
1384 view->creator_url_ = creator_url;
1385
1386 // Copy over the alternate error page URL so we can have alt error pages in
1387 // the new render view (we don't need the browser to send the URL back down).
1388 view->alternate_error_page_url_ = alternate_error_page_url_;
1389
1390 return view->webview();
1391}
1392
[email protected]310ebd6302011-10-10 19:06:281393WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]380244092011-10-07 17:26:271394 RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521395 return widget->webwidget();
1396}
1397
[email protected]310ebd6302011-10-10 19:06:281398WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441399 // TODO(jcivelli): Remove this deprecated method when its been removed from
1400 // the WebViewClient interface. It's been replaced by
1401 // createExternalPopupMenu.
1402 NOTREACHED();
1403 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521404}
1405
[email protected]310ebd6302011-10-10 19:06:281406WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081407 const WebPopupMenuInfo& popup_menu_info,
1408 WebExternalPopupMenuClient* popup_menu_client) {
1409 DCHECK(!external_popup_menu_.get());
1410 external_popup_menu_.reset(
1411 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1412 return external_popup_menu_.get();
1413}
1414
[email protected]310ebd6302011-10-10 19:06:281415RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521416 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531417 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421418 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411419 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531420 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271421 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391422 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561423 return widget;
[email protected]79c7bed2010-09-14 22:28:391424}
1425
[email protected]310ebd6302011-10-10 19:06:281426WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1427 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341428 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391429 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291430 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1431 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1432 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341433}
1434
[email protected]310ebd6302011-10-10 19:06:281435void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521436 const WebConsoleMessage& message, const WebString& source_name,
1437 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081438 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511439 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081440 case WebConsoleMessage::LevelTip:
1441 log_severity = logging::LOG_VERBOSE;
1442 break;
1443 case WebConsoleMessage::LevelLog:
1444 log_severity = logging::LOG_INFO;
1445 break;
1446 case WebConsoleMessage::LevelWarning:
1447 log_severity = logging::LOG_WARNING;
1448 break;
1449 case WebConsoleMessage::LevelError:
1450 log_severity = logging::LOG_ERROR;
1451 break;
1452 default:
1453 NOTREACHED();
1454 }
1455
[email protected]48c9cf2d2009-09-16 16:47:521456 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081457 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311458 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521459 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311460 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521461}
1462
[email protected]310ebd6302011-10-10 19:06:281463void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421464 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521465}
1466
[email protected]310ebd6302011-10-10 19:06:281467WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511468 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021469}
1470
[email protected]310ebd6302011-10-10 19:06:281471bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121472 const WebString& path,
1473 WebFileChooserCompletion* chooser_completion) {
1474 int id = enumeration_completion_id_++;
1475 enumeration_completions_[id] = chooser_completion;
1476 return Send(new ViewHostMsg_EnumerateDirectory(
1477 routing_id_,
1478 id,
1479 webkit_glue::WebStringToFilePath(path)));
1480}
1481
[email protected]310ebd6302011-10-10 19:06:281482void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521483 if (is_loading_) {
1484 DLOG(WARNING) << "didStartLoading called while loading";
1485 return;
1486 }
1487
1488 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521489
1490 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311491
1492 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521493}
1494
[email protected]310ebd6302011-10-10 19:06:281495void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521496 if (!is_loading_) {
1497 DLOG(WARNING) << "DidStopLoading called while not loading";
1498 return;
1499 }
1500
1501 is_loading_ = false;
1502
1503 // NOTE: For now we're doing the safest thing, and sending out notification
1504 // when done loading. This currently isn't an issue as the favicon is only
1505 // displayed when done loading. Ideally we would send notification when
1506 // finished parsing the head, but webkit doesn't support that yet.
1507 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521508 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1509
[email protected]90109412010-12-15 17:14:241510 if (load_progress_tracker_ != NULL)
1511 load_progress_tracker_->DidStopLoading();
1512
[email protected]93b9d692011-04-13 00:44:311513 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521514}
1515
[email protected]310ebd6302011-10-10 19:06:281516void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1517 double load_progress) {
[email protected]90109412010-12-15 17:14:241518 if (load_progress_tracker_ != NULL)
1519 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1520}
1521
[email protected]310ebd6302011-10-10 19:06:281522bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061523#if defined(OS_MACOSX)
1524 return true;
1525#else
1526 return false;
1527#endif
1528}
1529
[email protected]310ebd6302011-10-10 19:06:281530bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031531#if defined(OS_WIN)
1532 return true;
1533#else
1534 return false;
1535#endif
1536}
1537
[email protected]310ebd6302011-10-10 19:06:281538void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081539 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031540 return;
[email protected]4fb60142011-08-09 02:22:081541 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011542
[email protected]b781ff282011-08-20 06:19:361543 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031544}
1545
[email protected]310ebd6302011-10-10 19:06:281546void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121547 const std::string& name = UTF16ToUTF8(command_name);
1548 if (StartsWithASCII(name, "Move", true) ||
1549 StartsWithASCII(name, "Insert", true) ||
1550 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031551 return;
[email protected]f1a29a02011-10-06 23:08:441552 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031553}
1554
[email protected]310ebd6302011-10-10 19:06:281555bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101556 if (edit_commands_.empty())
1557 return false;
1558
[email protected]26aa0482009-09-30 16:55:271559 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101560 if (!frame)
1561 return false;
1562
1563 EditCommands::iterator it = edit_commands_.begin();
1564 EditCommands::iterator end = edit_commands_.end();
1565
[email protected]507b33ea2009-09-29 03:56:511566 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101567 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331568 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1569 // key (but it's the exception). Once one edit command is not executed, it
1570 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101571 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1572 WebString::fromUTF8(it->value)))
1573 break;
[email protected]507b33ea2009-09-29 03:56:511574 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101575 }
1576
[email protected]507b33ea2009-09-29 03:56:511577 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101578}
1579
[email protected]310ebd6302011-10-10 19:06:281580bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351581 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471582 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351583 // Do not open the file dialog in a hidden RenderView.
1584 if (is_hidden())
1585 return false;
[email protected]8caadeb2011-11-22 02:45:231586 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261587 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231588 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261589 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231590 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501591 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231592 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261593 else
[email protected]8caadeb2011-11-22 02:45:231594 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471595 ipc_params.title = params.title;
1596 ipc_params.default_file_name =
1597 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461598 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1599 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1600 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471601
1602 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461603}
1604
[email protected]269f86d2011-12-07 02:43:471605void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1606 const WebString& message) {
1607 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411608 message,
1609 string16(),
[email protected]b6cb3a842011-06-24 18:28:411610 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521611 NULL);
1612}
1613
[email protected]269f86d2011-12-07 02:43:471614bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1615 const WebString& message) {
1616 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411617 message,
1618 string16(),
[email protected]b6cb3a842011-06-24 18:28:411619 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521620 NULL);
1621}
1622
[email protected]269f86d2011-12-07 02:43:471623bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1624 const WebString& message,
1625 const WebString& default_value,
1626 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411627 string16 result;
[email protected]269f86d2011-12-07 02:43:471628 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411629 message,
1630 default_value,
[email protected]b6cb3a842011-06-24 18:28:411631 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521632 &result);
1633 if (ok)
[email protected]4f5ce842011-05-27 19:34:411634 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521635 return ok;
1636}
1637
[email protected]310ebd6302011-10-10 19:06:281638bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521639 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151640 // If we are swapping out, we have already run the beforeunload handler.
1641 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1642 // at all, to avoid running it twice.
1643 if (is_swapped_out_)
1644 return true;
1645
[email protected]48c9cf2d2009-09-16 16:47:521646 bool success = false;
1647 // This is an ignored return value, but is included so we can accept the same
1648 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411649 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211650 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411651 routing_id_, frame->document().url(), message,
1652 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521653 return success;
1654}
1655
[email protected]310ebd6302011-10-10 19:06:281656void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441657 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291658 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371659
1660 // frame is NULL if invoked by BlockedPlugin.
1661 if (frame)
1662 params.frame_id = frame->identifier();
1663
[email protected]db803aae2011-03-05 02:00:421664 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271665 // it. We replace it with an empty GURL so the appropriate items are disabled
1666 // in the context menu.
1667 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1668 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421669 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271670 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101671 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291672 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441673}
1674
[email protected]310ebd6302011-10-10 19:06:281675void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261676 // TODO(darin): Remove once WebKit roll is complete.
1677 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471678}
1679
[email protected]310ebd6302011-10-10 19:06:281680void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261681 // TODO(darin): Remove once WebKit roll is complete.
1682 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471683}
1684
[email protected]310ebd6302011-10-10 19:06:281685void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521686}
1687
[email protected]310ebd6302011-10-10 19:06:281688void RenderViewImpl::UpdateTargetURL(const GURL& url,
1689 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581690 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521691 if (latest_url == target_url_)
1692 return;
[email protected]163f8242009-10-30 20:19:551693
[email protected]48c9cf2d2009-09-16 16:47:521694 // Tell the browser to display a destination link.
1695 if (target_url_status_ == TARGET_INFLIGHT ||
1696 target_url_status_ == TARGET_PENDING) {
1697 // If we have a request in-flight, save the URL to be sent when we
1698 // receive an ACK to the in-flight request. We can happily overwrite
1699 // any existing pending sends.
1700 pending_target_url_ = latest_url;
1701 target_url_status_ = TARGET_PENDING;
1702 } else {
[email protected]c85f0212011-11-04 16:54:411703 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1704 // see |ParamTraits<GURL>|.
1705 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1706 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521707 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1708 target_url_ = latest_url;
1709 target_url_status_ = TARGET_INFLIGHT;
1710 }
1711}
1712
[email protected]310ebd6302011-10-10 19:06:281713void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311714 int delay;
1715 if (send_content_state_immediately_)
1716 delay = 0;
1717 else if (is_hidden())
1718 delay = kDelaySecondsForContentStateSyncHidden;
1719 else
1720 delay = kDelaySecondsForContentStateSync;
1721
1722 if (nav_state_sync_timer_.IsRunning()) {
1723 // The timer is already running. If the delay of the timer maches the amount
1724 // we want to delay by, then return. Otherwise stop the timer so that it
1725 // gets started with the right delay.
1726 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1727 return;
1728 nav_state_sync_timer_.Stop();
1729 }
1730
[email protected]d323a172011-09-02 18:23:021731 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281732 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311733}
1734
[email protected]310ebd6302011-10-10 19:06:281735void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551736 mouse_over_url_ = GURL(url);
1737 UpdateTargetURL(mouse_over_url_, focus_url_);
1738}
1739
[email protected]310ebd6302011-10-10 19:06:281740void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551741 focus_url_ = GURL(url);
1742 UpdateTargetURL(focus_url_, mouse_over_url_);
1743}
1744
[email protected]310ebd6302011-10-10 19:06:281745void RenderViewImpl::startDragging(const WebDragData& data,
1746 WebDragOperationsMask mask,
1747 const WebImage& image,
1748 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411749#if WEBKIT_USING_SKIA
1750 SkBitmap bitmap(image.getSkBitmap());
1751#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331752 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411753#endif
1754
[email protected]59f4f2fa2011-03-23 01:00:551755 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521756 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411757 mask,
1758 bitmap,
1759 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521760}
1761
[email protected]310ebd6302011-10-10 19:06:281762bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451763 return renderer_preferences_.can_accept_load_drops;
1764}
1765
[email protected]310ebd6302011-10-10 19:06:281766void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521767 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1768}
1769
[email protected]310ebd6302011-10-10 19:06:281770void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521771 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1772}
1773
[email protected]310ebd6302011-10-10 19:06:281774void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511775 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071776
[email protected]38b592902011-04-16 02:08:421777 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491778}
1779
[email protected]169d4282011-11-30 19:33:591780void RenderViewImpl::didUpdateLayout() {
1781 // We don't always want to set up a timer, only if we've been put in that
1782 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1783 // message.
1784 if (!send_preferred_size_changes_ || !webview())
1785 return;
1786
1787 if (check_preferred_size_timer_.IsRunning())
1788 return;
1789 check_preferred_size_timer_.Start(FROM_HERE,
1790 TimeDelta::FromMilliseconds(0), this,
1791 &RenderViewImpl::CheckPreferredSize);
1792}
1793
[email protected]310ebd6302011-10-10 19:06:281794void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521795 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1796}
1797
[email protected]310ebd6302011-10-10 19:06:281798int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001799 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521800}
1801
[email protected]310ebd6302011-10-10 19:06:281802int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001803 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521804}
1805
[email protected]310ebd6302011-10-10 19:06:281806void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321807 const WebAccessibilityObject& obj,
1808 WebAccessibilityNotification notification) {
1809 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1810}
1811
[email protected]310ebd6302011-10-10 19:06:281812void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141813 const WebString& value) {
1814 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1815 key.utf8(),
1816 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261817}
1818
[email protected]79dbc662009-09-04 05:42:511819// WebKit::WebWidgetClient ----------------------------------------------------
1820
[email protected]310ebd6302011-10-10 19:06:281821void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121822 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1823 // we won't have to test for user gesture anymore and we can
1824 // move that code back to render_widget.cc
1825 if (webview() && webview()->mainFrame() &&
1826 webview()->mainFrame()->isProcessingUserGesture()) {
1827 Send(new ViewHostMsg_Focus(routing_id_));
1828 }
1829}
1830
[email protected]310ebd6302011-10-10 19:06:281831void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121832 // TODO(jcivelli): see TODO above in didFocus().
1833 if (webview() && webview()->mainFrame() &&
1834 webview()->mainFrame()->isProcessingUserGesture()) {
1835 Send(new ViewHostMsg_Blur(routing_id_));
1836 }
1837}
1838
initial.commit09911bf2008-07-26 23:55:291839// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281840// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291841// point to dispatch the ShowView message.
1842//
1843// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281844// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291845//
[email protected]310ebd6302011-10-10 19:06:281846void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291847 DCHECK(!did_show_) << "received extraneous Show call";
1848 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1849
1850 if (did_show_)
1851 return;
1852 did_show_ = true;
1853
[email protected]6779aa12011-03-29 17:32:241854 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041855 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041856
[email protected]28295ec2009-10-16 05:34:331857 // Force new windows to a popup if they were not opened with a user gesture.
1858 if (!opened_by_user_gesture_) {
1859 // We exempt background tabs for compat with older versions of Chrome.
1860 // TODO(darin): This seems bogus. These should have a user gesture, so
1861 // we probably don't need this check.
1862 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1863 policy = WebKit::WebNavigationPolicyNewPopup;
1864 }
1865
initial.commit09911bf2008-07-26 23:55:291866 // NOTE: initial_pos_ may still have its default values at this point, but
1867 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1868 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281869 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1870 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291871 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241872 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291873}
1874
[email protected]310ebd6302011-10-10 19:06:281875void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:291876 DCHECK(did_show_) << "should already have shown the view";
1877
[email protected]c1f50aa2010-02-18 03:46:571878 // We must keep WebKit's shared timer running in this case in order to allow
1879 // showModalDialog to function properly.
1880 //
1881 // TODO(darin): WebKit should really be smarter about suppressing events and
1882 // timers so that we do not need to manage the shared timer in such a heavy
1883 // handed manner.
1884 //
[email protected]f1a29a02011-10-06 23:08:441885 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1886 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:571887
[email protected]12636df2009-09-28 22:32:211888 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291889}
1890
[email protected]2b624c562011-10-27 22:58:261891bool RenderViewImpl::enterFullScreen() {
1892 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1893 return true;
1894}
1895
1896void RenderViewImpl::exitFullScreen() {
1897 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1898}
1899
[email protected]3d9689372009-09-10 04:29:171900// WebKit::WebFrameClient -----------------------------------------------------
1901
[email protected]310ebd6302011-10-10 19:06:281902WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
1903 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:551904 WebPlugin* plugin = NULL;
1905 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
1906 this, frame, params, &plugin)) {
1907 return plugin;
1908 }
1909
[email protected]a813c8e2011-10-08 01:34:111910 webkit::WebPluginInfo info;
1911 std::string mime_type;
1912 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
1913 params.mimeType.utf8(), &info, &mime_type);
1914 if (!found)
1915 return NULL;
1916
1917 WebPluginParams params_to_use = params;
1918 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:311919 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:171920}
1921
[email protected]310ebd6302011-10-10 19:06:281922WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:421923 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371924 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421925
[email protected]30447b62009-11-13 01:13:371926 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511927 bool exists = false;
[email protected]30447b62009-11-13 01:13:371928 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511929 ViewHostMsg_CreateWorker_Params params;
1930 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:511931 params.name = name;
1932 params.document_id = document_id;
1933 params.render_view_route_id = routing_id_;
1934 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231935 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371936 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511937 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371938 if (url_mismatch) {
1939 return NULL;
1940 } else {
[email protected]f1a29a02011-10-06 23:08:441941 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:491942 document_id,
[email protected]6de0bcf2010-02-17 22:00:511943 exists,
[email protected]30447b62009-11-13 01:13:371944 route_id,
1945 routing_id_);
1946 }
[email protected]9c00f002009-11-05 22:37:421947}
1948
[email protected]310ebd6302011-10-10 19:06:281949WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:171950 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441951 FOR_EACH_OBSERVER(
1952 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171953
[email protected]bb6fd402011-12-09 02:45:441954 media::MessageLoopFactory* message_loop_factory =
1955 new media::MessageLoopFactoryImpl();
1956 media::FilterCollection* collection = new media::FilterCollection();
1957 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:371958
[email protected]9e2269d2012-01-07 00:06:211959 RenderAudioSourceProvider* audio_source_provider = NULL;
1960
[email protected]3d9689372009-09-10 04:29:171961 // Add in any custom filter factories first.
1962 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1963 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:211964 // audio_source_provider is a "provider" to WebKit, and a sink
1965 // from the perspective of the audio renderer.
1966 audio_source_provider = new RenderAudioSourceProvider();
1967
1968 // Add the chrome specific audio renderer, using audio_source_provider
1969 // as the sink.
1970 AudioRendererImpl* audio_renderer =
1971 new AudioRendererImpl(audio_source_provider);
1972 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:171973 }
1974
[email protected]e1d69d762011-12-13 05:12:181975#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
1976 // Currently only cros/arm has any HW video decode support in
1977 // GpuVideoDecodeAccelerator so we don't even try to use it on other
1978 // platforms. This is a startup-time optimization. When new VDA
1979 // implementations are added, relax the #if above.
1980 WebKit::WebGraphicsContext3D* wk_context3d = webview()->graphicsContext3D();
1981 if (wk_context3d) {
1982 WebGraphicsContext3DCommandBufferImpl* context3d =
1983 static_cast<WebGraphicsContext3DCommandBufferImpl*>(wk_context3d);
1984 GpuChannelHost* gpu_channel_host =
1985 RenderThreadImpl::current()->EstablishGpuChannelSync(
1986 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
1987 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:311988 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
1989 new RendererGpuVideoDecoderFactories(
1990 gpu_channel_host, context3d->context()->AsWeakPtr())));
[email protected]e1d69d762011-12-13 05:12:181991 }
1992#endif
1993
[email protected]da952fd2012-01-13 03:49:251994 webkit_media::WebMediaPlayerImpl* media_player =
1995 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
1996 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
1997 message_loop_factory, media_stream_impl_.get(), render_media_log);
1998 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:561999 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252000 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]9e2269d2012-01-07 00:06:212001 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]bb6fd402011-12-09 02:45:442002 }
[email protected]cec4eb82012-01-12 17:51:562003 return media_player;
[email protected]3d9689372009-09-10 04:29:172004}
2005
[email protected]310ebd6302011-10-10 19:06:282006WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212007 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232008 if (!frame || !frame->view())
2009 return NULL;
[email protected]035545f2010-04-09 13:10:212010 return new RendererWebApplicationCacheHostImpl(
2011 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442012 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212013}
2014
[email protected]310ebd6302011-10-10 19:06:282015WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382016 return &cookie_jar_;
2017}
2018
[email protected]310ebd6302011-10-10 19:06:282019void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512020 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452021}
2022
[email protected]310ebd6302011-10-10 19:06:282023void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512024 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172025}
2026
[email protected]310ebd6302011-10-10 19:06:282027void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172028 WebFrame* frame, const WebURLRequest& request,
2029 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342030 loadURLExternally(frame, request, policy, WebString());
2031}
2032
[email protected]310ebd6302011-10-10 19:06:282033void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342034 WebFrame* frame, const WebURLRequest& request,
2035 WebNavigationPolicy policy,
2036 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592037 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2038 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342039 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2040 suggested_name));
[email protected]efce17b2009-09-11 18:04:592041 } else {
[email protected]445e1042011-12-03 21:03:152042 OpenURL(frame, request.url(),
2043 Referrer(referrer, getReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592044 }
[email protected]3d9689372009-09-10 04:29:172045}
2046
[email protected]310ebd6302011-10-10 19:06:282047WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172048 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222049 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152050 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2051 if (is_swapped_out_) {
2052 DCHECK(request.url() == GURL("about:swappedout"));
2053 return default_policy;
2054 }
2055
[email protected]3d9689372009-09-10 04:29:172056 // Webkit is asking whether to navigate to a new URL.
2057 // This is fine normally, except if we're showing UI from one security
2058 // context and they're trying to navigate to a different context.
2059 const GURL& url = request.url();
2060
[email protected]d19ea342011-04-20 20:31:132061 // A content initiated navigation may have originated from a link-click,
2062 // script, drag-n-drop operation, etc.
2063 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072064 DocumentState::FromDataSource(frame->provisionalDataSource())->
2065 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132066
[email protected]a8c269a2011-10-25 20:17:222067 // Experimental:
2068 // If --enable-strict-site-isolation is enabled, send all top-level
2069 // navigations to the browser to let it swap processes when crossing site
2070 // boundaries. This is currently expected to break some script calls and
2071 // navigations, such as form submissions.
2072 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102073 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2074 !frame->parent() && (is_content_initiated || is_redirect)) {
2075 WebString origin_str = frame->document().securityOrigin().toString();
2076 GURL frame_url(origin_str.utf8().data());
2077 // TODO(cevans): revisit whether this origin check is still necessary once
2078 // crbug.com/101395 is fixed.
2079 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]445e1042011-12-03 21:03:152080 Referrer referrer(
2081 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2082 getReferrerPolicyFromRequest(request));
[email protected]313b80bd2011-11-23 03:49:102083 OpenURL(frame, url, referrer, default_policy);
2084 return WebKit::WebNavigationPolicyIgnore;
2085 }
[email protected]a8c269a2011-10-25 20:17:222086 }
2087
[email protected]3d9689372009-09-10 04:29:172088 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302089 // navigations.
[email protected]5f000f272012-01-19 05:25:082090 if (is_content_initiated) {
2091 bool browser_handles_top_level_requests =
2092 renderer_preferences_.browser_handles_top_level_requests &&
2093 IsNonLocalTopLevelNavigation(url, frame, type);
2094 if (browser_handles_top_level_requests ||
2095 renderer_preferences_.browser_handles_all_requests) {
2096 Referrer referrer(
2097 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2098 getReferrerPolicyFromRequest(request));
2099 // Reset these counters as the RenderView could be reused for the next
2100 // navigation.
2101 page_id_ = -1;
2102 last_page_id_sent_to_browser_ = -1;
2103 OpenURL(frame, url, referrer, default_policy);
2104 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2105 }
[email protected]3d9689372009-09-10 04:29:172106 }
2107
[email protected]6101c342010-12-16 22:44:372108 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552109 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572110 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372111 // opening a new window). But we sometimes navigate to about:blank to clear a
2112 // tab, and we want to still allow that.
2113 //
[email protected]8f4da8c2011-02-09 19:49:572114 // Note: we do this only for GET requests because our mechanism for switching
2115 // processes only issues GET requests. In particular, POST requests don't
2116 // work, because this mechanism does not preserve form POST data. If it
2117 // becomes necessary to support process switching for POST requests, we will
2118 // need to send the request's httpBody data up to the browser process, and
2119 // issue a special POST navigation in WebKit (via
2120 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2121 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222122 if (!frame->parent() && is_content_initiated &&
[email protected]6101c342010-12-16 22:44:372123 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2124 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2125 bool send_referrer = false;
2126 bool should_fork =
[email protected]e091df82011-10-11 18:13:212127 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172128 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372129 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112130
[email protected]e48869a2011-04-01 19:56:032131 if (!should_fork) {
2132 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362133 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032134 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362135 frame, url, is_content_initiated, is_initial_navigation,
2136 &send_referrer);
[email protected]6101c342010-12-16 22:44:372137 }
2138
2139 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152140 Referrer referrer(
2141 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2142 getReferrerPolicyFromRequest(request));
2143 OpenURL(
2144 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112145 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2146 }
[email protected]3d9689372009-09-10 04:29:172147 }
2148
[email protected]43763f982011-08-26 18:33:402149 // Use the frame's original request's URL rather than the document's URL for
2150 // this check. For a popup, the document's URL may become the opener window's
2151 // URL if the opener has called document.write. See http://crbug.com/93517.
2152 GURL old_url(frame->dataSource()->request().url());
2153
[email protected]3d9689372009-09-10 04:29:172154 // Detect when a page is "forking" a new tab that can be safely rendered in
2155 // its own process. This is done by sites like Gmail that try to open links
2156 // in new windows without script connections back to the original page. We
2157 // treat such cases as browser navigations (in which we will create a new
2158 // renderer for a cross-site navigation), rather than WebKit navigations.
2159 //
2160 // We use the following heuristic to decide whether to fork a new page in its
2161 // own process:
2162 // The parent page must open a new tab to about:blank, set the new tab's
2163 // window.opener to null, and then redirect the tab to a cross-site URL using
2164 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462165 //
2166 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2167 // (see below).
[email protected]3d9689372009-09-10 04:29:172168 bool is_fork =
2169 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582170 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172171 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522172 historyBackListCount() < 1 &&
2173 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172174 // The parent page must have set the child's window.opener to null before
2175 // redirecting to the desired URL.
2176 frame->opener() == NULL &&
2177 // Must be a top-level frame.
2178 frame->parent() == NULL &&
2179 // Must not have issued the request from this page.
2180 is_content_initiated &&
2181 // Must be targeted at the current tab.
2182 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2183 // Must be a JavaScript navigation, which appears as "other".
2184 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462185
2186 // Recognize if this navigation is from a link with rel=noreferrer and
2187 // target=_blank attributes, in which case the opener will be suppressed. If
2188 // so, it is safe to load cross-site pages in a separate process, so we
2189 // should let the browser handle it.
2190 bool is_noreferrer_and_blank_target =
2191 // Frame should be top level and not yet navigated.
2192 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412193 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462194 historyBackListCount() < 1 &&
2195 historyForwardListCount() < 1 &&
2196 // Links with rel=noreferrer will have no Referer field, and their
2197 // resulting frame will have its window.opener suppressed.
2198 // TODO(creis): should add a request.httpReferrer() method to help avoid
2199 // typos on the unusual spelling of Referer.
2200 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2201 opener_suppressed_ &&
2202 frame->opener() == NULL &&
2203 // Links with target=_blank will have no name.
2204 frame->name().isNull() &&
2205 // Another frame (with a non-empty creator) should have initiated the
2206 // request, targeted at this frame.
2207 !creator_url_.is_empty() &&
2208 is_content_initiated &&
2209 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2210 type == WebKit::WebNavigationTypeOther;
2211
2212 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172213 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152214 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172215 return WebKit::WebNavigationPolicyIgnore;
2216 }
2217
2218 return default_policy;
2219}
2220
[email protected]310ebd6302011-10-10 19:06:282221bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492222 WebFrame* frame, const WebURLRequest& request) {
2223 // We allow WebKit to think that everything can be handled even though
2224 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342225 return true;
2226}
2227
[email protected]310ebd6302011-10-10 19:06:282228WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492229 WebFrame* frame, const WebURLRequest& request) {
2230 NOTREACHED(); // Since we said we can handle all requests.
2231 return WebURLError();
2232}
2233
[email protected]310ebd6302011-10-10 19:06:282234WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492235 WebFrame* frame, const WebURLRequest& request) {
2236 WebURLError error;
2237 error.domain = WebString::fromUTF8(net::kErrorDomain);
2238 error.reason = net::ERR_ABORTED;
2239 error.unreachableURL = request.url();
2240 return error;
[email protected]7b7a7dc2009-10-19 02:23:342241}
2242
[email protected]310ebd6302011-10-10 19:06:282243void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492244 WebFrame*, const WebURLError&) {
2245 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342246}
2247
[email protected]310ebd6302011-10-10 19:06:282248void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432249 const WebKit::WebFormElement& form) {
2250 // Some login forms have onSubmit handlers that put a hash of the password
2251 // into a hidden field and then clear the password. (Issue 28910.)
2252 // This method gets called before any of those handlers run, so save away
2253 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072254 DocumentState* document_state =
2255 DocumentState::FromDataSource(frame->dataSource());
2256 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432257 PasswordFormDomManager::CreatePasswordForm(form));
2258}
2259
[email protected]310ebd6302011-10-10 19:06:282260void RenderViewImpl::willSubmitForm(WebFrame* frame,
2261 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072262 DocumentState* document_state =
2263 DocumentState::FromDataSource(frame->provisionalDataSource());
2264 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172265
[email protected]2905f742011-10-13 03:51:582266 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2267 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172268
2269 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352270 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072271 document_state->set_searchable_form_url(web_searchable_form_data.url());
2272 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212273 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432274 PasswordForm* password_form_data =
2275 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072276 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432277
[email protected]098c95cb2011-04-28 16:49:012278 // In order to save the password that the user actually typed and not one
2279 // that may have gotten transformed by the site prior to submit, recover it
2280 // from the form contents already stored by |willSendSubmitEvent| into the
2281 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2282 // which is what we're storing into now.)
2283 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072284 DocumentState* old_document_state =
2285 DocumentState::FromDataSource(frame->dataSource());
2286 if (old_document_state) {
2287 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432288 if (old_form_data && old_form_data->action == password_form_data->action)
2289 password_form_data->password_value = old_form_data->password_value;
2290 }
2291 }
[email protected]3d9689372009-09-10 04:29:172292
[email protected]2a5b1732011-04-01 23:55:552293 FOR_EACH_OBSERVER(
2294 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172295}
2296
[email protected]310ebd6302011-10-10 19:06:282297void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172298 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2299 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382300 FOR_EACH_OBSERVER(
2301 RenderViewObserver, observers_,
2302 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172303}
2304
[email protected]310ebd6302011-10-10 19:06:282305void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382306 FOR_EACH_OBSERVER(
2307 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172308}
2309
[email protected]310ebd6302011-10-10 19:06:282310void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172311 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152312 if (!frame->parent()) {
2313 WebDataSource* ds = frame->provisionalDataSource();
2314 // If there's no provisional data source, it's a reference fragment
2315 // navigation.
2316 completed_client_redirect_src_ = Referrer(
2317 from, ds ? getReferrerPolicyFromRequest(ds->request()) :
2318 frame->referrerPolicy());
2319 }
[email protected]eb0bff942011-04-07 22:08:382320 FOR_EACH_OBSERVER(
2321 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172322}
2323
[email protected]310ebd6302011-10-10 19:06:282324void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072325 DocumentState* document_state = DocumentState::FromDataSource(ds);
2326 if (!document_state) {
2327 document_state = new DocumentState;
2328 ds->setExtraData(document_state);
2329 }
2330
[email protected]3d9689372009-09-10 04:29:172331 // The rest of RenderView assumes that a WebDataSource will always have a
2332 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072333 bool content_initiated = !pending_navigation_params_.get();
2334 if (content_initiated)
2335 document_state->set_navigation_state(
2336 NavigationState::CreateContentInitiated());
2337 else
2338 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512339
[email protected]007733c2011-11-17 00:34:072340 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512341 // navigating from a page that used prefetching using a link on that
2342 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072343 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512344 // this value appropriately.
2345 // TODO(gavinp): catch the important case of navigation in a new
2346 // renderer process.
2347 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302348 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522349 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512350 const GURL referrer(
2351 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2352 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072353 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512354 old_frame->dataSource())->was_prefetcher()) {
2355 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2356 WebDataSource* old_frame_ds = old_frame->dataSource();
2357 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072358 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512359 break;
2360 }
2361 }
2362 }
2363 }
2364 }
2365
[email protected]4c1b6f0b2010-02-07 16:38:182366 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522367 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512368 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182369 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072370 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182371 break;
2372 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072373 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182374 break;
2375 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072376 document_state->set_load_type(
2377 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182378 break;
2379 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072380 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182381 break;
2382 }
2383 }
[email protected]fa7b6b542009-11-03 05:02:302384
[email protected]946a0032011-03-31 18:42:282385 FOR_EACH_OBSERVER(
2386 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172387}
2388
[email protected]007733c2011-11-17 00:34:072389void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2390 DocumentState* document_state) {
2391 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2392
2393 if (document_state->request_time().is_null())
2394 document_state->set_request_time(params.request_time);
2395
2396 // A navigation resulting from loading a javascript URL should not be treated
2397 // as a browser initiated event. Instead, we want it to look as if the page
2398 // initiated any load resulting from JS execution.
2399 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2400 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2401 params.page_id,
2402 params.pending_history_list_offset,
2403 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482404 navigation_state->set_transferred_request_child_id(
2405 params.transferred_request_child_id);
2406 navigation_state->set_transferred_request_request_id(
2407 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072408 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2409 // We're doing a load of a page that was restored from the last session.
2410 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2411 // which can result in stale data for pages that are set to expire. We
2412 // explicitly override that by setting the policy here so that as
2413 // necessary we load from the network.
2414 document_state->set_cache_policy_override(
2415 WebURLRequest::UseProtocolCachePolicy);
2416 }
2417 document_state->set_navigation_state(navigation_state);
2418 } else {
2419 document_state->set_navigation_state(
2420 NavigationState::CreateContentInitiated());
2421 }
2422
2423 if (IsReload(params))
2424 document_state->set_load_type(DocumentState::RELOAD);
2425 else if (!params.state.empty())
2426 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2427 else
2428 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2429
2430 pending_navigation_params_.reset();
2431}
2432
[email protected]310ebd6302011-10-10 19:06:282433void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172434 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072435 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172436
[email protected]3d9689372009-09-10 04:29:172437 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072438 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172439 double event_time = ds->triggeringEventTime();
2440 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072441 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172442 }
2443
[email protected]05c8e502010-08-15 15:13:522444 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072445 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522446
[email protected]3d9689372009-09-10 04:29:172447 bool is_top_most = !frame->parent();
2448 if (is_top_most) {
2449 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132450 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172451
2452 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152453 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172454 } else if (frame->parent()->isLoading()) {
2455 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002456 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072457 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582458 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172459 }
2460
[email protected]28685da92011-02-07 21:49:172461 FOR_EACH_OBSERVER(
2462 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2463
[email protected]3d9689372009-09-10 04:29:172464 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592465 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262466 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172467}
2468
[email protected]310ebd6302011-10-10 19:06:282469void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2470 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172471 if (frame->parent())
2472 return;
2473 // Received a redirect on the main frame.
2474 WebDataSource* data_source = frame->provisionalDataSource();
2475 if (!data_source) {
2476 // Should only be invoked when we have a data source.
2477 NOTREACHED();
2478 return;
2479 }
2480 std::vector<GURL> redirects;
2481 GetRedirectChain(data_source, &redirects);
2482 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512483 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592484 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172485 }
2486}
2487
[email protected]310ebd6302011-10-10 19:06:282488void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2489 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172490 // Notify the browser that we failed a provisional load with an error.
2491 //
2492 // Note: It is important this notification occur before DidStopLoading so the
2493 // SSL manager can react to the provisional load failure before being
2494 // notified the load stopped.
2495 //
2496 WebDataSource* ds = frame->provisionalDataSource();
2497 DCHECK(ds);
2498
2499 const WebURLRequest& failed_request = ds->request();
2500
[email protected]28685da92011-02-07 21:49:172501 FOR_EACH_OBSERVER(
2502 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2503
[email protected]3d9689372009-09-10 04:29:172504 bool show_repost_interstitial =
2505 (error.reason == net::ERR_CACHE_MISS &&
2506 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582507
2508 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2509 params.frame_id = frame->identifier();
2510 params.is_main_frame = !frame->parent();
2511 params.error_code = error.reason;
2512 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2513 failed_request,
2514 error,
2515 NULL,
2516 &params.error_description);
2517 params.url = error.unreachableURL;
2518 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172519 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582520 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172521
2522 // Don't display an error page if this is simply a cancelled load. Aside
2523 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2524 if (error.reason == net::ERR_ABORTED)
2525 return;
[email protected]b553edd52012-01-10 12:15:232526 // Don't display an error message if the request was handled by an
2527 // external protocol handler.
2528 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2529 return;
[email protected]3d9689372009-09-10 04:29:172530
2531 // Make sure we never show errors in view source mode.
2532 frame->enableViewSourceMode(false);
2533
[email protected]007733c2011-11-17 00:34:072534 DocumentState* document_state = DocumentState::FromDataSource(ds);
2535 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172536
2537 // If this is a failed back/forward/reload navigation, then we need to do a
2538 // 'replace' load. This is necessary to avoid messing up session history.
2539 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2540 // as session history is concerned.
2541 //
2542 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2543 // the page id.
2544 //
2545 bool replace =
2546 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582547 navigation_state->transition_type() ==
2548 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172549
2550 // If we failed on a browser initiated request, then make sure that our error
2551 // page load is regarded as the same browser initiated request.
2552 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072553 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2554 pending_navigation_params_->page_id =
2555 navigation_state->pending_page_id();
2556 pending_navigation_params_->pending_history_list_offset =
2557 navigation_state->pending_history_list_offset();
2558 pending_navigation_params_->transition =
2559 navigation_state->transition_type();
2560 pending_navigation_params_->request_time =
2561 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172562 }
2563
2564 // Provide the user with a more helpful error page?
2565 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2566 return;
2567
2568 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082569 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172570}
2571
[email protected]310ebd6302011-10-10 19:06:282572void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172573 WebFrame* frame, const char* data, size_t data_len,
2574 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072575 DocumentState* document_state =
2576 DocumentState::FromDataSource(frame->dataSource());
2577 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172578}
2579
[email protected]310ebd6302011-10-10 19:06:282580void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2581 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072582 DocumentState* document_state =
2583 DocumentState::FromDataSource(frame->dataSource());
2584 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172585
[email protected]007733c2011-11-17 00:34:072586 if (document_state->commit_load_time().is_null())
2587 document_state->set_commit_load_time(Time::Now());
2588
[email protected]3d9689372009-09-10 04:29:172589 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202590 // When we perform a new navigation, we need to update the last committed
2591 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172592 UpdateSessionHistory(frame);
2593
2594 // We bump our Page ID to correspond with the new session history entry.
2595 page_id_ = next_page_id_++;
2596
[email protected]3cc72b12010-03-18 23:03:002597 // Advance our offset in session history, applying the length limit. There
2598 // is now no forward history.
2599 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102600 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2601 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002602 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032603 history_page_ids_.resize(history_list_length_, -1);
2604 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172605 } else {
2606 // Inspect the navigation_state on this frame to see if the navigation
2607 // corresponds to a session history navigation... Note: |frame| may or
2608 // may not be the toplevel frame, but for the case of capturing session
2609 // history, the first committed frame suffices. We keep track of whether
2610 // we've seen this commit before so that only capture session history once
2611 // per navigation.
2612 //
2613 // Note that we need to check if the page ID changed. In the case of a
2614 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2615 // previous URL and the current page ID, which would be wrong.
2616 if (navigation_state->pending_page_id() != -1 &&
2617 navigation_state->pending_page_id() != page_id_ &&
2618 !navigation_state->request_committed()) {
2619 // This is a successful session history navigation!
2620 UpdateSessionHistory(frame);
2621 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002622
2623 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032624
2625 // If the history list is valid, our list of page IDs should be correct.
2626 DCHECK(history_list_length_ <= 0 ||
2627 history_list_offset_ < 0 ||
2628 history_list_offset_ >= history_list_length_ ||
2629 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172630 }
2631 }
2632
[email protected]28685da92011-02-07 21:49:172633 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2634 DidCommitProvisionalLoad(frame, is_new_navigation));
2635
[email protected]3d9689372009-09-10 04:29:172636 // Remember that we've already processed this request, so we don't update
2637 // the session history again. We do this regardless of whether this is
2638 // a session history navigation, because if we attempted a session history
2639 // navigation without valid HistoryItem state, WebCore will think it is a
2640 // new navigation.
2641 navigation_state->set_request_committed(true);
2642
2643 UpdateURL(frame);
2644
2645 // If this committed load was initiated by a client redirect, we're
2646 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152647 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172648
2649 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272650 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172651}
2652
[email protected]310ebd6302011-10-10 19:06:282653void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102654 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2655 DidClearWindowObject(frame));
2656
[email protected]b6cb3a842011-06-24 18:28:412657 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212658 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252659 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2660 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272661 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172662 }
[email protected]3d9689372009-09-10 04:29:172663}
2664
[email protected]310ebd6302011-10-10 19:06:282665void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172666 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412667 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252668 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272669 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172670 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2671 }
[email protected]e48869a2011-04-01 19:56:032672
2673 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2674 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172675}
2676
[email protected]310ebd6302011-10-10 19:06:282677void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2678 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462679 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172680
2681 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272682 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172683}
2684
[email protected]310ebd6302011-10-10 19:06:282685void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132686 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2687 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582688}
2689
[email protected]310ebd6302011-10-10 19:06:282690void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172691 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072692 DocumentState* document_state = DocumentState::FromDataSource(ds);
2693 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172694
[email protected]622474d2010-11-04 09:21:082695 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172696
[email protected]28685da92011-02-07 21:49:172697 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2698 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172699
2700 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272701 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172702}
2703
[email protected]310ebd6302011-10-10 19:06:282704void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082705 if (webview()->mainFrame() == frame) {
2706 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2707 page_id_));
2708 }
[email protected]3d9689372009-09-10 04:29:172709}
2710
[email protected]310ebd6302011-10-10 19:06:282711void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312712 WebDataSource* ds = frame->dataSource();
2713 DCHECK(ds);
2714
2715
[email protected]28685da92011-02-07 21:49:172716 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312717
2718 const WebURLRequest& failed_request = ds->request();
2719 string16 error_description;
2720 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2721 failed_request,
2722 error,
2723 NULL,
2724 &error_description);
2725 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2726 frame->identifier(),
2727 failed_request.url(),
2728 !frame->parent(),
2729 error.reason,
2730 error_description));
[email protected]3d9689372009-09-10 04:29:172731}
2732
[email protected]310ebd6302011-10-10 19:06:282733void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172734 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072735 DocumentState* document_state = DocumentState::FromDataSource(ds);
2736 if (document_state->finish_load_time().is_null())
2737 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412738
[email protected]676126f72011-01-15 00:03:512739 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172740
[email protected]1a55c5be2011-11-29 11:36:312741 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2742 frame->identifier(),
2743 ds->request().url(),
2744 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172745}
2746
[email protected]310ebd6302011-10-10 19:06:282747void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172748 WebFrame* frame, bool is_new_navigation) {
2749 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072750 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172751 // update the ExtraData on the datasource so that others who read the
2752 // ExtraData will get the new NavigationState. Similarly, if we did not
2753 // initiate this navigation, then we need to take care to reset any pre-
2754 // existing navigation state to a content-initiated navigation state.
2755 // DidCreateDataSource conveniently takes care of this for us.
2756 didCreateDataSource(frame, frame->dataSource());
2757
[email protected]007733c2011-11-17 00:34:072758 DocumentState* document_state =
2759 DocumentState::FromDataSource(frame->dataSource());
2760 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092761 new_state->set_was_within_same_page(true);
2762
[email protected]3d9689372009-09-10 04:29:172763 didCommitProvisionalLoad(frame, is_new_navigation);
2764
[email protected]750fcf872011-08-03 23:10:472765 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2766 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172767}
2768
[email protected]310ebd6302011-10-10 19:06:282769void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312770 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592771}
2772
[email protected]310ebd6302011-10-10 19:06:282773void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172774 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2775 // Ignore
2776}
2777
[email protected]310ebd6302011-10-10 19:06:282778void RenderViewImpl::willSendRequest(WebFrame* frame,
2779 unsigned identifier,
2780 WebURLRequest& request,
2781 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302782 WebFrame* top_frame = frame->top();
2783 if (!top_frame)
2784 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512785 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2786 WebDataSource* top_data_source = top_frame->dataSource();
2787 WebDataSource* data_source =
2788 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222789
[email protected]78d5cfe2011-02-04 08:43:222790 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032791 GURL new_url;
2792 if (content::GetContentClient()->renderer()->WillSendRequest(
2793 frame, request_url, &new_url)) {
2794 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222795 }
2796
[email protected]2905f742011-10-13 03:51:582797 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072798 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2799 NavigationState* navigation_state = document_state->navigation_state();
2800 if (document_state) {
2801 if (document_state->is_cache_policy_override_set())
2802 request.setCachePolicy(document_state->cache_policy_override());
2803 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:302804 }
[email protected]8a3125a712010-08-09 18:58:512805
[email protected]91043a8232011-11-04 16:41:192806 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:062807 new RequestExtraData(frame->referrerPolicy(),
2808 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:192809 frame->identifier(),
2810 frame->parent() == top_frame,
2811 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:482812 transition_type,
2813 navigation_state->transferred_request_child_id(),
2814 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:572815
[email protected]007733c2011-11-17 00:34:072816 DocumentState* top_document_state =
2817 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:572818 // TODO(gavinp): separate out prefetching and prerender field trials
2819 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:072820 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:572821 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2822 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:072823 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512824
[email protected]3d9689372009-09-10 04:29:172825 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132826 request.setHasUserGesture(frame->isProcessingUserGesture());
2827
[email protected]0a8db0d2011-04-13 15:15:402828 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132829 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172830}
2831
[email protected]310ebd6302011-10-10 19:06:282832void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:172833 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492834
[email protected]3d9689372009-09-10 04:29:172835 // Only do this for responses that correspond to a provisional data source
2836 // of the top-most frame. If we have a provisional data source, then we
2837 // can't have any sub-resources yet, so we know that this response must
2838 // correspond to a frame load.
2839 if (!frame->provisionalDataSource() || frame->parent())
2840 return;
2841
2842 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082843 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172844 if (frame->isViewSourceModeEnabled())
2845 return;
2846
[email protected]007733c2011-11-17 00:34:072847 DocumentState* document_state =
2848 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:082849 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532850
[email protected]972ebdff2010-06-10 22:59:072851 // Record page load flags.
[email protected]007733c2011-11-17 00:34:072852 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2853 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
2854 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:572855 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:072856 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
2857 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092858 // Whether or not the http status code actually corresponds to an error is
2859 // only checked when the page is done loading, if |use_error_page| is
2860 // still true.
[email protected]007733c2011-11-17 00:34:072861 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172862}
2863
[email protected]310ebd6302011-10-10 19:06:282864void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:172865 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:072866 DocumentState* document_state =
2867 DocumentState::FromDataSource(frame->dataSource());
2868 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172869 return;
2870
[email protected]7bfc153f2011-09-23 22:00:202871 // Do not show error page when DevTools is attached.
2872 if (devtools_agent_->IsAttached())
2873 return;
2874
[email protected]06333afe2011-02-24 14:55:092875 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:072876 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:082877 if (http_status_code == 404) {
2878 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412879 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172880
[email protected]b6cb3a842011-06-24 18:28:412881 const GURL& error_page_url =
2882 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092883 if (error_page_url.is_valid()) {
2884 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472885 original_error.domain = "http";
2886 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412887 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172888
[email protected]007733c2011-11-17 00:34:072889 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:092890 new AltErrorPageResourceFetcher(
2891 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:082892 base::Bind(&RenderViewImpl::AltErrorPageFinished,
2893 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:092894 return;
2895 }
2896 }
[email protected]3d9689372009-09-10 04:29:172897
[email protected]e6a2ce52011-10-08 01:40:132898 std::string error_domain;
2899 if (content::GetContentClient()->renderer()->HasErrorPage(
2900 http_status_code, &error_domain)) {
2901 WebURLError error;
2902 error.unreachableURL = frame->document().url();
2903 error.domain = WebString::fromUTF8(error_domain);
2904 error.reason = http_status_code;
2905
2906 LoadNavigationErrorPage(
2907 frame, frame->dataSource()->request(), error, std::string(), true);
2908 }
[email protected]3d9689372009-09-10 04:29:172909}
2910
[email protected]310ebd6302011-10-10 19:06:282911void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:172912 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2913 // Ignore
2914}
2915
[email protected]310ebd6302011-10-10 19:06:282916void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:172917 WebFrame* frame, const WebURLRequest& request,
2918 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:002919 // The recipients of this message have no use for data: URLs: they don't
2920 // affect the page's insecure content list and are not in the disk cache. To
2921 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
2922 // filter them out here.
2923 GURL url(request.url());
2924 if (url.SchemeIs("data"))
2925 return;
2926
[email protected]3d9689372009-09-10 04:29:172927 // Let the browser know we loaded a resource from the memory cache. This
2928 // message is needed to display the correct SSL indicators.
2929 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2930 routing_id_,
[email protected]84703292011-10-28 20:44:002931 url,
[email protected]70435962011-08-02 20:13:282932 response.securityInfo(),
2933 request.httpMethod().utf8(),
2934 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172935}
2936
[email protected]310ebd6302011-10-10 19:06:282937void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292938 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2939}
2940
[email protected]310ebd6302011-10-10 19:06:282941void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:022942 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292943 Send(new ViewHostMsg_DidRunInsecureContent(
2944 routing_id_,
[email protected]92771112011-01-20 00:13:022945 origin.toString().utf8(),
2946 target));
[email protected]e3d60e5d2009-09-25 21:08:292947}
2948
[email protected]310ebd6302011-10-10 19:06:282949void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:032950 webkit_glue::WebURLLoaderImpl* loader_impl =
2951 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2952 loader_impl->UpdateRoutingId(routing_id_);
2953}
2954
[email protected]310ebd6302011-10-10 19:06:282955void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172956 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2957}
2958
[email protected]310ebd6302011-10-10 19:06:282959void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
2960 v8::Handle<v8::Context> context,
2961 int world_id) {
[email protected]5bc10932011-09-21 21:03:302962 content::GetContentClient()->renderer()->DidCreateScriptContext(
2963 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282964}
2965
[email protected]310ebd6302011-10-10 19:06:282966void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
2967 v8::Handle<v8::Context> context,
2968 int world_id) {
[email protected]5bc10932011-09-21 21:03:302969 content::GetContentClient()->renderer()->WillReleaseScriptContext(
2970 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282971}
2972
[email protected]310ebd6302011-10-10 19:06:282973void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:072974 // We don't always want to send the change messages over IPC, only if we've
2975 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2976 // message.
2977 if (!send_preferred_size_changes_ || !webview())
2978 return;
2979
[email protected]705243f2010-05-05 19:58:072980 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2981 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532982
2983 // In the presence of zoom, these sizes are still reported as if unzoomed,
2984 // so we need to adjust.
2985 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2986 size.set_width(static_cast<int>(size.width() * zoom_factor));
2987 size.set_height(static_cast<int>(size.height() * zoom_factor));
2988
[email protected]6b5576cb2011-12-05 08:23:002989 if (!size.height())
2990 size.set_height(preferred_size_.height());
2991
[email protected]705243f2010-05-05 19:58:072992 if (size == preferred_size_)
2993 return;
[email protected]c27324b2009-11-19 22:44:292994
[email protected]705243f2010-05-05 19:58:072995 preferred_size_ = size;
2996 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2997 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172998}
2999
[email protected]273558fb2012-01-12 15:03:513000void RenderViewImpl::EnsureMediaStreamImpl() {
3001#if defined(ENABLE_P2P_APIS)
3002 if (!p2p_socket_dispatcher_)
3003 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3004#endif
3005
3006 if (!media_stream_dispatcher_)
3007 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3008
3009 if (!media_stream_impl_.get()) {
3010 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3011 media_stream_impl_ = new MediaStreamImpl(
3012 media_stream_dispatcher_,
3013 p2p_socket_dispatcher_,
3014 RenderThreadImpl::current()->video_capture_impl_manager(),
3015 factory);
3016 }
3017}
3018
[email protected]310ebd6302011-10-10 19:06:283019void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3020 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313021 if (webview()->mainFrame() != frame)
3022 return;
3023 WebView* frameView = frame->view();
3024 if (!frameView)
3025 return;
3026
3027 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3028 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3029
3030 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3031 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3032 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3033 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3034
3035 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3036 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3037 }
3038}
3039
[email protected]310ebd6302011-10-10 19:06:283040void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313041 WebSize offset = frame->scrollOffset();
3042 WebSize minimum_offset = frame->minimumScrollOffset();
3043 WebSize maximum_offset = frame->maximumScrollOffset();
3044
3045 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3046 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3047
3048 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3049 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3050 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3051 routing_id_, is_pinned_to_left, is_pinned_to_right));
3052
3053 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3054 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3055 }
3056}
3057
[email protected]310ebd6302011-10-10 19:06:283058void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493059 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313060
3061 if (webview()->mainFrame() == frame)
3062 UpdateScrollState(frame);
3063}
3064
[email protected]310ebd6302011-10-10 19:06:283065void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313066 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493067}
3068
[email protected]310ebd6302011-10-10 19:06:283069void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3070 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113071 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3072 if (!count)
3073 active_match_ordinal = 0;
3074
3075 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3076 routing_id_,
3077 request_id,
3078 count,
3079 gfx::Rect(),
3080 active_match_ordinal,
3081 final_update);
3082
[email protected]8922e1f2009-10-03 05:01:263083 // If we have a message that has been queued up, then we should just replace
3084 // it. The ACK from the browser will make sure it gets sent when the browser
3085 // wants it.
3086 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263087 queued_find_reply_message_.reset(msg);
3088 } else {
3089 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113090 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263091 }
3092}
3093
[email protected]310ebd6302011-10-10 19:06:283094void RenderViewImpl::reportFindInPageSelection(int request_id,
3095 int active_match_ordinal,
3096 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263097 // Send the search result over to the browser process.
3098 Send(new ViewHostMsg_Find_Reply(routing_id_,
3099 request_id,
3100 -1,
3101 selection_rect,
3102 active_match_ordinal,
3103 false));
3104}
3105
[email protected]310ebd6302011-10-10 19:06:283106void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223107 WebFrame* frame,
3108 WebFileSystem::Type type,
3109 long long size,
[email protected]d275d7a2010-11-03 01:34:493110 bool create,
[email protected]2b06a992010-08-21 05:48:223111 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083112 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223113
[email protected]b6cb3a842011-06-24 18:28:413114 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563115 if (origin.isUnique()) {
3116 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083117 callbacks->didFail(WebKit::WebFileErrorAbort);
3118 return;
3119 }
[email protected]2b06a992010-08-21 05:48:223120
[email protected]c5a272d2010-09-27 18:37:083121 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3122 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493123 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223124}
3125
[email protected]310ebd6302011-10-10 19:06:283126void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403127 WebFrame* frame,
3128 WebStorageQuotaType type,
3129 WebStorageQuotaCallbacks* callbacks) {
3130 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413131 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563132 if (origin.isUnique()) {
3133 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403134 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3135 return;
3136 }
3137 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533138 GURL(origin.toString()),
3139 static_cast<quota::StorageType>(type),
3140 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403141}
3142
[email protected]310ebd6302011-10-10 19:06:283143void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403144 WebFrame* frame,
3145 WebStorageQuotaType type,
3146 unsigned long long requested_size,
3147 WebStorageQuotaCallbacks* callbacks) {
3148 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413149 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563150 if (origin.isUnique()) {
3151 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403152 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3153 return;
3154 }
3155 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533156 routing_id(), GURL(origin.toString()),
3157 static_cast<quota::StorageType>(type), requested_size,
3158 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403159}
3160
[email protected]8b5af492011-11-28 21:50:583161void RenderViewImpl::registerIntentService(
3162 WebKit::WebFrame* frame, const WebKit::WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063163 string16 title = service.title();
3164 if (title.empty())
3165 title = webview()->mainFrame()->document().title();
3166
[email protected]8b5af492011-11-28 21:50:583167 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3168 service.action(),
3169 service.type(),
3170 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063171 title,
[email protected]8b5af492011-11-28 21:50:583172 service.disposition()));
3173}
3174
3175void RenderViewImpl::dispatchIntent(WebKit::WebFrame* frame,
[email protected]592e20b2012-01-20 05:53:443176 const WebKit::WebIntentRequest& request) {
3177 WebKit::WebIntent intent(request.intent());
[email protected]678105012011-12-09 04:01:213178 webkit_glue::WebIntentData intent_data(intent);
[email protected]8b5af492011-11-28 21:50:583179 Send(new IntentsHostMsg_WebIntentDispatch(
3180 routing_id_, intent_data, intent.identifier()));
3181}
3182
[email protected]18d5be92011-07-25 18:00:193183// WebKit::WebPageSerializerClient implementation ------------------------------
3184
[email protected]310ebd6302011-10-10 19:06:283185void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193186 const WebURL& frame_url,
3187 const WebCString& data,
3188 WebPageSerializerClient::PageSerializationStatus status) {
3189 Send(new ViewHostMsg_SendSerializedHtmlData(
3190 routing_id(),
3191 frame_url,
3192 data.data(),
3193 static_cast<int32>(status)));
3194}
3195
[email protected]a2ef54c2011-10-10 16:20:313196// content::RenderView implementation ------------------------------------------
3197
[email protected]310ebd6302011-10-10 19:06:283198bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313199 return RenderWidget::Send(message);
3200}
3201
[email protected]310ebd6302011-10-10 19:06:283202int RenderViewImpl::GetRoutingId() const {
[email protected]a2ef54c2011-10-10 16:20:313203 return routing_id_;
3204}
3205
[email protected]310ebd6302011-10-10 19:06:283206int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313207 return page_id_;
3208}
3209
[email protected]310ebd6302011-10-10 19:06:283210gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313211 return size();
3212}
3213
[email protected]310ebd6302011-10-10 19:06:283214gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313215 return host_window();
3216}
3217
[email protected]310ebd6302011-10-10 19:06:283218WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313219 return webkit_preferences_;
3220}
3221
[email protected]310ebd6302011-10-10 19:06:283222WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313223 return webview();
3224}
3225
[email protected]310ebd6302011-10-10 19:06:283226WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313227 if (!webview())
3228 return WebNode();
3229 WebFrame* focused_frame = webview()->focusedFrame();
3230 if (focused_frame) {
3231 WebDocument doc = focused_frame->document();
3232 if (!doc.isNull())
3233 return doc.focusedNode();
3234 }
3235
3236 return WebNode();
3237}
3238
[email protected]310ebd6302011-10-10 19:06:283239WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313240 return context_menu_node_;
3241}
3242
[email protected]310ebd6302011-10-10 19:06:283243bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313244 bool is_editable_node = false;
3245 if (!node.isNull()) {
3246 if (node.isContentEditable()) {
3247 is_editable_node = true;
3248 } else if (node.isElementNode()) {
3249 is_editable_node =
3250 node.toConst<WebElement>().isTextFormControlElement();
3251 }
3252 }
3253 return is_editable_node;
3254}
3255
[email protected]310ebd6302011-10-10 19:06:283256WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313257 WebKit::WebFrame* frame,
3258 const webkit::WebPluginInfo& info,
3259 const WebKit::WebPluginParams& params) {
3260 bool pepper_plugin_was_registered = false;
3261 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3262 pepper_delegate_.CreatePepperPluginModule(info,
3263 &pepper_plugin_was_registered));
3264 if (pepper_plugin_was_registered) {
3265 if (!pepper_module)
3266 return NULL;
3267 return new webkit::ppapi::WebPluginImpl(
3268 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3269 }
3270
3271 return new webkit::npapi::WebPluginImpl(
3272 frame, params, info.path, AsWeakPtr());
3273}
3274
[email protected]310ebd6302011-10-10 19:06:283275void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3276 const string16& jscript,
3277 int id,
3278 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313279 v8::Handle<v8::Value> result;
3280 WebFrame* web_frame = GetChildFrame(frame_xpath);
3281 if (web_frame)
3282 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3283 if (notify_result) {
3284 ListValue list;
3285 if (!result.IsEmpty() && web_frame) {
3286 v8::HandleScope handle_scope;
3287 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3288 v8::Context::Scope context_scope(context);
3289 V8ValueConverterImpl converter;
3290 converter.set_allow_date(true);
3291 converter.set_allow_regexp(true);
3292 list.Set(0, converter.FromV8Value(result, context));
3293 } else {
3294 list.Set(0, Value::CreateNullValue());
3295 }
3296 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3297 }
3298}
3299
[email protected]310ebd6302011-10-10 19:06:283300bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313301 return (!send_preferred_size_changes_ ||
3302 (disable_scrollbars_size_limit_.width() <= width ||
3303 disable_scrollbars_size_limit_.height() <= height));
3304}
3305
[email protected]310ebd6302011-10-10 19:06:283306int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313307 return enabled_bindings_;
3308}
3309
[email protected]310ebd6302011-10-10 19:06:283310void RenderViewImpl::SetEnabledBindings(int enabled_bindings) {
[email protected]a2ef54c2011-10-10 16:20:313311 enabled_bindings_ = enabled_bindings;
3312}
3313
[email protected]310ebd6302011-10-10 19:06:283314bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313315 return send_content_state_immediately_;
3316}
3317
[email protected]310ebd6302011-10-10 19:06:283318float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313319 return filtered_time_per_frame();
3320}
3321
[email protected]310ebd6302011-10-10 19:06:283322void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3323 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313324 showContextMenu(frame, data);
3325}
3326
[email protected]310ebd6302011-10-10 19:06:283327WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313328 return visibilityState();
3329}
3330
[email protected]310ebd6302011-10-10 19:06:283331void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3332 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313333 return runModalAlertDialog(frame, message);
3334}
3335
[email protected]310ebd6302011-10-10 19:06:283336void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313337 WebKit::WebFrame* frame,
3338 const WebKit::WebURLRequest& request,
3339 WebKit::WebNavigationPolicy policy) {
3340 loadURLExternally(frame, request, policy);
3341}
3342
3343// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513344
[email protected]310ebd6302011-10-10 19:06:283345webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533346 const FilePath& file_path,
3347 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593348 if (!PluginChannelHost::IsListening())
3349 return NULL;
3350
[email protected]00c39612010-03-06 02:53:283351 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463352 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323353#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223354 return webkit::npapi::WebPluginDelegateImpl::Create(
3355 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093356#else
[email protected]7398dcc2011-09-06 21:40:323357 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223358 NOTIMPLEMENTED();
3359 return NULL;
[email protected]7b6616f2010-01-14 18:07:553360#endif
[email protected]f103ab72009-09-02 17:10:593361 }
3362
[email protected]4e0616e2010-05-28 14:55:533363 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593364}
3365
[email protected]310ebd6302011-10-10 19:06:283366void RenderViewImpl::CreatedPluginWindow(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_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593369#endif
3370}
3371
[email protected]310ebd6302011-10-10 19:06:283372void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033373#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273374 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593375#endif
3376 CleanupWindowInPluginMoves(window);
3377}
3378
[email protected]310ebd6302011-10-10 19:06:283379void RenderViewImpl::DidMovePlugin(
3380 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593381 SchedulePluginMove(move);
3382}
3383
[email protected]310ebd6302011-10-10 19:06:283384void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593385 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523386 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593387}
3388
[email protected]310ebd6302011-10-10 19:06:283389void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593390 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523391 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593392}
3393
[email protected]310ebd6302011-10-10 19:06:283394WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513395 return &cookie_jar_;
3396}
3397
[email protected]a9288f52011-11-17 05:18:163398void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073399 Send(new ViewHostMsg_MediaNotification(routing_id_,
3400 reinterpret_cast<int64>(player),
3401 player->hasVideo(),
3402 player->hasAudio(),
3403 true));
3404}
3405
[email protected]a9288f52011-11-17 05:18:163406void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073407 Send(new ViewHostMsg_MediaNotification(routing_id_,
3408 reinterpret_cast<int64>(player),
3409 player->hasVideo(),
3410 player->hasAudio(),
3411 false));
3412}
3413
[email protected]a9288f52011-11-17 05:18:163414void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073415 DidPause(player);
3416}
3417
[email protected]310ebd6302011-10-10 19:06:283418void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293419 if (!webview())
3420 return;
3421
[email protected]26aa0482009-09-30 16:55:273422 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173423 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293424 return;
[email protected]ca948a22009-06-25 19:36:173425
3426 Send(new ViewHostMsg_UpdateState(
3427 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293428}
3429
[email protected]310ebd6302011-10-10 19:06:283430void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363431 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003432 if (!frame)
3433 return;
[email protected]b781ff282011-08-20 06:19:363434
[email protected]b781ff282011-08-20 06:19:363435 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003436 if (!webview()->caretOrSelectionRange(&location, &length))
3437 return;
3438
3439 string16 text;
3440 size_t offset;
3441 ui::Range range(location, location + length);
3442
3443 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3444 // If current focused element is editable, we will send 100 more chars
3445 // before and after selection. It is for input method surrounding text
3446 // feature.
3447 if (location > kExtraCharsBeforeAndAfterSelection)
3448 offset = location - kExtraCharsBeforeAndAfterSelection;
3449 else
3450 offset = 0;
3451 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3452 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3453 if (!webrange.isNull())
3454 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3455 } else {
3456 offset = location;
3457 text = frame->selectionAsText();
[email protected]e8cdf3532011-10-29 00:50:523458 // http://crbug.com/101435
3459 // In some case, frame->selectionAsText() returned text's length is not
3460 // equal to the length returned from webview()->caretOrSelectionRange().
3461 // So we have to set the range according to text.length().
3462 range.set_end(range.start() + text.length());
[email protected]b781ff282011-08-20 06:19:363463 }
3464
[email protected]b781ff282011-08-20 06:19:363465 // Sometimes we get repeated didChangeSelection calls from webkit when
3466 // the selection hasn't actually changed. We don't want to report these
3467 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003468 if (selection_text_offset_ != offset ||
3469 selection_range_ != range ||
3470 selection_text_ != text) {
3471 selection_text_ = text;
3472 selection_text_offset_ = offset;
3473 selection_range_ = range;
3474 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3475 }
[email protected]b781ff282011-08-20 06:19:363476}
3477
[email protected]310ebd6302011-10-10 19:06:283478GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3479 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553480 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293481 // If the URL that failed was secure, then the embedding web page was not
3482 // expecting a network attacker to be able to manipulate its contents. As
3483 // we fetch alternate error pages over HTTP, we would be allowing a network
3484 // attacker to manipulate the contents of the response if we tried to use
3485 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153486 return GURL();
initial.commit09911bf2008-07-26 23:55:293487 }
3488
3489 // Grab the base URL from the browser process.
3490 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153491 return GURL();
initial.commit09911bf2008-07-26 23:55:293492
3493 // Strip query params from the failed URL.
3494 GURL::Replacements remove_params;
3495 remove_params.ClearUsername();
3496 remove_params.ClearPassword();
3497 remove_params.ClearQuery();
3498 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553499 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503500 std::string spec_to_send = url_to_send.spec();
3501 // Notify link doctor of the url truncation by sending of "?" at the end.
3502 if (failed_url.has_query())
3503 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293504
3505 // Construct the query params to send to link doctor.
3506 std::string params(alternate_error_page_url_.query());
3507 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023508 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293509 params.append("&sourceid=chrome");
3510 params.append("&error=");
3511 switch (error_type) {
3512 case DNS_ERROR:
3513 params.append("dnserror");
3514 break;
3515
3516 case HTTP_404:
3517 params.append("http404");
3518 break;
3519
[email protected]5df266ac2008-10-15 19:50:133520 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333521 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133522 break;
3523
initial.commit09911bf2008-07-26 23:55:293524 default:
3525 NOTREACHED() << "unknown ErrorPageType";
3526 }
3527
3528 // OK, build the final url to return.
3529 GURL::Replacements link_doctor_params;
3530 link_doctor_params.SetQueryStr(params);
3531 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3532 return url;
3533}
3534
[email protected]310ebd6302011-10-10 19:06:283535GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593536 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3537 return GURL();
3538 else
3539 return creator_url_;
3540}
3541
[email protected]310ebd6302011-10-10 19:06:283542WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273543 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313544 web_ui_bindings_.reset(new WebUIBindings(
3545 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463546 }
[email protected]c50008512011-02-03 01:17:273547 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463548}
3549
[email protected]310ebd6302011-10-10 19:06:283550WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013551 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493552}
3553
[email protected]310ebd6302011-10-10 19:06:283554void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3555 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273556 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493557
[email protected]872542532011-06-23 00:43:163558 // Check if the plugin still exists in the document.
3559 if (main_frame->document().isPluginDocument() &&
3560 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493561 if (options.findNext) {
3562 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013563 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493564 } else {
[email protected]afdbd142010-07-10 08:01:233565 if (GetWebPluginFromPluginDocument()->startFind(
3566 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493567 } else {
[email protected]e7c58a32010-08-13 19:47:113568 // Send "no results".
3569 Send(new ViewHostMsg_Find_Reply(routing_id_,
3570 request_id,
3571 0,
3572 gfx::Rect(),
3573 0,
3574 true));
[email protected]24a7f3c2010-03-25 08:26:493575 }
3576 }
3577 return;
3578 }
3579
[email protected]b4bb2502009-10-01 22:35:273580 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273581 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293582 WebFrame* search_frame = focused_frame; // start searching focused frame.
3583
3584 bool multi_frame = (frame_after_main != main_frame);
3585
3586 // If we have multiple frames, we don't want to wrap the search within the
3587 // frame, so we check here if we only have main_frame in the chain.
3588 bool wrap_within_frame = !multi_frame;
3589
[email protected]b3f2b912009-04-09 16:18:523590 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293591 bool result = false;
3592
[email protected]7830da3e2009-11-06 16:27:263593 // If something is selected when we start searching it means we cannot just
3594 // increment the current match ordinal; we need to re-generate it.
3595 WebRange current_selection = focused_frame->selectionRange();
3596
initial.commit09911bf2008-07-26 23:55:293597 do {
[email protected]dd7daa82009-08-10 05:46:453598 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593599 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293600
3601 if (!result) {
3602 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223603 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293604
3605 // Find the next frame, but skip the invisible ones.
3606 do {
3607 // What is the next frame to search? (we might be going backwards). Note
3608 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593609 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273610 search_frame->traverseNext(true) :
3611 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453612 } while (!search_frame->hasVisibleContent() &&
3613 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293614
[email protected]884db412008-11-24 23:46:503615 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223616 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293617
3618 // If we have multiple frames and we have wrapped back around to the
3619 // focused frame, we need to search it once more allowing wrap within
3620 // the frame, otherwise it will report 'no match' if the focused frame has
3621 // reported matches, but no frames after the focused_frame contain a
3622 // match for the search word(s).
3623 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453624 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593625 request_id, search_text, options, true, // Force wrapping.
3626 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293627 }
3628 }
3629
[email protected]26aa0482009-09-30 16:55:273630 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293631 } while (!result && search_frame != focused_frame);
3632
[email protected]7830da3e2009-11-06 16:27:263633 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293634 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453635 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293636 } else {
3637 // If nothing is found, set result to "0 of 0", otherwise, set it to
3638 // "-1 of 1" to indicate that we found at least one item, but we don't know
3639 // yet what is active.
3640 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3641 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293642
[email protected]4f3dc372009-02-24 00:10:293643 // If we find no matches then this will be our last status update.
3644 // Otherwise the scoping effort will send more results.
3645 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293646
[email protected]4f3dc372009-02-24 00:10:293647 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403648 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593649 request_id,
[email protected]4f3dc372009-02-24 00:10:293650 match_count,
3651 selection_rect,
3652 ordinal,
3653 final_status_update));
initial.commit09911bf2008-07-26 23:55:293654
initial.commit09911bf2008-07-26 23:55:293655 // Scoping effort begins, starting with the mainframe.
3656 search_frame = main_frame;
3657
[email protected]dd7daa82009-08-10 05:46:453658 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293659
3660 do {
3661 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453662 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293663
3664 // We don't start another scoping effort unless at least one match has
3665 // been found.
3666 if (result) {
3667 // Start new scoping request. If the scoping function determines that it
3668 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453669 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593670 search_text,
3671 options,
initial.commit09911bf2008-07-26 23:55:293672 true); // reset the tickmarks
3673 }
3674
3675 // Iterate to the next frame. The frame will not necessarily scope, for
3676 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273677 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293678 } while (search_frame != main_frame);
3679 }
3680}
3681
[email protected]815dd9872011-11-23 18:40:303682void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493683 WebView* view = webview();
3684 if (!view)
3685 return;
3686
3687 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163688 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013689 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493690 return;
3691 }
3692
[email protected]815dd9872011-11-23 18:40:303693 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493694 if (clear_selection)
3695 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3696
3697 WebFrame* frame = view->mainFrame();
3698 while (frame) {
3699 frame->stopFinding(clear_selection);
3700 frame = frame->traverseNext(false);
3701 }
3702
[email protected]815dd9872011-11-23 18:40:303703 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493704 WebFrame* focused_frame = view->focusedFrame();
3705 if (focused_frame) {
3706 WebDocument doc = focused_frame->document();
3707 if (!doc.isNull()) {
3708 WebNode node = doc.focusedNode();
3709 if (!node.isNull())
3710 node.simulateClick();
3711 }
3712 }
3713 }
3714}
3715
[email protected]310ebd6302011-10-10 19:06:283716void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493717 // Check if there is any queued up request waiting to be sent.
3718 if (queued_find_reply_message_.get()) {
3719 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423720 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493721 }
3722}
3723
[email protected]54087fe2011-10-28 22:02:483724void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513725 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3726 return;
3727
[email protected]258d31122010-05-09 10:59:413728 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103729
[email protected]b75b8292010-10-01 07:28:253730 double old_zoom_level = webview()->zoomLevel();
3731 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483732 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253733 zoom_level = 0;
3734 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3735 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483736 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253737 } else {
3738 // Either the user hit the zoom factor limit and thus the zoom level is now
3739 // not a whole number, or a plugin changed it to a custom value. We want
3740 // to go to the next whole number so that the user can always get back to
3741 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483742 if ((old_zoom_level > 1 && zoom > 0) ||
3743 (old_zoom_level < 1 && zoom < 0)) {
3744 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253745 } else {
3746 // We're going towards 100%, so first go to the next whole number.
3747 zoom_level = static_cast<int>(old_zoom_level);
3748 }
3749 }
[email protected]b75b8292010-10-01 07:28:253750 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413751 zoomLevelChanged();
3752}
3753
3754void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3755 int zoom_center_x, int zoom_center_y) {
3756 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3757 kScalingIncrementForGesture);
3758}
3759
3760void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3761 int zoom_center_x,
3762 int zoom_center_y,
3763 float scaling_increment) {
3764 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3765 return;
3766
[email protected]c514d6372011-08-16 22:54:443767 double old_page_scale_factor = webview()->pageScaleFactor();
3768 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:483769 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:443770 page_scale_factor = 1.0;
3771 } else {
3772 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:413773 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:443774 }
[email protected]47578fa02011-11-02 19:34:413775 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:093776 webview()->setPageScaleFactor(page_scale_factor,
3777 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:413778 }
[email protected]40bd6582009-12-04 23:49:513779}
3780
[email protected]310ebd6302011-10-10 19:06:283781void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173782 webview()->hidePopups();
3783 webview()->setZoomLevel(false, zoom_level);
3784 zoomLevelChanged();
3785}
3786
[email protected]310ebd6302011-10-10 19:06:283787void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3788 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543789 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293790}
3791
[email protected]310ebd6302011-10-10 19:06:283792void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273793 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293794}
3795
[email protected]310ebd6302011-10-10 19:06:283796void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273797 WebString no_encoding;
3798 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183799}
3800
[email protected]310ebd6302011-10-10 19:06:283801WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453802 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273803 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453804
3805 // xpath string can represent a frame deep down the tree (across multiple
3806 // frame DOMs).
3807 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3808 // should break into 2 xpaths
3809 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413810 std::vector<string16> xpaths;
3811 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453812
[email protected]26aa0482009-09-30 16:55:273813 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413814 for (std::vector<string16>::const_iterator i = xpaths.begin();
3815 frame && i != xpaths.end(); ++i) {
3816 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293817 }
3818
[email protected]dd7daa82009-08-10 05:46:453819 return frame;
initial.commit09911bf2008-07-26 23:55:293820}
3821
[email protected]310ebd6302011-10-10 19:06:283822void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
3823 const string16& jscript,
3824 int id,
3825 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:533826 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293827}
3828
[email protected]310ebd6302011-10-10 19:06:283829void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
3830 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413831 WebFrame* frame = GetChildFrame(frame_xpath);
3832 if (!frame)
[email protected]216813952011-05-19 22:21:263833 return;
[email protected]ae461542009-06-19 19:03:413834
[email protected]01cf589c2011-07-28 18:04:033835 frame->document().insertUserStyleSheet(
3836 WebString::fromUTF8(css),
3837 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483838}
3839
[email protected]310ebd6302011-10-10 19:06:283840void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:093841 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293842}
3843
[email protected]310ebd6302011-10-10 19:06:283844void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
3845 const std::string& value) {
[email protected]e091df82011-10-11 18:13:213846 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:273847 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293848}
3849
[email protected]310ebd6302011-10-10 19:06:283850void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
3851 const gfx::Point& client_point,
3852 const gfx::Point& screen_point,
3853 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553854 WebDragOperation operation = webview()->dragTargetDragEnter(
3855 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553856 client_point,
3857 screen_point,
3858 ops);
3859
3860 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3861}
3862
[email protected]310ebd6302011-10-10 19:06:283863void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
3864 const gfx::Point& screen_point,
3865 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553866 WebDragOperation operation = webview()->dragTargetDragOver(
3867 client_point,
3868 screen_point,
3869 ops);
3870
3871 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3872}
3873
[email protected]310ebd6302011-10-10 19:06:283874void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:553875 webview()->dragTargetDragLeave();
3876}
3877
[email protected]310ebd6302011-10-10 19:06:283878void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
3879 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:553880 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573881
3882 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553883}
3884
[email protected]310ebd6302011-10-10 19:06:283885void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3886 const gfx::Point& screen_point,
3887 bool ended,
3888 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033889 if (ended) {
[email protected]26aa0482009-09-30 16:55:273890 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203891 } else {
3892 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033893 }
initial.commit09911bf2008-07-26 23:55:293894}
3895
[email protected]310ebd6302011-10-10 19:06:283896void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273897 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293898}
3899
[email protected]310ebd6302011-10-10 19:06:283900void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593901 webkit_preferences_ = prefs;
3902 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293903}
3904
[email protected]310ebd6302011-10-10 19:06:283905void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:293906 alternate_error_page_url_ = url;
3907}
3908
[email protected]310ebd6302011-10-10 19:06:283909void RenderViewImpl::OnCustomContextMenuAction(
[email protected]b29aa74b2011-01-31 21:41:083910 const webkit_glue::CustomContextMenuContext& custom_context,
3911 unsigned action) {
3912 if (custom_context.is_pepper_menu)
3913 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3914 else
3915 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:583916 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3917 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:333918}
3919
[email protected]310ebd6302011-10-10 19:06:283920void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:513921 int id,
3922 const std::vector<FilePath>& paths) {
3923 if (!enumeration_completions_[id])
3924 return;
3925
3926 WebVector<WebString> ws_file_names(paths.size());
3927 for (size_t i = 0; i < paths.size(); ++i)
3928 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3929
3930 enumeration_completions_[id]->didChooseFile(ws_file_names);
3931 enumeration_completions_.erase(id);
3932}
3933
[email protected]310ebd6302011-10-10 19:06:283934void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363935 // This could happen if we navigated to a different page before the user
3936 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473937 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363938 return;
3939
[email protected]cdaf8d02010-03-30 19:52:473940 WebVector<WebString> ws_file_names(paths.size());
3941 for (size_t i = 0; i < paths.size(); ++i)
3942 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463943
[email protected]cdaf8d02010-03-30 19:52:473944 if (file_chooser_completions_.front()->completion)
3945 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3946 file_chooser_completions_.pop_front();
3947
3948 // If there are more pending file chooser requests, schedule one now.
3949 if (!file_chooser_completions_.empty()) {
3950 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3951 file_chooser_completions_.front()->params));
3952 }
initial.commit09911bf2008-07-26 23:55:293953}
3954
[email protected]244ac1892011-12-02 17:04:473955void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
3956 const gfx::Size& max_size) {
3957 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
3958 if (!webview())
3959 return;
3960 webview()->enableAutoResizeMode(true, min_size, max_size);
3961}
3962
[email protected]2bf834f2011-11-17 20:02:213963void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:243964 if (send_preferred_size_changes_)
3965 return;
[email protected]9fb325e2010-05-06 18:23:243966 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393967
[email protected]d812fd12011-05-27 23:05:073968 // Start off with an initial preferred size notification (in case
3969 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:593970 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:083971}
3972
[email protected]310ebd6302011-10-10 19:06:283973void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:103974 const gfx::Size& disable_scrollbar_size_limit) {
3975 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3976}
3977
[email protected]310ebd6302011-10-10 19:06:283978void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:313979 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:503980 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:513981 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373982 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133983#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413984 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3985 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463986 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513987 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343988 renderer_prefs.thumb_inactive_color,
3989 renderer_prefs.thumb_active_color,
3990 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323991
[email protected]644d77e2010-01-27 01:03:103992 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323993 webview()->setScrollbarColors(
3994 renderer_prefs.thumb_inactive_color,
3995 renderer_prefs.thumb_active_color,
3996 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103997 webview()->setSelectionColors(
3998 renderer_prefs.active_selection_bg_color,
3999 renderer_prefs.active_selection_fg_color,
4000 renderer_prefs.inactive_selection_bg_color,
4001 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464002 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104003 }
[email protected]7a74e102009-09-03 00:16:564004#endif
[email protected]d051d9a2011-12-10 02:02:504005 // If the zoom level for this page matches the old zoom default, and this
4006 // is not a plugin, update the zoom level to match the new default.
4007 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4008 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4009 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4010 zoomLevelChanged();
4011 }
[email protected]80d96fa2009-06-10 22:34:514012}
4013
[email protected]310ebd6302011-10-10 19:06:284014void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4015 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284016 if (webview())
4017 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564018}
4019
[email protected]81375e872012-01-11 21:40:364020void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4021 const WebPluginAction& action) {
4022 if (webview())
4023 webview()->performPluginAction(action, location);
4024}
4025
[email protected]310ebd6302011-10-10 19:06:284026void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194027 const GURL& page_url) {
4028 // Prepare list to storage all savable resource links.
4029 std::vector<GURL> resources_list;
4030 std::vector<GURL> referrers_list;
4031 std::vector<GURL> frames_list;
4032 webkit_glue::SavableResourcesResult result(&resources_list,
4033 &referrers_list,
4034 &frames_list);
4035
[email protected]445e1042011-12-03 21:03:154036 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4037 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194038 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4039 webview(),
4040 page_url,
4041 &result,
[email protected]2a80aee2011-10-07 16:06:034042 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194043 // If something is wrong when collecting all savable resource links,
4044 // send empty list to embedder(browser) to tell it failed.
4045 referrers_list.clear();
4046 resources_list.clear();
4047 frames_list.clear();
4048 }
4049
4050 // Send result of all savable resource links to embedder.
4051 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4052 resources_list,
4053 referrers_list,
4054 frames_list));
4055}
4056
[email protected]310ebd6302011-10-10 19:06:284057void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194058 const std::vector<GURL>& links,
4059 const std::vector<FilePath>& local_paths,
4060 const FilePath& local_directory_name) {
4061
4062 // Convert std::vector of GURLs to WebVector<WebURL>
4063 WebVector<WebURL> weburl_links(links);
4064
4065 // Convert std::vector of std::strings to WebVector<WebString>
4066 WebVector<WebString> webstring_paths(local_paths.size());
4067 for (size_t i = 0; i < local_paths.size(); i++)
4068 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4069
4070 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4071 webstring_paths,
4072 webkit_glue::FilePathToWebString(
4073 local_directory_name));
4074}
4075
[email protected]310ebd6302011-10-10 19:06:284076void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274077 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474078 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294079}
4080
[email protected]310ebd6302011-10-10 19:06:284081void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]992db4c2011-05-12 15:37:154082 if (is_swapped_out_)
4083 return;
4084
4085 // Swap this RenderView out so the tab can navigate to a page rendered by a
4086 // different process. This involves running the unload handler and clearing
4087 // the page. Once WasSwappedOut is called, we also allow this process to exit
4088 // if there are no other active RenderViews in it.
4089
4090 // Send an UpdateState message before we get swapped out.
4091 SyncNavigationState();
4092
4093 // Synchronously run the unload handler before sending the ACK.
4094 webview()->dispatchUnloadEvent();
4095
4096 // Swap out and stop sending any IPC messages that are not ACKs.
4097 SetSwappedOut(true);
4098
4099 // Replace the page with a blank dummy URL. The unload handler will not be
4100 // run a second time, thanks to a check in FrameLoader::stopLoading.
4101 // TODO(creis): Need to add a better way to do this that avoids running the
4102 // beforeunload handler. For now, we just run it a second time silently.
4103 webview()->mainFrame()->loadHTMLString(std::string(),
4104 GURL("about:swappedout"),
4105 GURL("about:swappedout"),
4106 false);
4107
4108 // Just echo back the params in the ACK.
4109 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4110}
4111
[email protected]310ebd6302011-10-10 19:06:284112void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374113 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294114 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4115 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4116 // in the onunload handler from appearing. For now, we're bypassing that and
4117 // calling the FrameLoader's CloseURL method directly. This should be
4118 // revisited to avoid having two ways to close a page. Having a single way
4119 // to close that can run onunload is also useful for fixing
4120 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274121 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294122
[email protected]992db4c2011-05-12 15:37:154123 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294124}
4125
[email protected]310ebd6302011-10-10 19:06:284126void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024127#if defined(USE_AURA)
4128 // Aura doesn't care if we switch themes.
4129#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164130 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464131 if (webview())
4132 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574133#else // defined(OS_WIN)
4134 // TODO(port): we don't support theming on non-Windows platforms yet
4135 NOTIMPLEMENTED();
4136#endif
initial.commit09911bf2008-07-26 23:55:294137}
4138
[email protected]310ebd6302011-10-10 19:06:284139void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084140 if (decrement_shared_popup_at_destruction_)
4141 shared_popup_counter_->data--;
4142 shared_popup_counter_ = new SharedRenderViewCounter(0);
4143 decrement_shared_popup_at_destruction_ = false;
4144}
4145
[email protected]310ebd6302011-10-10 19:06:284146bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4147 const WebURLError& error,
4148 bool replace) {
[email protected]15d79e12009-08-02 19:23:454149 // We only show alternate error pages in the main frame. They are
4150 // intended to assist the user when navigating, so there is not much
4151 // value in showing them for failed subframes. Ideally, we would be
4152 // able to use the TYPED transition type for this, but that flag is
4153 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454154 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454155 return false;
4156
4157 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374158 // connection failure.
[email protected]15d79e12009-08-02 19:23:454159 int ec = error.reason;
4160 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4161 ec != net::ERR_CONNECTION_FAILED &&
4162 ec != net::ERR_CONNECTION_REFUSED &&
4163 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374164 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454165 return false;
4166
4167 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554168 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454169 if (!error_page_url.is_valid())
4170 return false;
4171
4172 // Load an empty page first so there is an immediate response to the error,
4173 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454174 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364175 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454176 error.unreachableURL,
4177 replace);
4178
4179 // Now, create a fetcher for the error page and associate it with the data
4180 // source we just created via the LoadHTMLString call. That way if another
4181 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074182 DocumentState* document_state =
4183 DocumentState::FromDataSource(frame->provisionalDataSource());
4184 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454185 new AltErrorPageResourceFetcher(
4186 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084187 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4188 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454189 return true;
4190}
4191
[email protected]310ebd6302011-10-10 19:06:284192void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4193 const WebURLError& original_error,
4194 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454195 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094196 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554197 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094198 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454199}
4200
[email protected]310ebd6302011-10-10 19:06:284201void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004202 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474203 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004204}
4205
[email protected]310ebd6302011-10-10 19:06:284206void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094207 const gfx::Rect& resizer_rect,
4208 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104209 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474210 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104211 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204212 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314213 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104214 }
[email protected]dd6afca2011-08-13 03:44:314215 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104216 }
4217
[email protected]ee41e7d22011-10-14 19:34:094218 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004219}
[email protected]0aa477bd2009-03-23 22:21:434220
[email protected]310ebd6302011-10-10 19:06:284221void RenderViewImpl::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014222 // Notify the pepper plugins that we started painting.
4223 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284224}
4225
[email protected]310ebd6302011-10-10 19:06:284226void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284227 // Notify any pepper plugins that we painted. This will call into the plugin,
4228 // and we it may ask to close itself as a result. This will, in turn, modify
4229 // our set, possibly invalidating the iterator. So we iterate on a copy that
4230 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014231 pepper_delegate_.ViewFlushedPaint();
4232
[email protected]00c39612010-03-06 02:53:284233 WebFrame* main_frame = webview()->mainFrame();
4234
4235 // If we have a provisional frame we are between the start and commit stages
4236 // of loading and we don't want to save stats.
4237 if (!main_frame->provisionalDataSource()) {
4238 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074239 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284240
[email protected]05c8e502010-08-15 15:13:524241 // TODO(jar): The following code should all be inside a method, probably in
4242 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284243 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074244 if (document_state->first_paint_time().is_null()) {
4245 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284246 }
[email protected]007733c2011-11-17 00:34:074247 if (document_state->first_paint_after_load_time().is_null() &&
4248 !document_state->finish_load_time().is_null()) {
4249 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284250 }
4251 }
4252}
4253
[email protected]310ebd6302011-10-10 19:06:284254void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084255 RenderWidget::OnSwapBuffersPosted();
4256}
4257
[email protected]310ebd6302011-10-10 19:06:284258void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244259 RenderWidget::OnSwapBuffersComplete();
4260}
4261
[email protected]310ebd6302011-10-10 19:06:284262void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244263 RenderWidget::OnSwapBuffersAborted();
4264}
4265
[email protected]310ebd6302011-10-10 19:06:284266webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154267 const gfx::Rect& paint_bounds,
4268 TransportDIB** dib,
4269 gfx::Rect* location,
4270 gfx::Rect* clip) {
4271 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4272 paint_bounds, dib, location, clip);
4273}
4274
[email protected]310ebd6302011-10-10 19:06:284275gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074276 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434277 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524278}
4279
[email protected]310ebd6302011-10-10 19:06:284280void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164281 if (webview())
[email protected]26aa0482009-09-30 16:55:274282 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164283}
4284
[email protected]310ebd6302011-10-10 19:06:284285void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144286 if (webview())
[email protected]b4bb2502009-10-01 22:35:274287 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144288
4289 SetBackground(background);
4290}
4291
[email protected]310ebd6302011-10-10 19:06:284292void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344293 if (webview())
[email protected]b4bb2502009-10-01 22:35:274294 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264295
4296#if defined(OS_MACOSX)
4297 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4298 for (plugin_it = plugin_delegates_.begin();
4299 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4300 (*plugin_it)->SetWindowFocus(active);
4301 }
4302#endif
[email protected]8c66c5a2009-07-22 17:26:344303}
4304
[email protected]6ce7abc52010-02-02 18:40:144305#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284306void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144307 // Inform plugins that their container has changed visibility.
4308 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4309 for (plugin_it = plugin_delegates_.begin();
4310 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4311 (*plugin_it)->SetContainerVisibility(visible);
4312 }
4313}
[email protected]1e6e3c992010-02-08 15:52:134314
[email protected]310ebd6302011-10-10 19:06:284315void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4316 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134317 // Inform plugins that their window's frame has changed.
4318 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4319 for (plugin_it = plugin_delegates_.begin();
4320 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4321 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4322 }
4323}
[email protected]935d63d2010-10-15 23:31:554324
[email protected]310ebd6302011-10-10 19:06:284325void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4326 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134327 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554328 // applies to it or not, so inform all the delegates.
4329 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4330 for (plugin_it = plugin_delegates_.begin();
4331 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134332 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554333 }
4334}
[email protected]6ce7abc52010-02-02 18:40:144335#endif // OS_MACOSX
4336
[email protected]310ebd6302011-10-10 19:06:284337void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484338 const EditCommands& edit_commands) {
4339 edit_commands_ = edit_commands;
4340}
4341
[email protected]310ebd6302011-10-10 19:06:284342void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594343 // We need to grab a pointer to the doomed WebView before we destroy it.
4344 WebView* doomed = webview();
4345 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494346 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594347}
4348
[email protected]310ebd6302011-10-10 19:06:284349void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484350 edit_commands_.clear();
4351}
4352
[email protected]310ebd6302011-10-10 19:06:284353bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]b993705a2011-10-09 23:00:244354 return pepper_delegate_.HandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374355}
4356
[email protected]310ebd6302011-10-10 19:06:284357void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514358 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064359}
4360
[email protected]310ebd6302011-10-10 19:06:284361void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244362 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4363}
4364
[email protected]310ebd6302011-10-10 19:06:284365void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434366 RenderWidget::OnWasHidden();
4367
[email protected]a6939ca42011-02-18 17:58:074368 if (webview()) {
4369 webview()->settings()->setMinimumTimerInterval(
4370 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444371 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074372 }
4373
[email protected]204f1df2012-01-04 20:21:134374 // Inform PPAPI plugins that their page is no longer visible.
4375 pepper_delegate_.PageVisibilityChanged(false);
4376
[email protected]a6939ca42011-02-18 17:58:074377#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134378 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434379 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4380 for (plugin_it = plugin_delegates_.begin();
4381 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4382 (*plugin_it)->SetContainerVisibility(false);
4383 }
[email protected]a6939ca42011-02-18 17:58:074384#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434385}
4386
[email protected]310ebd6302011-10-10 19:06:284387void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434388 RenderWidget::OnWasRestored(needs_repainting);
4389
[email protected]a6939ca42011-02-18 17:58:074390 if (webview()) {
4391 webview()->settings()->setMinimumTimerInterval(
4392 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444393 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074394 }
4395
[email protected]204f1df2012-01-04 20:21:134396 // Inform PPAPI plugins that their page is visible.
4397 pepper_delegate_.PageVisibilityChanged(true);
4398
[email protected]a6939ca42011-02-18 17:58:074399#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134400 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434401 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4402 for (plugin_it = plugin_delegates_.begin();
4403 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4404 (*plugin_it)->SetContainerVisibility(true);
4405 }
[email protected]784ea1ab2010-09-18 00:02:344406#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074407}
[email protected]1e6e3c992010-02-08 15:52:134408
[email protected]310ebd6302011-10-10 19:06:284409bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384410 if (WebWidgetHandlesCompositorScheduling())
4411 return false;
4412
[email protected]65225772011-05-12 21:10:244413 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4414 if (!context)
4415 return false;
4416 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4417 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4418 std::string::npos;
4419}
4420
[email protected]310ebd6302011-10-10 19:06:284421void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134422 RenderWidget::OnSetFocus(enable);
4423
[email protected]7d3c02c2010-05-05 23:10:314424 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074425 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134426 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4427 for (plugin_it = plugin_delegates_.begin();
4428 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344429#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314430 // RenderWidget's call to setFocus can cause the underlying webview's
4431 // activation state to change just like a call to setIsActive.
4432 if (enable)
4433 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344434#endif
[email protected]7d3c02c2010-05-05 23:10:314435 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134436 }
[email protected]589621b2010-09-23 22:01:074437
4438 // Notify all Pepper plugins.
4439 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134440 }
4441}
[email protected]941e4552010-02-01 21:23:434442
[email protected]310ebd6302011-10-10 19:06:284443void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004444 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504445 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574446}
4447
[email protected]73bf95812011-10-12 11:38:324448void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004449 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324450}
4451
[email protected]3f783362011-10-21 22:40:504452void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4453 UpdateSelectionBounds();
4454}
4455
[email protected]b25b3ee2012-01-13 05:19:544456bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4457 if (!pepper_delegate_.IsPluginFocused())
4458 return false;
4459 *rect = pepper_delegate_.GetCaretBounds();
4460 return true;
4461}
4462
[email protected]73bf95812011-10-12 11:38:324463void RenderViewImpl::PpapiPluginCancelComposition() {
4464 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4465 ui::Range range(ui::Range::InvalidRange());
4466 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4467}
4468
[email protected]310ebd6302011-10-10 19:06:284469void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574470 const string16& text,
4471 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4472 int selection_start,
4473 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324474 if (pepper_delegate_.IsPluginFocused()) {
4475 // When a PPAPI plugin has focus, we bypass WebKit.
4476 pepper_delegate_.OnImeSetComposition(text,
4477 underlines,
4478 selection_start,
4479 selection_end);
4480 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234481#if defined(OS_WIN)
4482 // When a plug-in has focus, we create platform-specific IME data used by
4483 // our IME emulator and send it directly to the focused plug-in, i.e. we
4484 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4485 // instance ID is the same one as the specified ID.)
4486 if (focused_plugin_id_ >= 0) {
4487 std::vector<int> clauses;
4488 std::vector<int> target;
4489 for (size_t i = 0; i < underlines.size(); ++i) {
4490 clauses.push_back(underlines[i].startOffset);
4491 clauses.push_back(underlines[i].endOffset);
4492 if (underlines[i].thick) {
4493 target.clear();
4494 target.push_back(underlines[i].startOffset);
4495 target.push_back(underlines[i].endOffset);
4496 }
4497 }
4498 std::set<WebPluginDelegateProxy*>::iterator it;
4499 for (it = plugin_delegates_.begin();
4500 it != plugin_delegates_.end(); ++it) {
4501 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4502 focused_plugin_id_);
4503 }
4504 return;
4505 }
4506#endif
[email protected]56ea1a62011-05-30 07:05:574507 RenderWidget::OnImeSetComposition(text,
4508 underlines,
4509 selection_start,
4510 selection_end);
4511 }
4512}
4513
[email protected]4de6d1692011-10-12 08:45:444514void RenderViewImpl::OnImeConfirmComposition(
4515 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574516 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324517 // When a PPAPI plugin has focus, we bypass WebKit.
4518 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574519 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234520#if defined(OS_WIN)
4521 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4522 // plug-ins. When we send IME text directly to plug-ins, we should not send
4523 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444524 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234525 if (focused_plugin_id_ >= 0) {
4526 std::set<WebPluginDelegateProxy*>::iterator it;
4527 for (it = plugin_delegates_.begin();
4528 it != plugin_delegates_.end(); ++it) {
4529 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4530 }
4531 return;
4532 }
4533#endif
[email protected]ebd28ac2011-10-13 18:49:054534 if (replacement_range.IsValid() && webview()) {
4535 // Select the text in |replacement_range|, it will then be replaced by
4536 // text added by the call to RenderWidget::OnImeConfirmComposition().
4537 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164538 WebRange webrange = WebRange::fromDocumentRange(
4539 frame, replacement_range.start(), replacement_range.length());
4540 if (!webrange.isNull())
4541 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054542 }
4543 }
[email protected]4de6d1692011-10-12 08:45:444544 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574545 }
4546}
4547
[email protected]310ebd6302011-10-10 19:06:284548ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324549 return pepper_delegate_.IsPluginFocused() ?
4550 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4551}
4552
[email protected]3f783362011-10-21 22:40:504553void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4554 if (pepper_delegate_.IsPluginFocused()) {
4555 // TODO(kinaba) http://crbug.com/101101
4556 // Current Pepper IME API does not handle selection bounds. So we simply
4557 // use the caret position as an empty range for now. It will be updated
4558 // after Pepper API equips features related to surrounding text retrieval.
4559 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4560 *start = caret;
4561 *end = caret;
4562 return;
4563 }
4564 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454565}
4566
[email protected]310ebd6302011-10-10 19:06:284567bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324568 return pepper_delegate_.IsPluginFocused() ?
4569 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574570}
4571
[email protected]e6ae0f6c2011-10-04 10:39:234572#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284573void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234574 if (focused)
4575 focused_plugin_id_ = plugin_id;
4576 else
4577 focused_plugin_id_ = -1;
4578}
4579#endif
4580
[email protected]43f28f832010-02-03 02:28:484581#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284582void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134583 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4584 focused, plugin_id);
4585 Send(msg);
4586}
4587
[email protected]310ebd6302011-10-10 19:06:284588void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134589 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554590 // This message can be sent during event-handling, and needs to be delivered
4591 // within that context.
4592 msg->set_unblock(true);
4593 Send(msg);
4594}
4595
[email protected]310ebd6302011-10-10 19:06:284596gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234597 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484598 gfx::PluginWindowHandle window = NULL;
4599 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234600 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114601 if (window) {
4602 fake_plugin_window_handles_.insert(window);
4603 }
[email protected]43f28f832010-02-03 02:28:484604 return window;
4605}
4606
[email protected]310ebd6302011-10-10 19:06:284607void RenderViewImpl::DestroyFakePluginWindowHandle(
4608 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114609 if (window && fake_plugin_window_handles_.find(window) !=
4610 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484611 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114612 fake_plugin_window_handles_.erase(window);
4613 }
[email protected]43f28f832010-02-03 02:28:484614}
4615
[email protected]310ebd6302011-10-10 19:06:284616void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4617 gfx::PluginWindowHandle window,
4618 int32 width,
4619 int32 height,
4620 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334621 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484622 routing_id(), window, width, height, io_surface_identifier));
4623}
4624
[email protected]310ebd6302011-10-10 19:06:284625void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334626 gfx::PluginWindowHandle window,
4627 int32 width,
4628 int32 height,
4629 TransportDIB::Handle transport_dib) {
4630 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074631 routing_id(), window, width, height, transport_dib));
4632}
4633
[email protected]310ebd6302011-10-10 19:06:284634TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334635 size_t size) {
[email protected]1aef98132010-02-23 18:00:074636 TransportDIB::Handle dib_handle;
4637 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384638 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074639 return dib_handle;
4640 // Return an invalid handle if Send() fails.
4641 return TransportDIB::DefaultHandleValue();
4642}
4643
[email protected]310ebd6302011-10-10 19:06:284644void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4645 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074646 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4647}
4648
[email protected]310ebd6302011-10-10 19:06:284649void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144650 gfx::PluginWindowHandle window, uint64 surface_id) {
4651 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4652 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484653}
4654#endif
[email protected]58c321d2010-02-19 12:11:284655
[email protected]310ebd6302011-10-10 19:06:284656bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234657 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474658 WebFileChooserCompletion* completion) {
4659 static const size_t kMaximumPendingFileChooseRequests = 4;
4660 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4661 // This sanity check prevents too many file choose requests from getting
4662 // queued which could DoS the user. Getting these is most likely a
4663 // programming error (there are many ways to DoS the user so it's not
4664 // considered a "real" security check), either in JS requesting many file
4665 // choosers to pop up, or in a plugin.
4666 //
4667 // TODO(brettw) we might possibly want to require a user gesture to open
4668 // a file picker, which will address this issue in a better way.
4669 return false;
4670 }
4671
4672 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4673 new PendingFileChooser(params, completion)));
4674 if (file_chooser_completions_.size() == 1) {
4675 // Actually show the browse dialog when this is the first request.
4676 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4677 }
4678 return true;
4679}
4680
[email protected]310ebd6302011-10-10 19:06:284681WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514682 if (!geolocation_dispatcher_)
4683 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4684 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254685}
[email protected]61c9f032010-03-31 23:04:194686
[email protected]310ebd6302011-10-10 19:06:284687WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114688 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224689#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514690 if (!speech_input_dispatcher_)
4691 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224692#endif
[email protected]676126f72011-01-15 00:03:514693 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114694}
4695
[email protected]310ebd6302011-10-10 19:06:284696WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514697 if (!device_orientation_dispatcher_)
4698 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4699 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534700}
4701
[email protected]310ebd6302011-10-10 19:06:284702void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4703 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254704 // For now, don't remember plugin zoom values. We don't want to mix them with
4705 // normal web content (i.e. a fixed layout plugin would usually want them
4706 // different).
4707 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4708
[email protected]b75b8292010-10-01 07:28:254709 int minimum_percent = static_cast<int>(
4710 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4711 int maximum_percent = static_cast<int>(
4712 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254713
4714 Send(new ViewHostMsg_UpdateZoomLimits(
4715 routing_id_, minimum_percent, maximum_percent, remember));
4716}
4717
[email protected]310ebd6302011-10-10 19:06:284718void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254719 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084720 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:254721 // Tell the browser which url got zoomed so it can update the menu and the
4722 // saved values if necessary
4723 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084724 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414725 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254726}
4727
[email protected]310ebd6302011-10-10 19:06:284728void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4729 const WebString& base_url,
4730 const WebString& url,
4731 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484732 GURL base(base_url);
4733 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4734 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4735 return;
4736 }
[email protected]f1a29a02011-10-06 23:08:444737 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4738 UTF16ToUTF8(scheme),
4739 absolute_url,
4740 title));
[email protected]a6d36cc2011-02-23 00:39:484741}
4742
[email protected]310ebd6302011-10-10 19:06:284743WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444744 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4745 WebKit::WebPageVisibilityStateHidden :
4746 WebKit::WebPageVisibilityStateVisible;
4747 WebKit::WebPageVisibilityState override_state = current_state;
4748 if (content::GetContentClient()->renderer()->
4749 ShouldOverridePageVisibilityState(this,
4750 &override_state))
4751 return override_state;
4752 return current_state;
[email protected]94dec932011-05-26 20:04:214753}
4754
[email protected]273558fb2012-01-12 15:03:514755WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
4756 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
4757 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
4758 return NULL;
4759 EnsureMediaStreamImpl();
4760 return media_stream_impl_;
4761}
4762
[email protected]310ebd6302011-10-10 19:06:284763bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194764 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454765 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194766 if (frame->parent() != NULL)
4767 return false;
4768
[email protected]f0a3d0b2010-08-06 22:51:534769 // Navigations initiated within Webkit are not sent out to the external host
4770 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274771 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134772 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534773 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134774 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334775 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534776 return false;
4777
[email protected]2fc22d12010-12-02 23:08:164778 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324779 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014780 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164781 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014782 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324783 // The opener relationship between the new window and the parent allows the
4784 // new window to script the parent and vice versa. This is not allowed if
4785 // the origins of the two domains are different. This can be treated as a
4786 // top level navigation and routed back to the host.
4787 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274788 if (!opener) {
[email protected]86965362011-04-21 18:42:514789 return true;
[email protected]d19ea342011-04-20 20:31:134790 } else {
[email protected]b6cb3a842011-06-24 18:28:414791 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324792 return true;
4793 }
4794 }
[email protected]61c9f032010-03-31 23:04:194795 return false;
4796}
[email protected]2b06a992010-08-21 05:48:224797
[email protected]310ebd6302011-10-10 19:06:284798void RenderViewImpl::OnAsyncFileOpened(
4799 base::PlatformFileError error_code,
4800 IPC::PlatformFileForTransit file_for_transit,
4801 int message_id) {
[email protected]27a9ef32010-09-10 04:06:244802 pepper_delegate_.OnAsyncFileOpened(
4803 error_code,
4804 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4805 message_id);
4806}
[email protected]caf706f2010-10-26 17:54:084807
[email protected]310ebd6302011-10-10 19:06:284808void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:474809 int request_id,
4810 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434811 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474812 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4813 broker_process_handle,
4814 handle);
[email protected]eb415bf0e2011-04-14 02:45:424815}
4816
[email protected]caf706f2010-10-26 17:54:084817#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284818void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154819 if (external_popup_menu_ == NULL) {
4820 // Crash reports from the field indicate that we can be notified with a
4821 // NULL external popup menu (we probably get notified twice).
4822 // If you hit this please file a bug against jcivelli and include the page
4823 // and steps to repro.
4824 NOTREACHED();
4825 return;
4826 }
[email protected]caf706f2010-10-26 17:54:084827 external_popup_menu_->DidSelectItem(selected_index);
4828 external_popup_menu_.reset();
4829}
4830#endif
[email protected]bb461532010-11-26 21:50:234831
[email protected]1b4209f2011-01-07 00:25:404832#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:284833void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:404834 int request_id,
4835 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:494836 const PP_NetAddress_Private& local_addr,
4837 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:404838 pepper_delegate_.OnConnectTcpACK(
4839 request_id,
4840 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4841 local_addr,
4842 remote_addr);
4843}
4844#endif
[email protected]a6097f42011-01-10 08:50:514845
[email protected]310ebd6302011-10-10 19:06:284846void RenderViewImpl::OnContextMenuClosed(
[email protected]b29aa74b2011-01-31 21:41:084847 const webkit_glue::CustomContextMenuContext& custom_context) {
4848 if (custom_context.is_pepper_menu)
4849 pepper_delegate_.OnContextMenuClosed(custom_context);
4850 else
4851 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104852}
[email protected]5a7b15a2011-08-22 22:48:184853
[email protected]310ebd6302011-10-10 19:06:284854void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:184855 if (!webview())
4856 return;
4857 WebFrame* main_frame = webview()->mainFrame();
4858 if (!main_frame)
4859 return;
4860 main_frame->enableViewSourceMode(true);
4861}
[email protected]67bfb83f2011-09-22 03:36:374862
[email protected]310ebd6302011-10-10 19:06:284863void RenderViewImpl::OnLockMouseACK(bool succeeded) {
[email protected]57e02be2011-10-11 19:00:534864 // Mouse Lock removes the system cursor and provides all mouse motion as
4865 // .movementX/Y values on events all sent to a fixed target. This requires
4866 // content to specifically request the mode to be entered.
4867 // Mouse Capture is implicitly given for the duration of a drag event, and
4868 // sends all mouse events to the initial target of the drag.
4869 // If Lock is entered it supercedes any in progress Capture.
4870 if (succeeded)
4871 OnMouseCaptureLost();
4872
[email protected]67bfb83f2011-09-22 03:36:374873 pepper_delegate_.OnLockMouseACK(succeeded);
4874}
4875
[email protected]310ebd6302011-10-10 19:06:284876void RenderViewImpl::OnMouseLockLost() {
[email protected]67bfb83f2011-09-22 03:36:374877 pepper_delegate_.OnMouseLockLost();
4878}
[email protected]c3d45532011-10-07 19:20:404879
[email protected]310ebd6302011-10-10 19:06:284880bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:084881 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:404882}
[email protected]7f3c7af2011-10-20 22:52:514883
[email protected]64d0e192011-12-09 14:44:204884void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:514885 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:184886#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:204887 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:184888#endif
[email protected]7f3c7af2011-10-20 22:52:514889}