blob: 2b9c197a6b11465d1a192915d0e7a4271bff6244 [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]766a7082012-02-03 23:39:1553#include "content/renderer/dom_automation_controller.h"
[email protected]55722152011-03-22 01:33:5354#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1955#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4056#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]1784b2f2011-11-24 10:53:4857#include "content/renderer/idle_user_detector.h"
[email protected]0d9989d2011-12-21 20:26:0058#include "content/renderer/web_intents_host.h"
[email protected]07161902011-11-11 09:57:4259#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0260#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0861#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3762#include "content/renderer/media/audio_renderer_impl.h"
[email protected]273558fb2012-01-12 15:03:5163#include "content/renderer/media/media_stream_dependency_factory.h"
64#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4065#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4866#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4067#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4868#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]4a19be92011-09-22 14:25:0269#include "content/renderer/mhtml_generator.h"
[email protected]217690d2012-01-27 07:33:1170#include "content/renderer/mouse_lock_dispatcher.h"
[email protected]230b7ef2011-03-16 22:30:1971#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3772#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3573#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0574#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4475#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4476#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3277#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0178#include "content/renderer/renderer_webapplicationcachehost_impl.h"
79#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1980#include "content/renderer/speech_input_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3281#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1982#include "content/renderer/v8_value_converter_impl.h"
[email protected]663bd9e2011-03-21 01:07:0183#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3584#include "content/renderer/webplugin_delegate_proxy.h"
85#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4986#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4187#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2788#include "media/base/message_loop_factory_impl.h"
[email protected]e1d69d762011-12-13 05:12:1889#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2990#include "net/base/escape.h"
91#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0492#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5793#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3794#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:3795#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3796#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3797#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
98#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3799#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
100#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
101#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
102#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
103#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37104#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37105#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57106#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58107#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44108#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58109#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14110#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37111#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19112#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37113#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36114#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37115#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37118#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37119#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17122#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37123#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37124#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40125#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51126#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08127#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]273558fb2012-01-12 15:03:51133#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08135#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]e6e90dc2011-12-03 00:01:37138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26144#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47145#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38146#include "ui/gfx/native_widget_types.h"
147#include "ui/gfx/point.h"
148#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55149#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04150#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]9c4bf232011-12-15 02:25:08151#include "webkit/forms/form_data.h"
152#include "webkit/forms/form_field.h"
153#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43154#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24155#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19156#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24157#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29158#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07159#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29160#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03161#include "webkit/glue/weburlloader_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51162#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16163#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50164#include "webkit/plugins/npapi/plugin_list.h"
165#include "webkit/plugins/npapi/webplugin_delegate.h"
166#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
167#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52168#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29169
[email protected]6c8afae52009-01-22 02:24:57170#if defined(OS_WIN)
171// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57172// * theming
[email protected]08397d52011-02-05 01:53:38173#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03174#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37175#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51176#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33177#elif defined(OS_MACOSX)
178#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57179#endif
180
[email protected]9892b472010-09-16 00:23:42181using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08182using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21183using WebKit::WebApplicationCacheHost;
184using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26185using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41186using WebKit::WebColor;
187using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59188using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44189using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51190using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55191using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28192using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00193using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58194using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25195using WebKit::WebDragOperation;
196using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51197using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51198using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08199using WebKit::WebExternalPopupMenu;
200using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47201using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22202using WebKit::WebFileSystem;
203using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49204using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59205using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48206using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45207using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51208using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17209using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13210using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41211using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50212using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15213using WebKit::WebIntentRequest;
214using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17215using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28216using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17217using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28218using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28219using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51220using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19221using WebKit::WebPageSerializer;
222using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17223using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36224using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40225using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49226using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09227using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52228using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59229using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51230using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52231using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15232using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40233using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35234using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29235using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17236using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59237using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42238using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02239using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34240using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40241using WebKit::WebStorageQuotaCallbacks;
242using WebKit::WebStorageQuotaError;
243using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28244using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51245using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52246using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24247using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28248using WebKit::WebURL;
249using WebKit::WebURLError;
250using WebKit::WebURLRequest;
251using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28252using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03253using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28254using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26255using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26256using appcache::WebApplicationCacheHostImpl;
257using base::Time;
258using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07259using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32260using content::NavigationState;
[email protected]380244092011-10-07 17:26:27261using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44262using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36263using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15264using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19265using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08266using webkit::forms::FormField;
267using webkit::forms::PasswordForm;
268using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26269using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23270using webkit_glue::ResourceFetcher;
[email protected]e1acf6f2008-10-27 20:43:33271
initial.commit09911bf2008-07-26 23:55:29272//-----------------------------------------------------------------------------
273
[email protected]310ebd6302011-10-10 19:06:28274typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49275static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02276
[email protected]882daa92009-11-05 16:31:31277// Time, in seconds, we delay before sending content state changes (such as form
278// state and scroll position) to the browser. We delay sending changes to avoid
279// spamming the browser.
280// To avoid having tab/session restore require sending a message to get the
281// current content state during tab closing we use a shorter timeout for the
282// foreground renderer. This means there is a small window of time from which
283// content state is modified and not sent to session restore, but this is
284// better than having to wake up all renderers during shutdown.
285static const int kDelaySecondsForContentStateSyncHidden = 5;
286static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29287
[email protected]e99ef6f2011-10-16 01:13:00288static const size_t kExtraCharsBeforeAndAfterSelection = 100;
289
[email protected]0aa55312008-10-17 21:53:08290// The maximum number of popups that can be spawned from one page.
291static const int kMaximumNumberOfUnacknowledgedPopups = 25;
292
[email protected]c514d6372011-08-16 22:54:44293static const float kScalingIncrement = 0.1f;
294
[email protected]47578fa02011-11-02 19:34:41295static const float kScalingIncrementForGesture = 0.01f;
296
[email protected]726985e22009-06-18 21:09:28297static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
298 WebVector<WebURL> urls;
299 ds->redirectChain(urls);
300 result->reserve(urls.size());
301 for (size_t i = 0; i < urls.size(); ++i)
302 result->push_back(urls[i]);
303}
304
[email protected]007733c2011-11-17 00:34:07305// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44306// the AltErrorPageResourceFetcher is reset.
307static void StopAltErrorPageFetcher(WebDataSource* data_source) {
308 if (data_source) {
[email protected]007733c2011-11-17 00:34:07309 DocumentState* document_state = DocumentState::FromDataSource(data_source);
310 if (document_state)
311 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44312 }
313}
314
[email protected]007733c2011-11-17 00:34:07315static bool IsReload(const ViewMsg_Navigate_Params& params) {
316 return
317 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
318 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
319}
320
[email protected]445e1042011-12-03 21:03:15321static WebReferrerPolicy getReferrerPolicyFromRequest(
322 const WebURLRequest& request) {
323 return request.extraData() ?
324 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
325 WebKit::WebReferrerPolicyDefault;
326}
327
initial.commit09911bf2008-07-26 23:55:29328///////////////////////////////////////////////////////////////////////////////
329
[email protected]310ebd6302011-10-10 19:06:28330struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23331 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47332 WebFileChooserCompletion* c)
333 : params(p),
334 completion(c) {
335 }
[email protected]8caadeb2011-11-22 02:45:23336 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47337 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
338};
339
[email protected]217690d2012-01-27 07:33:11340namespace {
341
342class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
343 public:
344 WebWidgetLockTarget (WebKit::WebWidget* webwidget)
345 : webwidget_(webwidget) {}
346
347 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
348 if (succeeded)
349 webwidget_->didAcquirePointerLock();
350 else
351 webwidget_->didNotAcquirePointerLock();
352 }
353
354 virtual void OnMouseLockLost() OVERRIDE {
355 webwidget_->didLosePointerLock();
356 }
357
358 virtual bool HandleMouseLockedInputEvent(
359 const WebKit::WebMouseEvent &event) OVERRIDE {
360 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
361 return false;
362 }
363
364 private:
365 WebKit::WebWidget* webwidget_;
366};
367
[email protected]86cd9472012-02-03 19:51:05368int64 ExtractPostId(const WebHistoryItem& item) {
369 if (item.isNull())
370 return -1;
371
372 if (item.httpBody().isNull())
373 return -1;
374
375 return item.httpBody().identifier();
376}
377
[email protected]217690d2012-01-27 07:33:11378} // namespace
379
[email protected]daf82f82011-10-31 22:35:31380RenderViewImpl::RenderViewImpl(
381 gfx::NativeViewId parent_hwnd,
382 int32 opener_id,
383 const content::RendererPreferences& renderer_prefs,
384 const WebPreferences& webkit_prefs,
385 SharedRenderViewCounter* counter,
386 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56387 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31388 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46389 const string16& frame_name,
390 int32 next_page_id)
[email protected]380244092011-10-07 17:26:27391 : RenderWidget(WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51392 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02393 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09394 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02395 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24396 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21397 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02398 opened_by_user_gesture_(true),
399 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24400 page_id_(-1),
401 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46402 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00403 history_list_offset_(-1),
404 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02405 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55406 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31407 cached_is_main_frame_pinned_to_left_(false),
408 cached_is_main_frame_pinned_to_right_(false),
409 cached_has_main_frame_horizontal_scrollbar_(false),
410 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]3354d3e2010-06-10 19:53:02411 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51412 geolocation_dispatcher_(NULL),
413 speech_input_dispatcher_(NULL),
414 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51415 media_stream_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18416 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41417 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32418 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11419 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08420 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18421 handling_select_range_(false),
422#if defined(OS_WIN)
423 focused_plugin_id_(-1),
424#endif
425 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51426 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56427 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51428 if (opener_id != MSG_ROUTING_NONE)
429 opener_id_ = opener_id;
430
[email protected]74ce1ad2011-12-16 21:51:46431 // Ensure we start with a valid next_page_id_ from the browser.
432 DCHECK_GE(next_page_id_, 0);
433
[email protected]21b3a6ae2011-11-30 00:45:29434#if defined(ENABLE_NOTIFICATIONS)
435 notification_provider_ = new NotificationProvider(this);
436#else
437 notification_provider_ = NULL;
438#endif
439
[email protected]11fee2332011-03-29 20:36:35440 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11441 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35442
[email protected]676126f72011-01-15 00:03:51443 if (counter) {
444 shared_popup_counter_ = counter;
445 shared_popup_counter_->data++;
446 decrement_shared_popup_at_destruction_ = true;
447 } else {
448 shared_popup_counter_ = new SharedRenderViewCounter(0);
449 decrement_shared_popup_at_destruction_ = false;
450 }
451
[email protected]0d9989d2011-12-21 20:26:00452 intents_host_ = new WebIntentsHost(this);
[email protected]7cce3232011-10-28 10:41:57453
[email protected]380244092011-10-07 17:26:27454 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51455 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47456 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51457 AddRef();
458
459 // If this is a popup, we must wait for the CreatingNew_ACK message before
460 // completing initialization. Otherwise, we can finish it now.
461 if (opener_id == MSG_ROUTING_NONE) {
462 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55463 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51464 }
465
[email protected]34c61bd52011-05-02 19:38:33466 g_view_map.Get().insert(std::make_pair(webview(), this));
467 webkit_preferences_.Apply(webview());
468 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35469 if (!frame_name.empty())
470 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33471 webview()->settings()->setMinimumTimerInterval(
472 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
473 webkit_glue::kForegroundTabTimerInterval);
474
475 OnSetRendererPrefs(renderer_prefs);
476
[email protected]676126f72011-01-15 00:03:51477 host_window_ = parent_hwnd;
478
[email protected]a026daa2011-04-20 15:49:51479#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51480 if (!p2p_socket_dispatcher_)
481 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51482#endif
[email protected]cae8c8492011-03-03 11:12:18483
[email protected]735873d2012-01-25 23:31:02484 if (!media_stream_dispatcher_)
485 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
486
[email protected]8f6a3b852011-07-19 16:48:56487 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32488#if defined(OS_MACOSX)
489 new TextInputClientObserver(this);
490#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56491
[email protected]217690d2012-01-27 07:33:11492 // The next group of objects all implement RenderViewObserver, so are deleted
493 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41494 devtools_agent_ = new DevToolsAgent(this);
[email protected]063afcb2011-09-29 07:54:32495 renderer_accessibility_ = new RendererAccessibility(this);
[email protected]217690d2012-01-27 07:33:11496 mouse_lock_dispatcher_ = new MouseLockDispatcher(this);
[email protected]063afcb2011-09-29 07:54:32497
[email protected]1784b2f2011-11-24 10:53:48498 new IdleUserDetector(this);
499
[email protected]766a7082012-02-03 23:39:15500 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
501 if (command_line.HasSwitch(switches::kDomAutomationController))
502 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
503
[email protected]e48869a2011-04-01 19:56:03504 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29505}
506
[email protected]310ebd6302011-10-10 19:06:28507RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03508 history_page_ids_.clear();
509
[email protected]0aa55312008-10-17 21:53:08510 if (decrement_shared_popup_at_destruction_)
511 shared_popup_counter_->data--;
512
[email protected]a1128322009-10-06 18:38:46513 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47514 while (!file_chooser_completions_.empty()) {
515 if (file_chooser_completions_.front()->completion) {
516 file_chooser_completions_.front()->completion->didChooseFile(
517 WebVector<WebString>());
518 }
519 file_chooser_completions_.pop_front();
520 }
[email protected]a1128322009-10-06 18:38:46521
[email protected]83dde542009-09-11 20:59:55522#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11523 // Destroy all fake plugin window handles on the browser side.
524 while (!fake_plugin_window_handles_.empty()) {
525 // Make sure no NULL plugin window handles were inserted into this list.
526 DCHECK(*fake_plugin_window_handles_.begin());
527 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
528 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
529 }
[email protected]83dde542009-09-11 20:59:55530#endif
[email protected]98324892009-09-09 21:16:05531
[email protected]60c42a8c72009-10-09 04:08:59532#ifndef NDEBUG
533 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49534 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59535 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
536 DCHECK_NE(this, it->second) << "Failed to call Close?";
537#endif
[email protected]676126f72011-01-15 00:03:51538
[email protected]273558fb2012-01-12 15:03:51539 // MediaStreamImpl holds weak references to RenderViewObserver objects,
540 // ensure it's deleted before the observers.
541 media_stream_impl_ = NULL;
542
[email protected]310ebd6302011-10-10 19:06:28543 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51544 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59545}
546
547/*static*/
[email protected]310ebd6302011-10-10 19:06:28548RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31549 ViewMap* views = g_view_map.Pointer();
550 ViewMap::iterator it = views->find(webview);
551 return it == views->end() ? NULL : it->second;
552}
553
554/*static*/
555content::RenderView*
556 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28557 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31558}
559
560/*static*/
561void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49562 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59563 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
564 if (!visitor->Visit(it->second))
565 return;
566 }
567}
568
569/*static*/
[email protected]310ebd6302011-10-10 19:06:28570RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15571 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08572 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31573 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08574 const WebPreferences& webkit_prefs,
575 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34576 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56577 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26578 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46579 const string16& frame_name,
580 int32 next_page_id) {
initial.commit09911bf2008-07-26 23:55:29581 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28582 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51583 parent_hwnd,
584 opener_id,
585 renderer_prefs,
586 webkit_prefs,
587 counter,
588 routing_id,
[email protected]9f4f3322012-01-18 22:29:56589 surface_id,
[email protected]676126f72011-01-15 00:03:51590 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46591 frame_name,
592 next_page_id); // adds reference
initial.commit09911bf2008-07-26 23:55:29593}
594
[email protected]273558fb2012-01-12 15:03:51595WebKit::WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
596 WebKit::WebPeerConnectionHandlerClient* client) {
597 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
598 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
599 return NULL;
600 EnsureMediaStreamImpl();
601 return media_stream_impl_->CreatePeerConnectionHandler(client);
602}
603
[email protected]310ebd6302011-10-10 19:06:28604void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51605 observers_.AddObserver(observer);
606}
607
[email protected]310ebd6302011-10-10 19:06:28608void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
609 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51610 observers_.RemoveObserver(observer);
611}
612
[email protected]310ebd6302011-10-10 19:06:28613WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26614 return static_cast<WebKit::WebView*>(webwidget());
615}
616
[email protected]310ebd6302011-10-10 19:06:28617void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40618 if (!enabled) {
619 load_progress_tracker_.reset(NULL);
620 return;
621 }
622 if (load_progress_tracker_ == NULL)
623 load_progress_tracker_.reset(new LoadProgressTracker(this));
624}
625
[email protected]310ebd6302011-10-10 19:06:28626void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51627 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29628}
629
[email protected]310ebd6302011-10-10 19:06:28630void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26631 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30632 // If the renderer is visible, set initial visibility and focus state.
633 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34634#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30635 delegate->SetContainerVisibility(true);
636 if (webview() && webview()->isActive())
637 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34638#endif
[email protected]49232292010-09-03 19:07:30639 }
[email protected]784ea1ab2010-09-18 00:02:34640 // Plugins start assuming the content has focus (so that they work in
641 // environments where RenderView isn't hosting them), so we always have to
642 // set the initial state. See webplugin_delegate_impl.h for details.
643 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26644}
645
[email protected]310ebd6302011-10-10 19:06:28646void RenderViewImpl::UnregisterPluginDelegate(
647 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26648 plugin_delegates_.erase(delegate);
649}
[email protected]d8fd6fa2010-02-01 15:54:26650
[email protected]310ebd6302011-10-10 19:06:28651bool RenderViewImpl::GetPluginInfo(const GURL& url,
652 const GURL& page_url,
653 const std::string& mime_type,
654 webkit::WebPluginInfo* plugin_info,
655 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08656 bool found = false;
657 Send(new ViewHostMsg_GetPluginInfo(
658 routing_id_, url, page_url, mime_type, &found, plugin_info,
659 actual_mime_type));
660 return found;
661}
662
[email protected]310ebd6302011-10-10 19:06:28663bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27664 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27665 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41666 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26667
[email protected]676126f72011-01-15 00:03:51668 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
669 RenderViewObserver* observer;
670 while ((observer = it.GetNext()) != NULL)
671 if (observer->OnMessageReceived(message))
672 return true;
[email protected]b2abac72009-02-26 12:39:28673
[email protected]a95986a82010-12-24 06:19:28674 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40675 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28676 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29677 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
678 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56679 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29680 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
681 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
682 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
683 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27684#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35685 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27686#endif
initial.commit09911bf2008-07-26 23:55:29687 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15688 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29689 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
690 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
691 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08692 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29693 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15694 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29695 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49696 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
697 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17698 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17699 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41700 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54701 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
702 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29703 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18704 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
705 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29706 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48707 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55708 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
709 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
710 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
711 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
712 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
713 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
714 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45715 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40716 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29717 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19718 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
719 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29720 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
721 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
722 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51723 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
724 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29725 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04726 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15727 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29728 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
729 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08730 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
731 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00732 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16733 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14734 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25735 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
736 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47737 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]cda45c02010-02-25 19:28:10738 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
739 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51740 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56741 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36742 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34743 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14744#if defined(OS_MACOSX)
745 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13746 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13747 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
748 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14749#endif
[email protected]446705872009-09-10 07:22:48750 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33751 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33752 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
753 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24754 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42755 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
756 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19757 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
758 OnGetAllSavableResourceLinksForCurrentPage)
759 IPC_MESSAGE_HANDLER(
760 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
761 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08762#if defined(OS_MACOSX)
763 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
764#endif
[email protected]521b2482011-01-15 00:10:10765 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51766 // TODO(viettrungluu): Move to a separate message filter.
767#if defined(ENABLE_FLAPPER_HACKS)
768 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
769#endif
[email protected]54ca3ca892011-06-07 21:14:54770#if defined(OS_MACOSX)
771 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
772#endif
[email protected]9e1ad4b2011-08-14 16:49:19773 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
774 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18775 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51776 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19777
initial.commit09911bf2008-07-26 23:55:29778 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28779 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29780 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40781
782 if (!msg_is_ok) {
783 // The message had a handler, but its deserialization failed.
784 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28785 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40786 }
787
[email protected]a95986a82010-12-24 06:19:28788 return handled;
initial.commit09911bf2008-07-26 23:55:29789}
790
[email protected]310ebd6302011-10-10 19:06:28791void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
initial.commit09911bf2008-07-26 23:55:29792 if (!webview())
793 return;
794
[email protected]440a0e52011-09-13 17:38:58795 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
796
[email protected]007733c2011-11-17 00:34:07797 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03798
799 // If this is a stale back/forward (due to a recent navigation the browser
800 // didn't know about), ignore it.
801 if (IsBackForwardToStaleEntry(params, is_reload))
802 return;
803
[email protected]992db4c2011-05-12 15:37:15804 // Swap this renderer back in if necessary.
805 if (is_swapped_out_)
806 SetSwappedOut(false);
807
[email protected]3cc72b12010-03-18 23:03:00808 history_list_offset_ = params.current_history_list_offset;
809 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03810 if (history_list_length_ >= 0)
811 history_page_ids_.resize(history_list_length_, -1);
812 if (params.pending_history_list_offset >= 0 &&
813 params.pending_history_list_offset < history_list_length_)
814 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00815
[email protected]38b592902011-04-16 02:08:42816 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29817
[email protected]26aa0482009-09-30 16:55:27818 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45819 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29820 // We cannot reload if we do not have any history state. This happens, for
821 // example, when recovering from a crash. Our workaround here is a bit of
822 // a hack since it means that reload after a crashed tab does not cause an
823 // end-to-end cache validation.
824 is_reload = false;
825 }
826
[email protected]007733c2011-11-17 00:34:07827 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
828 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50829
[email protected]04d3c6e2009-05-22 17:00:13830 // If we are reloading, then WebKit will use the history state of the current
831 // page, so we should just ignore any given history state. Otherwise, if we
832 // have history state, then we need to navigate to it, which corresponds to a
833 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55834 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29835 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02836 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29837 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55838 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13839 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58840 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45841 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17842 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13843 } else {
844 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28845 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29846
[email protected]e6f546c32009-07-01 17:12:55847 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23848 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13849
[email protected]dd7daa82009-08-10 05:46:45850 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55851 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13852
[email protected]445e1042011-12-03 21:03:15853 if (params.referrer.url.is_valid()) {
854 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
855 params.referrer.policy,
856 params.url,
857 WebString::fromUTF8(params.referrer.url.spec()));
858 if (!referrer.isEmpty())
859 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28860 }
[email protected]04d3c6e2009-05-22 17:00:13861
[email protected]52c68652010-12-07 17:47:04862 if (!params.extra_headers.empty()) {
863 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
864 params.extra_headers.end(), "\n");
865 i.GetNext(); ) {
866 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
867 WebString::fromUTF8(i.values()));
868 }
869 }
870
[email protected]dd7daa82009-08-10 05:46:45871 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50872 }
873
[email protected]77f17a82009-05-21 04:42:54874 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07875 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29876}
877
[email protected]310ebd6302011-10-10 19:06:28878bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03879 const ViewMsg_Navigate_Params& params,
880 bool is_reload) {
881 // Make sure this isn't a back/forward to an entry we have already cropped
882 // or replaced from our history, before the browser knew about it. If so,
883 // a new navigation has committed in the mean time, and we can ignore this.
884 bool is_back_forward = !is_reload && !params.state.empty();
885
886 // Note: if the history_list_length_ is 0 for a back/forward, we must be
887 // restoring from a previous session. We'll update our state in OnNavigate.
888 if (!is_back_forward || history_list_length_ <= 0)
889 return false;
890
891 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
892
893 // Check for whether the forward history has been cropped due to a recent
894 // navigation the browser didn't know about.
895 if (params.pending_history_list_offset >= history_list_length_)
896 return true;
897
898 // Check for whether this entry has been replaced with a new one.
899 int expected_page_id =
900 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44901 if (expected_page_id > 0 && params.page_id != expected_page_id) {
902 if (params.page_id < expected_page_id)
903 return true;
904
905 // Otherwise we've removed an earlier entry and should have shifted all
906 // entries left. For now, it's ok to lazily update the list.
907 // TODO(creis): Notify all live renderers when we remove entries from
908 // the front of the list, so that we don't hit this case.
909 history_page_ids_[params.pending_history_list_offset] = params.page_id;
910 }
[email protected]d466b8a2011-07-15 21:48:03911
912 return false;
913}
914
initial.commit09911bf2008-07-26 23:55:29915// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28916void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44917 if (webview()) {
918 WebFrame* main_frame = webview()->mainFrame();
919 // Stop the alt error page fetcher. If we let it continue it may complete
920 // and cause RenderViewHostManager to swap to this RenderView, even though
921 // it may no longer be active.
922 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
923 StopAltErrorPageFetcher(main_frame->dataSource());
924 main_frame->stopLoading();
925 }
initial.commit09911bf2008-07-26 23:55:29926}
927
[email protected]ecbf10d2010-02-18 13:03:29928// Reload current focused frame.
929// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28930void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29931 if (webview() && webview()->focusedFrame()) {
932 // We always obey the cache (ignore_cache=false) here.
933 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
934 // a cache-ignoring reload of the frame.
935 webview()->focusedFrame()->reload(false);
936 }
[email protected]1dda4022010-01-28 18:24:56937}
938
[email protected]310ebd6302011-10-10 19:06:28939void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27940 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29941}
942
[email protected]310ebd6302011-10-10 19:06:28943void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:25944 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27945 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25946 return;
947
[email protected]26aa0482009-09-30 16:55:27948 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45949 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25950}
951
[email protected]310ebd6302011-10-10 19:06:28952void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:29953 // Check if there is a targeturl waiting to be sent.
954 if (target_url_status_ == TARGET_PENDING) {
955 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
956 pending_target_url_));
957 }
958
959 target_url_status_ = TARGET_NONE;
960}
961
[email protected]310ebd6302011-10-10 19:06:28962void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:29963 if (!webview())
964 return;
965
[email protected]26aa0482009-09-30 16:55:27966 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29967}
968
[email protected]310ebd6302011-10-10 19:06:28969void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:29970 if (!webview())
971 return;
972
[email protected]26aa0482009-09-30 16:55:27973 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29974}
975
[email protected]310ebd6302011-10-10 19:06:28976void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:29977 if (!webview())
978 return;
979
[email protected]26aa0482009-09-30 16:55:27980 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29981}
982
[email protected]310ebd6302011-10-10 19:06:28983void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:29984 if (!webview())
985 return;
986
[email protected]f6b1856b2011-06-29 22:02:53987 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
988 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29989}
990
[email protected]c0cc3092009-09-12 08:27:27991#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:28992void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:35993 if (!webview())
994 return;
995
996 // Since the find pasteboard supports only plain text, this can be simpler
997 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27998 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35999 if (frame->hasSelection()) {
1000 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271001 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171002 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351003 }
[email protected]a954bf72009-09-12 07:30:351004}
[email protected]c0cc3092009-09-12 08:27:271005#endif
[email protected]a954bf72009-09-12 07:30:351006
[email protected]310ebd6302011-10-10 19:06:281007void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291008 if (!webview())
1009 return;
1010
[email protected]26aa0482009-09-30 16:55:271011 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291012}
1013
[email protected]44bf7002011-10-16 02:46:151014void RenderViewImpl::OnPasteAndMatchStyle() {
1015 if (!webview())
1016 return;
1017
1018 webview()->focusedFrame()->executeCommand(
1019 WebString::fromUTF8("PasteAndMatchStyle"));
1020}
1021
[email protected]310ebd6302011-10-10 19:06:281022void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291023 if (!webview())
1024 return;
1025
[email protected]1ff7a032010-02-03 02:46:031026 WebFrame* frame = webview()->focusedFrame();
1027 if (!frame->hasSelection())
1028 frame->selectWordAroundCaret();
1029 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291030}
1031
[email protected]310ebd6302011-10-10 19:06:281032void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291033 if (!webview())
1034 return;
1035
[email protected]26aa0482009-09-30 16:55:271036 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291037}
1038
[email protected]310ebd6302011-10-10 19:06:281039void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291040 if (!webview())
1041 return;
1042
[email protected]26aa0482009-09-30 16:55:271043 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221044 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291045}
1046
[email protected]310ebd6302011-10-10 19:06:281047void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1048 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081049 if (!webview())
1050 return;
1051
1052 handling_select_range_ = true;
1053 webview()->focusedFrame()->selectRange(start, end);
1054 handling_select_range_ = false;
1055}
1056
[email protected]310ebd6302011-10-10 19:06:281057void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1058 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191059 DCHECK(history_length >= 0);
1060 DCHECK(history_list_offset_ == history_list_length_ - 1);
1061 DCHECK(minimum_page_id >= -1);
1062
1063 // Generate the new list.
1064 std::vector<int32> new_history_page_ids(history_length, -1);
1065 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1066 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1067 continue;
1068 new_history_page_ids.push_back(history_page_ids_[i]);
1069 }
1070 new_history_page_ids.swap(history_page_ids_);
1071
1072 // Update indexes.
1073 history_list_length_ = history_page_ids_.size();
1074 history_list_offset_ = history_list_length_ - 1;
1075}
1076
1077
[email protected]310ebd6302011-10-10 19:06:281078void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291079 if (!webview())
1080 return;
[email protected]26aa0482009-09-30 16:55:271081 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291082}
1083
[email protected]54ca3ca892011-06-07 21:14:541084#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281085void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331086 if (!webview())
1087 return;
1088 if (in_live_resize)
1089 webview()->willStartLiveResize();
1090 else
1091 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541092}
1093#endif
1094
[email protected]310ebd6302011-10-10 19:06:281095void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1096 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091097 WebKit::WebNode node = GetFocusedNode();
1098 if (!node.isNull()) {
1099 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191100 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511101 }
1102}
1103
initial.commit09911bf2008-07-26 23:55:291104///////////////////////////////////////////////////////////////////////////////
1105
1106// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281107void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451108 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291109 DCHECK(ds);
1110
[email protected]726985e22009-06-18 21:09:281111 const WebURLRequest& request = ds->request();
1112 const WebURLRequest& original_request = ds->originalRequest();
1113 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291114
[email protected]007733c2011-11-17 00:34:071115 DocumentState* document_state = DocumentState::FromDataSource(ds);
1116 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291117
1118 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281119 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291120 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051121 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291122 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071123 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191124 params.socket_address.set_host(response.remoteIPAddress().utf8());
1125 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031126 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091127 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071128 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291129 // SSL state specified in the request takes precedence over the one in the
1130 // response.
1131 // So far this is only intended for error pages that are not expected to be
1132 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281133 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071134 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291135 } else {
[email protected]726985e22009-06-18 21:09:281136 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291137 }
1138
1139 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281140 if (ds->hasUnreachableURL()) {
1141 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291142 } else {
[email protected]726985e22009-06-18 21:09:281143 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291144 }
1145
[email protected]5f9b8712011-11-23 08:55:571146 if (frame->document().baseURL() != params.url)
1147 params.base_url = frame->document().baseURL();
1148
[email protected]726985e22009-06-18 21:09:281149 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241150 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041151 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291152
[email protected]007733c2011-11-17 00:34:071153 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351154 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071155 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291156
1157 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071158 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291159 if (password_form_data)
1160 params.password_form = *password_form_data;
1161
1162 params.gesture = navigation_gesture_;
1163 navigation_gesture_ = NavigationGestureUnknown;
1164
[email protected]0f38dc4552011-02-25 11:24:001165 // Make navigation state a part of the FrameNavigate message so that commited
1166 // entry had it at all times.
1167 const WebHistoryItem& item = frame->currentHistoryItem();
1168 if (!item.isNull()) {
1169 params.content_state = webkit_glue::HistoryItemToString(item);
1170 } else {
1171 params.content_state =
1172 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1173 }
1174
[email protected]dd7daa82009-08-10 05:46:451175 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291176 // Top-level navigation.
1177
[email protected]b75b8292010-10-01 07:28:251178 // Set zoom level, but don't do it for full-page plugin since they don't use
1179 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011180 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541181 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251182 if (webview()->mainFrame()->document().isPluginDocument()) {
1183 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251184 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251185 } else {
1186 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251187 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251188 }
1189
[email protected]f85f0702010-01-30 09:31:011190 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511191 // This zoom level was merely recorded transiently for this load. We can
1192 // erase it now. If at some point we reload this page, the browser will
1193 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011194 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511195 }
1196
[email protected]b75b8292010-10-01 07:28:251197 // Reset the zoom limits in case a plugin had changed them previously. This
1198 // will also call us back which will cause us to send a message to
1199 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251200 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011201 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1202 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251203
initial.commit09911bf2008-07-26 23:55:291204 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551205 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291206
[email protected]daa8c58e2009-06-15 17:21:101207 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581208 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291209 // If the main frame does a load, it should not be reported as a subframe
1210 // navigation. This can occur in the following case:
1211 // 1. You're on a site with frames.
1212 // 2. You do a subframe navigation. This is stored with transition type
1213 // MANUAL_SUBFRAME.
1214 // 3. You navigate to some non-frame site, say, google.com.
1215 // 4. You navigate back to the page from step 2. Since it was initially
1216 // MANUAL_SUBFRAME, it will be that same transition type here.
1217 // We don't want that, because any navigation that changes the toplevel
1218 // frame should be tracked as a toplevel navigation (this allows us to
1219 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581220 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291221 }
1222
initial.commit09911bf2008-07-26 23:55:291223 // If we have a valid consumed client redirect source,
1224 // the page contained a client redirect (meta refresh, document.loc...),
1225 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151226 if (completed_client_redirect_src_.url.is_valid()) {
1227 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291228 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581229 params.transition = static_cast<content::PageTransition>(
1230 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291231 } else {
1232 // Bug 654101: the referrer will be empty on https->http transitions. It
1233 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151234 params.referrer = Referrer(GURL(
1235 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
1236 getReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291237 }
1238
[email protected]726985e22009-06-18 21:09:281239 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051240 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291241 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051242 params.post_id = ExtractPostId(item);
1243 }
initial.commit09911bf2008-07-26 23:55:291244
[email protected]c2a797d2009-09-21 16:46:321245 // Save some histogram data so we can compute the average memory used per
1246 // page load of the glyphs.
1247 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1248 webkit_glue::GetGlyphPageCount());
1249
[email protected]15cf526b2010-02-12 06:33:491250 // This message needs to be sent before any of allowScripts(),
1251 // allowImages(), allowPlugins() is called for the new page, so that when
1252 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1253 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291254 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1255 } else {
1256 // Subframe navigation: the type depends on whether this navigation
1257 // generated a new session history entry. When they do generate a session
1258 // history entry, it means the user initiated the navigation and we should
1259 // mark it as such. This test checks if this is the first time UpdateURL
1260 // has been called since WillNavigateToURL was called to initiate the load.
1261 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581262 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291263 else
[email protected]2905f742011-10-13 03:51:581264 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291265
initial.commit09911bf2008-07-26 23:55:291266 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1267 }
1268
1269 last_page_id_sent_to_browser_ =
1270 std::max(last_page_id_sent_to_browser_, page_id_);
1271
1272 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101273 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581274 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291275}
1276
1277// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281278void RenderViewImpl::UpdateTitle(WebFrame* frame,
1279 const string16& title,
1280 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461281 // Ignore all but top level navigations.
1282 if (frame->parent())
1283 return;
1284
1285 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1286 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1287 title_direction));
initial.commit09911bf2008-07-26 23:55:291288}
1289
[email protected]310ebd6302011-10-10 19:06:281290void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1291 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291292 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271293 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291294 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301295 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291296 last_encoding_name_ = encoding_name;
1297
[email protected]e38f40152008-09-12 23:08:301298 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291299 }
1300}
1301
[email protected]e15f680732010-11-23 22:30:201302// Sends the last committed session history state to the browser so it will be
1303// saved before we navigate to a new page. This must be called *before* the
1304// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281305void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291306 // If we have a valid page ID at this point, then it corresponds to the page
1307 // we are navigating away from. Otherwise, this is the first navigation, so
1308 // there is no past session history to record.
1309 if (page_id_ == -1)
1310 return;
1311
[email protected]ca948a22009-06-25 19:36:171312 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271313 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171314 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291315 return;
[email protected]ca948a22009-06-25 19:36:171316
1317 Send(new ViewHostMsg_UpdateState(
1318 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291319}
1320
[email protected]310ebd6302011-10-10 19:06:281321void RenderViewImpl::OpenURL(WebFrame* frame,
1322 const GURL& url,
[email protected]445e1042011-12-03 21:03:151323 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281324 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171325 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581326 routing_id_,
1327 url,
1328 referrer,
1329 NavigationPolicyToDisposition(policy),
1330 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171331}
1332
[email protected]79dbc662009-09-04 05:42:511333// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291334
[email protected]310ebd6302011-10-10 19:06:281335void RenderViewImpl::LoadNavigationErrorPage(
1336 WebFrame* frame,
1337 const WebURLRequest& failed_request,
1338 const WebURLError& error,
1339 const std::string& html,
1340 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581341 std::string alt_html;
1342 const std::string* error_html;
1343
1344 if (!html.empty()) {
1345 error_html = &html;
1346 } else {
1347 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1348 failed_request, error, &alt_html, NULL);
1349 error_html = &alt_html;
1350 }
1351
1352 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361353 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251354 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551355 replace);
initial.commit09911bf2008-07-26 23:55:291356}
1357
[email protected]269f86d2011-12-07 02:43:471358bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281359 const string16& message,
1360 const string16& default_value,
1361 const GURL& frame_url,
1362 string16* result) {
initial.commit09911bf2008-07-26 23:55:291363 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411364 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291365 if (!result)
1366 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291367
[email protected]12636df2009-09-28 22:32:211368 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1369 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291370 return success;
1371}
1372
[email protected]310ebd6302011-10-10 19:06:281373bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571374 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1375 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1376 // it is particularly important that we do not call willEnterModalLoop as
1377 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441378 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1379 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571380
1381 message->EnableMessagePumping(); // Runs a nested message loop.
1382 return Send(message);
1383}
1384
[email protected]48c9cf2d2009-09-16 16:47:521385// WebKit::WebViewClient ------------------------------------------------------
1386
[email protected]310ebd6302011-10-10 19:06:281387WebView* RenderViewImpl::createView(
[email protected]844acf372011-01-14 10:49:271388 WebFrame* creator,
1389 const WebURLRequest& request,
1390 const WebWindowFeatures& features,
1391 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521392 // Check to make sure we aren't overloading on popups.
1393 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1394 return NULL;
1395
[email protected]8ab04652010-06-12 02:47:261396 ViewHostMsg_CreateWindow_Params params;
1397 params.opener_id = routing_id_;
1398 params.user_gesture = creator->isProcessingUserGesture();
1399 params.window_container_type = WindowFeaturesToContainerType(features);
1400 params.session_storage_namespace_id = session_storage_namespace_id_;
1401 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111402 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411403 params.opener_url = creator->document().url();
1404 params.opener_security_origin =
1405 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111406 if (!request.isNull())
1407 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261408
[email protected]48c9cf2d2009-09-16 16:47:521409 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561410 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341411 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261412 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521413
[email protected]380244092011-10-07 17:26:271414 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261415 new ViewHostMsg_CreateWindow(params,
1416 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561417 &surface_id,
[email protected]8ab04652010-06-12 02:47:261418 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211419 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521420 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521421
[email protected]310ebd6302011-10-10 19:06:281422 RenderViewImpl* view = RenderViewImpl::Create(
1423 0,
1424 routing_id_,
1425 renderer_preferences_,
1426 webkit_preferences_,
1427 shared_popup_counter_,
1428 routing_id,
[email protected]9f4f3322012-01-18 22:29:561429 surface_id,
[email protected]310ebd6302011-10-10 19:06:281430 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461431 frame_name,
1432 1);
[email protected]8ab04652010-06-12 02:47:261433 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521434
[email protected]007a848b2009-10-26 15:55:461435 // Record whether the creator frame is trying to suppress the opener field.
1436 view->opener_suppressed_ = opener_suppressed;
1437
[email protected]48c9cf2d2009-09-16 16:47:521438 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411439 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521440 if (!creator_url.is_valid() || !creator_url.IsStandard())
1441 creator_url = GURL();
1442 view->creator_url_ = creator_url;
1443
1444 // Copy over the alternate error page URL so we can have alt error pages in
1445 // the new render view (we don't need the browser to send the URL back down).
1446 view->alternate_error_page_url_ = alternate_error_page_url_;
1447
1448 return view->webview();
1449}
1450
[email protected]310ebd6302011-10-10 19:06:281451WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]380244092011-10-07 17:26:271452 RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521453 return widget->webwidget();
1454}
1455
[email protected]310ebd6302011-10-10 19:06:281456WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441457 // TODO(jcivelli): Remove this deprecated method when its been removed from
1458 // the WebViewClient interface. It's been replaced by
1459 // createExternalPopupMenu.
1460 NOTREACHED();
1461 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521462}
1463
[email protected]310ebd6302011-10-10 19:06:281464WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081465 const WebPopupMenuInfo& popup_menu_info,
1466 WebExternalPopupMenuClient* popup_menu_client) {
1467 DCHECK(!external_popup_menu_.get());
1468 external_popup_menu_.reset(
1469 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1470 return external_popup_menu_.get();
1471}
1472
[email protected]310ebd6302011-10-10 19:06:281473RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521474 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531475 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421476 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411477 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531478 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271479 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391480 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561481 return widget;
[email protected]79c7bed2010-09-14 22:28:391482}
1483
[email protected]310ebd6302011-10-10 19:06:281484WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1485 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341486 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391487 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291488 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1489 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1490 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341491}
1492
[email protected]7e8b4d12012-01-20 23:39:511493WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]01e69032012-01-31 05:39:061494 const WebGraphicsContext3D::Attributes& attributes,
[email protected]7e8b4d12012-01-20 23:39:511495 bool direct) {
1496 if (!webview())
1497 return NULL;
1498 // The WebGraphicsContext3DInProcessImpl code path is used for
1499 // layout tests (though not through this code) as well as for
1500 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511501 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571502 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
1503 attributes, webview(), direct);
[email protected]7e8b4d12012-01-20 23:39:511504 } else {
[email protected]56200f012012-02-03 23:13:571505 scoped_ptr<WebGraphicsContext3D> context(
1506 new WebGraphicsContext3DCommandBufferImpl());
1507 if (!context->initialize(attributes, webview(), direct))
1508 return NULL;
1509 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511510 }
[email protected]7e8b4d12012-01-20 23:39:511511}
1512
[email protected]310ebd6302011-10-10 19:06:281513void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521514 const WebConsoleMessage& message, const WebString& source_name,
1515 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081516 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511517 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081518 case WebConsoleMessage::LevelTip:
1519 log_severity = logging::LOG_VERBOSE;
1520 break;
1521 case WebConsoleMessage::LevelLog:
1522 log_severity = logging::LOG_INFO;
1523 break;
1524 case WebConsoleMessage::LevelWarning:
1525 log_severity = logging::LOG_WARNING;
1526 break;
1527 case WebConsoleMessage::LevelError:
1528 log_severity = logging::LOG_ERROR;
1529 break;
1530 default:
1531 NOTREACHED();
1532 }
1533
[email protected]48c9cf2d2009-09-16 16:47:521534 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081535 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311536 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521537 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311538 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521539}
1540
[email protected]310ebd6302011-10-10 19:06:281541void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421542 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521543}
1544
[email protected]310ebd6302011-10-10 19:06:281545WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511546 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021547}
1548
[email protected]310ebd6302011-10-10 19:06:281549bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121550 const WebString& path,
1551 WebFileChooserCompletion* chooser_completion) {
1552 int id = enumeration_completion_id_++;
1553 enumeration_completions_[id] = chooser_completion;
1554 return Send(new ViewHostMsg_EnumerateDirectory(
1555 routing_id_,
1556 id,
1557 webkit_glue::WebStringToFilePath(path)));
1558}
1559
[email protected]310ebd6302011-10-10 19:06:281560void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521561 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141562 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521563 return;
1564 }
1565
1566 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521567
1568 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311569
1570 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521571}
1572
[email protected]310ebd6302011-10-10 19:06:281573void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521574 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141575 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521576 return;
1577 }
1578
1579 is_loading_ = false;
1580
1581 // NOTE: For now we're doing the safest thing, and sending out notification
1582 // when done loading. This currently isn't an issue as the favicon is only
1583 // displayed when done loading. Ideally we would send notification when
1584 // finished parsing the head, but webkit doesn't support that yet.
1585 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521586 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1587
[email protected]90109412010-12-15 17:14:241588 if (load_progress_tracker_ != NULL)
1589 load_progress_tracker_->DidStopLoading();
1590
[email protected]93b9d692011-04-13 00:44:311591 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521592}
1593
[email protected]310ebd6302011-10-10 19:06:281594void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1595 double load_progress) {
[email protected]90109412010-12-15 17:14:241596 if (load_progress_tracker_ != NULL)
1597 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1598}
1599
[email protected]310ebd6302011-10-10 19:06:281600bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061601#if defined(OS_MACOSX)
1602 return true;
1603#else
1604 return false;
1605#endif
1606}
1607
[email protected]310ebd6302011-10-10 19:06:281608bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031609#if defined(OS_WIN)
1610 return true;
1611#else
1612 return false;
1613#endif
1614}
1615
[email protected]310ebd6302011-10-10 19:06:281616void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081617 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031618 return;
[email protected]4fb60142011-08-09 02:22:081619 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011620
[email protected]b781ff282011-08-20 06:19:361621 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031622}
1623
[email protected]310ebd6302011-10-10 19:06:281624void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121625 const std::string& name = UTF16ToUTF8(command_name);
1626 if (StartsWithASCII(name, "Move", true) ||
1627 StartsWithASCII(name, "Insert", true) ||
1628 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031629 return;
[email protected]f1a29a02011-10-06 23:08:441630 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031631}
1632
[email protected]310ebd6302011-10-10 19:06:281633bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101634 if (edit_commands_.empty())
1635 return false;
1636
[email protected]26aa0482009-09-30 16:55:271637 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101638 if (!frame)
1639 return false;
1640
1641 EditCommands::iterator it = edit_commands_.begin();
1642 EditCommands::iterator end = edit_commands_.end();
1643
[email protected]507b33ea2009-09-29 03:56:511644 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101645 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331646 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1647 // key (but it's the exception). Once one edit command is not executed, it
1648 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101649 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1650 WebString::fromUTF8(it->value)))
1651 break;
[email protected]507b33ea2009-09-29 03:56:511652 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101653 }
1654
[email protected]507b33ea2009-09-29 03:56:511655 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101656}
1657
[email protected]310ebd6302011-10-10 19:06:281658bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351659 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471660 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351661 // Do not open the file dialog in a hidden RenderView.
1662 if (is_hidden())
1663 return false;
[email protected]8caadeb2011-11-22 02:45:231664 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261665 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231666 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261667 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231668 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501669 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231670 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261671 else
[email protected]8caadeb2011-11-22 02:45:231672 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471673 ipc_params.title = params.title;
1674 ipc_params.default_file_name =
1675 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461676 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1677 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1678 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471679
1680 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461681}
1682
[email protected]269f86d2011-12-07 02:43:471683void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1684 const WebString& message) {
1685 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411686 message,
1687 string16(),
[email protected]b6cb3a842011-06-24 18:28:411688 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521689 NULL);
1690}
1691
[email protected]269f86d2011-12-07 02:43:471692bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1693 const WebString& message) {
1694 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411695 message,
1696 string16(),
[email protected]b6cb3a842011-06-24 18:28:411697 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521698 NULL);
1699}
1700
[email protected]269f86d2011-12-07 02:43:471701bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1702 const WebString& message,
1703 const WebString& default_value,
1704 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411705 string16 result;
[email protected]269f86d2011-12-07 02:43:471706 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411707 message,
1708 default_value,
[email protected]b6cb3a842011-06-24 18:28:411709 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521710 &result);
1711 if (ok)
[email protected]4f5ce842011-05-27 19:34:411712 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521713 return ok;
1714}
1715
[email protected]310ebd6302011-10-10 19:06:281716bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521717 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151718 // If we are swapping out, we have already run the beforeunload handler.
1719 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1720 // at all, to avoid running it twice.
1721 if (is_swapped_out_)
1722 return true;
1723
[email protected]48c9cf2d2009-09-16 16:47:521724 bool success = false;
1725 // This is an ignored return value, but is included so we can accept the same
1726 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411727 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211728 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411729 routing_id_, frame->document().url(), message,
1730 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521731 return success;
1732}
1733
[email protected]310ebd6302011-10-10 19:06:281734void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441735 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291736 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371737
1738 // frame is NULL if invoked by BlockedPlugin.
1739 if (frame)
1740 params.frame_id = frame->identifier();
1741
[email protected]db803aae2011-03-05 02:00:421742 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271743 // it. We replace it with an empty GURL so the appropriate items are disabled
1744 // in the context menu.
1745 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1746 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421747 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271748 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101749 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291750 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441751}
1752
[email protected]310ebd6302011-10-10 19:06:281753void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261754 // TODO(darin): Remove once WebKit roll is complete.
1755 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471756}
1757
[email protected]310ebd6302011-10-10 19:06:281758void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261759 // TODO(darin): Remove once WebKit roll is complete.
1760 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471761}
1762
[email protected]310ebd6302011-10-10 19:06:281763void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521764}
1765
[email protected]310ebd6302011-10-10 19:06:281766void RenderViewImpl::UpdateTargetURL(const GURL& url,
1767 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581768 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521769 if (latest_url == target_url_)
1770 return;
[email protected]163f8242009-10-30 20:19:551771
[email protected]48c9cf2d2009-09-16 16:47:521772 // Tell the browser to display a destination link.
1773 if (target_url_status_ == TARGET_INFLIGHT ||
1774 target_url_status_ == TARGET_PENDING) {
1775 // If we have a request in-flight, save the URL to be sent when we
1776 // receive an ACK to the in-flight request. We can happily overwrite
1777 // any existing pending sends.
1778 pending_target_url_ = latest_url;
1779 target_url_status_ = TARGET_PENDING;
1780 } else {
[email protected]c85f0212011-11-04 16:54:411781 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1782 // see |ParamTraits<GURL>|.
1783 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1784 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521785 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1786 target_url_ = latest_url;
1787 target_url_status_ = TARGET_INFLIGHT;
1788 }
1789}
1790
[email protected]310ebd6302011-10-10 19:06:281791void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311792 int delay;
1793 if (send_content_state_immediately_)
1794 delay = 0;
1795 else if (is_hidden())
1796 delay = kDelaySecondsForContentStateSyncHidden;
1797 else
1798 delay = kDelaySecondsForContentStateSync;
1799
1800 if (nav_state_sync_timer_.IsRunning()) {
1801 // The timer is already running. If the delay of the timer maches the amount
1802 // we want to delay by, then return. Otherwise stop the timer so that it
1803 // gets started with the right delay.
1804 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1805 return;
1806 nav_state_sync_timer_.Stop();
1807 }
1808
[email protected]d323a172011-09-02 18:23:021809 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281810 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311811}
1812
[email protected]310ebd6302011-10-10 19:06:281813void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551814 mouse_over_url_ = GURL(url);
1815 UpdateTargetURL(mouse_over_url_, focus_url_);
1816}
1817
[email protected]310ebd6302011-10-10 19:06:281818void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551819 focus_url_ = GURL(url);
1820 UpdateTargetURL(focus_url_, mouse_over_url_);
1821}
1822
[email protected]310ebd6302011-10-10 19:06:281823void RenderViewImpl::startDragging(const WebDragData& data,
1824 WebDragOperationsMask mask,
1825 const WebImage& image,
1826 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411827#if WEBKIT_USING_SKIA
1828 SkBitmap bitmap(image.getSkBitmap());
1829#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331830 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411831#endif
1832
[email protected]59f4f2fa2011-03-23 01:00:551833 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521834 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411835 mask,
1836 bitmap,
1837 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521838}
1839
[email protected]310ebd6302011-10-10 19:06:281840bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451841 return renderer_preferences_.can_accept_load_drops;
1842}
1843
[email protected]310ebd6302011-10-10 19:06:281844void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521845 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1846}
1847
[email protected]310ebd6302011-10-10 19:06:281848void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521849 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1850}
1851
[email protected]310ebd6302011-10-10 19:06:281852void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511853 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071854
[email protected]38b592902011-04-16 02:08:421855 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491856}
1857
[email protected]169d4282011-11-30 19:33:591858void RenderViewImpl::didUpdateLayout() {
1859 // We don't always want to set up a timer, only if we've been put in that
1860 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1861 // message.
1862 if (!send_preferred_size_changes_ || !webview())
1863 return;
1864
1865 if (check_preferred_size_timer_.IsRunning())
1866 return;
1867 check_preferred_size_timer_.Start(FROM_HERE,
1868 TimeDelta::FromMilliseconds(0), this,
1869 &RenderViewImpl::CheckPreferredSize);
1870}
1871
[email protected]310ebd6302011-10-10 19:06:281872void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521873 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1874}
1875
[email protected]310ebd6302011-10-10 19:06:281876int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001877 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521878}
1879
[email protected]310ebd6302011-10-10 19:06:281880int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001881 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521882}
1883
[email protected]310ebd6302011-10-10 19:06:281884void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321885 const WebAccessibilityObject& obj,
1886 WebAccessibilityNotification notification) {
1887 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1888}
1889
[email protected]310ebd6302011-10-10 19:06:281890void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141891 const WebString& value) {
1892 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1893 key.utf8(),
1894 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261895}
1896
[email protected]79dbc662009-09-04 05:42:511897// WebKit::WebWidgetClient ----------------------------------------------------
1898
[email protected]310ebd6302011-10-10 19:06:281899void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121900 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1901 // we won't have to test for user gesture anymore and we can
1902 // move that code back to render_widget.cc
1903 if (webview() && webview()->mainFrame() &&
1904 webview()->mainFrame()->isProcessingUserGesture()) {
1905 Send(new ViewHostMsg_Focus(routing_id_));
1906 }
1907}
1908
[email protected]310ebd6302011-10-10 19:06:281909void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121910 // TODO(jcivelli): see TODO above in didFocus().
1911 if (webview() && webview()->mainFrame() &&
1912 webview()->mainFrame()->isProcessingUserGesture()) {
1913 Send(new ViewHostMsg_Blur(routing_id_));
1914 }
1915}
1916
initial.commit09911bf2008-07-26 23:55:291917// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281918// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291919// point to dispatch the ShowView message.
1920//
1921// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281922// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291923//
[email protected]310ebd6302011-10-10 19:06:281924void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291925 DCHECK(!did_show_) << "received extraneous Show call";
1926 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1927
1928 if (did_show_)
1929 return;
1930 did_show_ = true;
1931
[email protected]6779aa12011-03-29 17:32:241932 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041933 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041934
[email protected]28295ec2009-10-16 05:34:331935 // Force new windows to a popup if they were not opened with a user gesture.
1936 if (!opened_by_user_gesture_) {
1937 // We exempt background tabs for compat with older versions of Chrome.
1938 // TODO(darin): This seems bogus. These should have a user gesture, so
1939 // we probably don't need this check.
1940 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1941 policy = WebKit::WebNavigationPolicyNewPopup;
1942 }
1943
initial.commit09911bf2008-07-26 23:55:291944 // NOTE: initial_pos_ may still have its default values at this point, but
1945 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1946 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281947 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1948 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291949 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241950 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291951}
1952
[email protected]310ebd6302011-10-10 19:06:281953void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:291954 DCHECK(did_show_) << "should already have shown the view";
1955
[email protected]c1f50aa2010-02-18 03:46:571956 // We must keep WebKit's shared timer running in this case in order to allow
1957 // showModalDialog to function properly.
1958 //
1959 // TODO(darin): WebKit should really be smarter about suppressing events and
1960 // timers so that we do not need to manage the shared timer in such a heavy
1961 // handed manner.
1962 //
[email protected]f1a29a02011-10-06 23:08:441963 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1964 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:571965
[email protected]12636df2009-09-28 22:32:211966 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291967}
1968
[email protected]2b624c562011-10-27 22:58:261969bool RenderViewImpl::enterFullScreen() {
1970 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1971 return true;
1972}
1973
1974void RenderViewImpl::exitFullScreen() {
1975 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1976}
1977
[email protected]217690d2012-01-27 07:33:111978bool RenderViewImpl::requestPointerLock() {
1979 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
1980}
1981
1982void RenderViewImpl::requestPointerUnlock() {
1983 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
1984}
1985
1986bool RenderViewImpl::isPointerLocked() {
1987 return mouse_lock_dispatcher_->IsMouseLockedTo(
1988 webwidget_mouse_lock_target_.get());
1989}
1990
[email protected]3d9689372009-09-10 04:29:171991// WebKit::WebFrameClient -----------------------------------------------------
1992
[email protected]310ebd6302011-10-10 19:06:281993WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
1994 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:551995 WebPlugin* plugin = NULL;
1996 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
1997 this, frame, params, &plugin)) {
1998 return plugin;
1999 }
2000
[email protected]a813c8e2011-10-08 01:34:112001 webkit::WebPluginInfo info;
2002 std::string mime_type;
2003 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2004 params.mimeType.utf8(), &info, &mime_type);
2005 if (!found)
2006 return NULL;
2007
2008 WebPluginParams params_to_use = params;
2009 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312010 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172011}
2012
[email protected]310ebd6302011-10-10 19:06:282013WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422014 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372015 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422016
[email protected]30447b62009-11-13 01:13:372017 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512018 bool exists = false;
[email protected]30447b62009-11-13 01:13:372019 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512020 ViewHostMsg_CreateWorker_Params params;
2021 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512022 params.name = name;
2023 params.document_id = document_id;
2024 params.render_view_route_id = routing_id_;
2025 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232026 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372027 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512028 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372029 if (url_mismatch) {
2030 return NULL;
2031 } else {
[email protected]f1a29a02011-10-06 23:08:442032 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492033 document_id,
[email protected]6de0bcf2010-02-17 22:00:512034 exists,
[email protected]30447b62009-11-13 01:13:372035 route_id,
2036 routing_id_);
2037 }
[email protected]9c00f002009-11-05 22:37:422038}
2039
[email protected]310ebd6302011-10-10 19:06:282040WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172041 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442042 FOR_EACH_OBSERVER(
2043 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172044
[email protected]bb6fd402011-12-09 02:45:442045 media::MessageLoopFactory* message_loop_factory =
2046 new media::MessageLoopFactoryImpl();
2047 media::FilterCollection* collection = new media::FilterCollection();
2048 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372049
[email protected]9e2269d2012-01-07 00:06:212050 RenderAudioSourceProvider* audio_source_provider = NULL;
2051
[email protected]3d9689372009-09-10 04:29:172052 // Add in any custom filter factories first.
2053 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2054 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212055 // audio_source_provider is a "provider" to WebKit, and a sink
2056 // from the perspective of the audio renderer.
2057 audio_source_provider = new RenderAudioSourceProvider();
2058
2059 // Add the chrome specific audio renderer, using audio_source_provider
2060 // as the sink.
2061 AudioRendererImpl* audio_renderer =
2062 new AudioRendererImpl(audio_source_provider);
2063 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172064 }
2065
[email protected]e1d69d762011-12-13 05:12:182066#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
2067 // Currently only cros/arm has any HW video decode support in
2068 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2069 // platforms. This is a startup-time optimization. When new VDA
2070 // implementations are added, relax the #if above.
2071 WebKit::WebGraphicsContext3D* wk_context3d = webview()->graphicsContext3D();
2072 if (wk_context3d) {
2073 WebGraphicsContext3DCommandBufferImpl* context3d =
2074 static_cast<WebGraphicsContext3DCommandBufferImpl*>(wk_context3d);
2075 GpuChannelHost* gpu_channel_host =
2076 RenderThreadImpl::current()->EstablishGpuChannelSync(
2077 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2078 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312079 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
2080 new RendererGpuVideoDecoderFactories(
2081 gpu_channel_host, context3d->context()->AsWeakPtr())));
[email protected]e1d69d762011-12-13 05:12:182082 }
2083#endif
2084
[email protected]da952fd2012-01-13 03:49:252085 webkit_media::WebMediaPlayerImpl* media_player =
2086 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2087 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
2088 message_loop_factory, media_stream_impl_.get(), render_media_log);
2089 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562090 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252091 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]9e2269d2012-01-07 00:06:212092 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]bb6fd402011-12-09 02:45:442093 }
[email protected]cec4eb82012-01-12 17:51:562094 return media_player;
[email protected]3d9689372009-09-10 04:29:172095}
2096
[email protected]310ebd6302011-10-10 19:06:282097WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212098 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232099 if (!frame || !frame->view())
2100 return NULL;
[email protected]035545f2010-04-09 13:10:212101 return new RendererWebApplicationCacheHostImpl(
2102 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442103 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212104}
2105
[email protected]310ebd6302011-10-10 19:06:282106WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382107 return &cookie_jar_;
2108}
2109
[email protected]310ebd6302011-10-10 19:06:282110void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512111 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452112}
2113
[email protected]310ebd6302011-10-10 19:06:282114void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512115 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172116}
2117
[email protected]310ebd6302011-10-10 19:06:282118void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172119 WebFrame* frame, const WebURLRequest& request,
2120 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342121 loadURLExternally(frame, request, policy, WebString());
2122}
2123
[email protected]310ebd6302011-10-10 19:06:282124void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342125 WebFrame* frame, const WebURLRequest& request,
2126 WebNavigationPolicy policy,
2127 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592128 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2129 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342130 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2131 suggested_name));
[email protected]efce17b2009-09-11 18:04:592132 } else {
[email protected]445e1042011-12-03 21:03:152133 OpenURL(frame, request.url(),
2134 Referrer(referrer, getReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592135 }
[email protected]3d9689372009-09-10 04:29:172136}
2137
[email protected]310ebd6302011-10-10 19:06:282138WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172139 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222140 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152141 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2142 if (is_swapped_out_) {
2143 DCHECK(request.url() == GURL("about:swappedout"));
2144 return default_policy;
2145 }
2146
[email protected]3d9689372009-09-10 04:29:172147 // Webkit is asking whether to navigate to a new URL.
2148 // This is fine normally, except if we're showing UI from one security
2149 // context and they're trying to navigate to a different context.
2150 const GURL& url = request.url();
2151
[email protected]d19ea342011-04-20 20:31:132152 // A content initiated navigation may have originated from a link-click,
2153 // script, drag-n-drop operation, etc.
2154 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072155 DocumentState::FromDataSource(frame->provisionalDataSource())->
2156 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132157
[email protected]a8c269a2011-10-25 20:17:222158 // Experimental:
2159 // If --enable-strict-site-isolation is enabled, send all top-level
2160 // navigations to the browser to let it swap processes when crossing site
2161 // boundaries. This is currently expected to break some script calls and
2162 // navigations, such as form submissions.
2163 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102164 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2165 !frame->parent() && (is_content_initiated || is_redirect)) {
2166 WebString origin_str = frame->document().securityOrigin().toString();
2167 GURL frame_url(origin_str.utf8().data());
2168 // TODO(cevans): revisit whether this origin check is still necessary once
2169 // crbug.com/101395 is fixed.
2170 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]445e1042011-12-03 21:03:152171 Referrer referrer(
2172 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2173 getReferrerPolicyFromRequest(request));
[email protected]313b80bd2011-11-23 03:49:102174 OpenURL(frame, url, referrer, default_policy);
2175 return WebKit::WebNavigationPolicyIgnore;
2176 }
[email protected]a8c269a2011-10-25 20:17:222177 }
2178
[email protected]3d9689372009-09-10 04:29:172179 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302180 // navigations.
[email protected]5f000f272012-01-19 05:25:082181 if (is_content_initiated) {
2182 bool browser_handles_top_level_requests =
2183 renderer_preferences_.browser_handles_top_level_requests &&
2184 IsNonLocalTopLevelNavigation(url, frame, type);
2185 if (browser_handles_top_level_requests ||
2186 renderer_preferences_.browser_handles_all_requests) {
2187 Referrer referrer(
2188 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2189 getReferrerPolicyFromRequest(request));
2190 // Reset these counters as the RenderView could be reused for the next
2191 // navigation.
2192 page_id_ = -1;
2193 last_page_id_sent_to_browser_ = -1;
2194 OpenURL(frame, url, referrer, default_policy);
2195 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2196 }
[email protected]3d9689372009-09-10 04:29:172197 }
2198
[email protected]6101c342010-12-16 22:44:372199 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552200 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572201 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372202 // opening a new window). But we sometimes navigate to about:blank to clear a
2203 // tab, and we want to still allow that.
2204 //
[email protected]8f4da8c2011-02-09 19:49:572205 // Note: we do this only for GET requests because our mechanism for switching
2206 // processes only issues GET requests. In particular, POST requests don't
2207 // work, because this mechanism does not preserve form POST data. If it
2208 // becomes necessary to support process switching for POST requests, we will
2209 // need to send the request's httpBody data up to the browser process, and
2210 // issue a special POST navigation in WebKit (via
2211 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2212 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222213 if (!frame->parent() && is_content_initiated &&
[email protected]6101c342010-12-16 22:44:372214 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2215 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2216 bool send_referrer = false;
2217 bool should_fork =
[email protected]e091df82011-10-11 18:13:212218 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172219 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372220 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112221
[email protected]e48869a2011-04-01 19:56:032222 if (!should_fork) {
2223 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362224 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032225 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362226 frame, url, is_content_initiated, is_initial_navigation,
2227 &send_referrer);
[email protected]6101c342010-12-16 22:44:372228 }
2229
2230 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152231 Referrer referrer(
2232 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2233 getReferrerPolicyFromRequest(request));
2234 OpenURL(
2235 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112236 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2237 }
[email protected]3d9689372009-09-10 04:29:172238 }
2239
[email protected]43763f982011-08-26 18:33:402240 // Use the frame's original request's URL rather than the document's URL for
2241 // this check. For a popup, the document's URL may become the opener window's
2242 // URL if the opener has called document.write. See http://crbug.com/93517.
2243 GURL old_url(frame->dataSource()->request().url());
2244
[email protected]3d9689372009-09-10 04:29:172245 // Detect when a page is "forking" a new tab that can be safely rendered in
2246 // its own process. This is done by sites like Gmail that try to open links
2247 // in new windows without script connections back to the original page. We
2248 // treat such cases as browser navigations (in which we will create a new
2249 // renderer for a cross-site navigation), rather than WebKit navigations.
2250 //
2251 // We use the following heuristic to decide whether to fork a new page in its
2252 // own process:
2253 // The parent page must open a new tab to about:blank, set the new tab's
2254 // window.opener to null, and then redirect the tab to a cross-site URL using
2255 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462256 //
2257 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2258 // (see below).
[email protected]3d9689372009-09-10 04:29:172259 bool is_fork =
2260 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582261 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172262 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522263 historyBackListCount() < 1 &&
2264 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172265 // The parent page must have set the child's window.opener to null before
2266 // redirecting to the desired URL.
2267 frame->opener() == NULL &&
2268 // Must be a top-level frame.
2269 frame->parent() == NULL &&
2270 // Must not have issued the request from this page.
2271 is_content_initiated &&
2272 // Must be targeted at the current tab.
2273 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2274 // Must be a JavaScript navigation, which appears as "other".
2275 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462276
2277 // Recognize if this navigation is from a link with rel=noreferrer and
2278 // target=_blank attributes, in which case the opener will be suppressed. If
2279 // so, it is safe to load cross-site pages in a separate process, so we
2280 // should let the browser handle it.
2281 bool is_noreferrer_and_blank_target =
2282 // Frame should be top level and not yet navigated.
2283 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412284 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462285 historyBackListCount() < 1 &&
2286 historyForwardListCount() < 1 &&
2287 // Links with rel=noreferrer will have no Referer field, and their
2288 // resulting frame will have its window.opener suppressed.
2289 // TODO(creis): should add a request.httpReferrer() method to help avoid
2290 // typos on the unusual spelling of Referer.
2291 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2292 opener_suppressed_ &&
2293 frame->opener() == NULL &&
2294 // Links with target=_blank will have no name.
2295 frame->name().isNull() &&
2296 // Another frame (with a non-empty creator) should have initiated the
2297 // request, targeted at this frame.
2298 !creator_url_.is_empty() &&
2299 is_content_initiated &&
2300 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2301 type == WebKit::WebNavigationTypeOther;
2302
2303 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172304 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152305 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172306 return WebKit::WebNavigationPolicyIgnore;
2307 }
2308
2309 return default_policy;
2310}
2311
[email protected]310ebd6302011-10-10 19:06:282312bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492313 WebFrame* frame, const WebURLRequest& request) {
2314 // We allow WebKit to think that everything can be handled even though
2315 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342316 return true;
2317}
2318
[email protected]310ebd6302011-10-10 19:06:282319WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492320 WebFrame* frame, const WebURLRequest& request) {
2321 NOTREACHED(); // Since we said we can handle all requests.
2322 return WebURLError();
2323}
2324
[email protected]310ebd6302011-10-10 19:06:282325WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492326 WebFrame* frame, const WebURLRequest& request) {
2327 WebURLError error;
2328 error.domain = WebString::fromUTF8(net::kErrorDomain);
2329 error.reason = net::ERR_ABORTED;
2330 error.unreachableURL = request.url();
2331 return error;
[email protected]7b7a7dc2009-10-19 02:23:342332}
2333
[email protected]310ebd6302011-10-10 19:06:282334void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492335 WebFrame*, const WebURLError&) {
2336 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342337}
2338
[email protected]310ebd6302011-10-10 19:06:282339void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432340 const WebKit::WebFormElement& form) {
2341 // Some login forms have onSubmit handlers that put a hash of the password
2342 // into a hidden field and then clear the password. (Issue 28910.)
2343 // This method gets called before any of those handlers run, so save away
2344 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072345 DocumentState* document_state =
2346 DocumentState::FromDataSource(frame->dataSource());
2347 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432348 PasswordFormDomManager::CreatePasswordForm(form));
2349}
2350
[email protected]310ebd6302011-10-10 19:06:282351void RenderViewImpl::willSubmitForm(WebFrame* frame,
2352 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072353 DocumentState* document_state =
2354 DocumentState::FromDataSource(frame->provisionalDataSource());
2355 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172356
[email protected]2905f742011-10-13 03:51:582357 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2358 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172359
2360 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352361 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072362 document_state->set_searchable_form_url(web_searchable_form_data.url());
2363 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212364 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432365 PasswordForm* password_form_data =
2366 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072367 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432368
[email protected]098c95cb2011-04-28 16:49:012369 // In order to save the password that the user actually typed and not one
2370 // that may have gotten transformed by the site prior to submit, recover it
2371 // from the form contents already stored by |willSendSubmitEvent| into the
2372 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2373 // which is what we're storing into now.)
2374 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072375 DocumentState* old_document_state =
2376 DocumentState::FromDataSource(frame->dataSource());
2377 if (old_document_state) {
2378 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432379 if (old_form_data && old_form_data->action == password_form_data->action)
2380 password_form_data->password_value = old_form_data->password_value;
2381 }
2382 }
[email protected]3d9689372009-09-10 04:29:172383
[email protected]2a5b1732011-04-01 23:55:552384 FOR_EACH_OBSERVER(
2385 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172386}
2387
[email protected]310ebd6302011-10-10 19:06:282388void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172389 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2390 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382391 FOR_EACH_OBSERVER(
2392 RenderViewObserver, observers_,
2393 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172394}
2395
[email protected]310ebd6302011-10-10 19:06:282396void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382397 FOR_EACH_OBSERVER(
2398 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172399}
2400
[email protected]310ebd6302011-10-10 19:06:282401void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172402 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152403 if (!frame->parent()) {
2404 WebDataSource* ds = frame->provisionalDataSource();
2405 // If there's no provisional data source, it's a reference fragment
2406 // navigation.
2407 completed_client_redirect_src_ = Referrer(
2408 from, ds ? getReferrerPolicyFromRequest(ds->request()) :
2409 frame->referrerPolicy());
2410 }
[email protected]eb0bff942011-04-07 22:08:382411 FOR_EACH_OBSERVER(
2412 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172413}
2414
[email protected]310ebd6302011-10-10 19:06:282415void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072416 DocumentState* document_state = DocumentState::FromDataSource(ds);
2417 if (!document_state) {
2418 document_state = new DocumentState;
2419 ds->setExtraData(document_state);
2420 }
2421
[email protected]3d9689372009-09-10 04:29:172422 // The rest of RenderView assumes that a WebDataSource will always have a
2423 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072424 bool content_initiated = !pending_navigation_params_.get();
2425 if (content_initiated)
2426 document_state->set_navigation_state(
2427 NavigationState::CreateContentInitiated());
2428 else
2429 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512430
[email protected]007733c2011-11-17 00:34:072431 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512432 // navigating from a page that used prefetching using a link on that
2433 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072434 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512435 // this value appropriately.
2436 // TODO(gavinp): catch the important case of navigation in a new
2437 // renderer process.
2438 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302439 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522440 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512441 const GURL referrer(
2442 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2443 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072444 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512445 old_frame->dataSource())->was_prefetcher()) {
2446 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2447 WebDataSource* old_frame_ds = old_frame->dataSource();
2448 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072449 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512450 break;
2451 }
2452 }
2453 }
2454 }
2455 }
2456
[email protected]4c1b6f0b2010-02-07 16:38:182457 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522458 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512459 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182460 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072461 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182462 break;
2463 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072464 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182465 break;
2466 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072467 document_state->set_load_type(
2468 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182469 break;
2470 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072471 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182472 break;
2473 }
2474 }
[email protected]fa7b6b542009-11-03 05:02:302475
[email protected]946a0032011-03-31 18:42:282476 FOR_EACH_OBSERVER(
2477 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172478}
2479
[email protected]007733c2011-11-17 00:34:072480void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2481 DocumentState* document_state) {
2482 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2483
2484 if (document_state->request_time().is_null())
2485 document_state->set_request_time(params.request_time);
2486
2487 // A navigation resulting from loading a javascript URL should not be treated
2488 // as a browser initiated event. Instead, we want it to look as if the page
2489 // initiated any load resulting from JS execution.
2490 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2491 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2492 params.page_id,
2493 params.pending_history_list_offset,
2494 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482495 navigation_state->set_transferred_request_child_id(
2496 params.transferred_request_child_id);
2497 navigation_state->set_transferred_request_request_id(
2498 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072499 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2500 // We're doing a load of a page that was restored from the last session.
2501 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2502 // which can result in stale data for pages that are set to expire. We
2503 // explicitly override that by setting the policy here so that as
2504 // necessary we load from the network.
2505 document_state->set_cache_policy_override(
2506 WebURLRequest::UseProtocolCachePolicy);
2507 }
2508 document_state->set_navigation_state(navigation_state);
2509 } else {
2510 document_state->set_navigation_state(
2511 NavigationState::CreateContentInitiated());
2512 }
2513
2514 if (IsReload(params))
2515 document_state->set_load_type(DocumentState::RELOAD);
2516 else if (!params.state.empty())
2517 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2518 else
2519 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2520
2521 pending_navigation_params_.reset();
2522}
2523
[email protected]310ebd6302011-10-10 19:06:282524void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172525 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072526 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172527
[email protected]3d9689372009-09-10 04:29:172528 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072529 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172530 double event_time = ds->triggeringEventTime();
2531 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072532 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172533 }
2534
[email protected]05c8e502010-08-15 15:13:522535 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072536 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522537
[email protected]3d9689372009-09-10 04:29:172538 bool is_top_most = !frame->parent();
2539 if (is_top_most) {
2540 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132541 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172542
2543 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152544 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172545 } else if (frame->parent()->isLoading()) {
2546 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002547 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072548 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582549 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172550 }
2551
[email protected]28685da92011-02-07 21:49:172552 FOR_EACH_OBSERVER(
2553 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2554
[email protected]3d9689372009-09-10 04:29:172555 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592556 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262557 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172558}
2559
[email protected]310ebd6302011-10-10 19:06:282560void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2561 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172562 if (frame->parent())
2563 return;
2564 // Received a redirect on the main frame.
2565 WebDataSource* data_source = frame->provisionalDataSource();
2566 if (!data_source) {
2567 // Should only be invoked when we have a data source.
2568 NOTREACHED();
2569 return;
2570 }
2571 std::vector<GURL> redirects;
2572 GetRedirectChain(data_source, &redirects);
2573 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512574 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592575 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172576 }
2577}
2578
[email protected]310ebd6302011-10-10 19:06:282579void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2580 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172581 // Notify the browser that we failed a provisional load with an error.
2582 //
2583 // Note: It is important this notification occur before DidStopLoading so the
2584 // SSL manager can react to the provisional load failure before being
2585 // notified the load stopped.
2586 //
2587 WebDataSource* ds = frame->provisionalDataSource();
2588 DCHECK(ds);
2589
2590 const WebURLRequest& failed_request = ds->request();
2591
[email protected]28685da92011-02-07 21:49:172592 FOR_EACH_OBSERVER(
2593 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2594
[email protected]3d9689372009-09-10 04:29:172595 bool show_repost_interstitial =
2596 (error.reason == net::ERR_CACHE_MISS &&
2597 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582598
2599 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2600 params.frame_id = frame->identifier();
2601 params.is_main_frame = !frame->parent();
2602 params.error_code = error.reason;
2603 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2604 failed_request,
2605 error,
2606 NULL,
2607 &params.error_description);
2608 params.url = error.unreachableURL;
2609 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172610 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582611 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172612
2613 // Don't display an error page if this is simply a cancelled load. Aside
2614 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2615 if (error.reason == net::ERR_ABORTED)
2616 return;
[email protected]b553edd52012-01-10 12:15:232617 // Don't display an error message if the request was handled by an
2618 // external protocol handler.
2619 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2620 return;
[email protected]3d9689372009-09-10 04:29:172621
2622 // Make sure we never show errors in view source mode.
2623 frame->enableViewSourceMode(false);
2624
[email protected]007733c2011-11-17 00:34:072625 DocumentState* document_state = DocumentState::FromDataSource(ds);
2626 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172627
2628 // If this is a failed back/forward/reload navigation, then we need to do a
2629 // 'replace' load. This is necessary to avoid messing up session history.
2630 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2631 // as session history is concerned.
2632 //
2633 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2634 // the page id.
2635 //
2636 bool replace =
2637 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582638 navigation_state->transition_type() ==
2639 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172640
2641 // If we failed on a browser initiated request, then make sure that our error
2642 // page load is regarded as the same browser initiated request.
2643 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072644 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2645 pending_navigation_params_->page_id =
2646 navigation_state->pending_page_id();
2647 pending_navigation_params_->pending_history_list_offset =
2648 navigation_state->pending_history_list_offset();
2649 pending_navigation_params_->transition =
2650 navigation_state->transition_type();
2651 pending_navigation_params_->request_time =
2652 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172653 }
2654
2655 // Provide the user with a more helpful error page?
2656 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2657 return;
2658
2659 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082660 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172661}
2662
[email protected]310ebd6302011-10-10 19:06:282663void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172664 WebFrame* frame, const char* data, size_t data_len,
2665 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072666 DocumentState* document_state =
2667 DocumentState::FromDataSource(frame->dataSource());
2668 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172669}
2670
[email protected]310ebd6302011-10-10 19:06:282671void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2672 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072673 DocumentState* document_state =
2674 DocumentState::FromDataSource(frame->dataSource());
2675 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172676
[email protected]007733c2011-11-17 00:34:072677 if (document_state->commit_load_time().is_null())
2678 document_state->set_commit_load_time(Time::Now());
2679
[email protected]3d9689372009-09-10 04:29:172680 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202681 // When we perform a new navigation, we need to update the last committed
2682 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172683 UpdateSessionHistory(frame);
2684
2685 // We bump our Page ID to correspond with the new session history entry.
2686 page_id_ = next_page_id_++;
2687
[email protected]3cc72b12010-03-18 23:03:002688 // Advance our offset in session history, applying the length limit. There
2689 // is now no forward history.
2690 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102691 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2692 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002693 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032694 history_page_ids_.resize(history_list_length_, -1);
2695 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172696 } else {
2697 // Inspect the navigation_state on this frame to see if the navigation
2698 // corresponds to a session history navigation... Note: |frame| may or
2699 // may not be the toplevel frame, but for the case of capturing session
2700 // history, the first committed frame suffices. We keep track of whether
2701 // we've seen this commit before so that only capture session history once
2702 // per navigation.
2703 //
2704 // Note that we need to check if the page ID changed. In the case of a
2705 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2706 // previous URL and the current page ID, which would be wrong.
2707 if (navigation_state->pending_page_id() != -1 &&
2708 navigation_state->pending_page_id() != page_id_ &&
2709 !navigation_state->request_committed()) {
2710 // This is a successful session history navigation!
2711 UpdateSessionHistory(frame);
2712 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002713
2714 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032715
2716 // If the history list is valid, our list of page IDs should be correct.
2717 DCHECK(history_list_length_ <= 0 ||
2718 history_list_offset_ < 0 ||
2719 history_list_offset_ >= history_list_length_ ||
2720 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172721 }
2722 }
2723
[email protected]28685da92011-02-07 21:49:172724 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2725 DidCommitProvisionalLoad(frame, is_new_navigation));
2726
[email protected]3d9689372009-09-10 04:29:172727 // Remember that we've already processed this request, so we don't update
2728 // the session history again. We do this regardless of whether this is
2729 // a session history navigation, because if we attempted a session history
2730 // navigation without valid HistoryItem state, WebCore will think it is a
2731 // new navigation.
2732 navigation_state->set_request_committed(true);
2733
2734 UpdateURL(frame);
2735
2736 // If this committed load was initiated by a client redirect, we're
2737 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152738 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172739
2740 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272741 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172742}
2743
[email protected]310ebd6302011-10-10 19:06:282744void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102745 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2746 DidClearWindowObject(frame));
2747
[email protected]b6cb3a842011-06-24 18:28:412748 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212749 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252750 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2751 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272752 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172753 }
[email protected]766a7082012-02-03 23:39:152754
2755 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
2756 if (!dom_automation_controller_.get())
2757 dom_automation_controller_.reset(new DomAutomationController());
2758 dom_automation_controller_->set_message_sender(
2759 static_cast<content::RenderView*>(this));
2760 dom_automation_controller_->set_routing_id(routing_id());
2761 dom_automation_controller_->BindToJavascript(frame,
2762 "domAutomationController");
2763 }
[email protected]3d9689372009-09-10 04:29:172764}
2765
[email protected]310ebd6302011-10-10 19:06:282766void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172767 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412768 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252769 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272770 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172771 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2772 }
[email protected]e48869a2011-04-01 19:56:032773
2774 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2775 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172776}
2777
[email protected]310ebd6302011-10-10 19:06:282778void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2779 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462780 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172781
2782 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272783 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172784}
2785
[email protected]310ebd6302011-10-10 19:06:282786void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132787 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2788 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582789}
2790
[email protected]310ebd6302011-10-10 19:06:282791void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172792 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072793 DocumentState* document_state = DocumentState::FromDataSource(ds);
2794 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172795
[email protected]622474d2010-11-04 09:21:082796 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172797
[email protected]28685da92011-02-07 21:49:172798 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2799 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172800
2801 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272802 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172803}
2804
[email protected]310ebd6302011-10-10 19:06:282805void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082806 if (webview()->mainFrame() == frame) {
2807 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2808 page_id_));
2809 }
[email protected]3d9689372009-09-10 04:29:172810}
2811
[email protected]310ebd6302011-10-10 19:06:282812void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312813 WebDataSource* ds = frame->dataSource();
2814 DCHECK(ds);
2815
2816
[email protected]28685da92011-02-07 21:49:172817 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312818
2819 const WebURLRequest& failed_request = ds->request();
2820 string16 error_description;
2821 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2822 failed_request,
2823 error,
2824 NULL,
2825 &error_description);
2826 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2827 frame->identifier(),
2828 failed_request.url(),
2829 !frame->parent(),
2830 error.reason,
2831 error_description));
[email protected]3d9689372009-09-10 04:29:172832}
2833
[email protected]310ebd6302011-10-10 19:06:282834void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172835 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072836 DocumentState* document_state = DocumentState::FromDataSource(ds);
2837 if (document_state->finish_load_time().is_null())
2838 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412839
[email protected]676126f72011-01-15 00:03:512840 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172841
[email protected]1a55c5be2011-11-29 11:36:312842 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2843 frame->identifier(),
2844 ds->request().url(),
2845 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172846}
2847
[email protected]310ebd6302011-10-10 19:06:282848void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172849 WebFrame* frame, bool is_new_navigation) {
2850 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072851 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172852 // update the ExtraData on the datasource so that others who read the
2853 // ExtraData will get the new NavigationState. Similarly, if we did not
2854 // initiate this navigation, then we need to take care to reset any pre-
2855 // existing navigation state to a content-initiated navigation state.
2856 // DidCreateDataSource conveniently takes care of this for us.
2857 didCreateDataSource(frame, frame->dataSource());
2858
[email protected]007733c2011-11-17 00:34:072859 DocumentState* document_state =
2860 DocumentState::FromDataSource(frame->dataSource());
2861 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092862 new_state->set_was_within_same_page(true);
2863
[email protected]3d9689372009-09-10 04:29:172864 didCommitProvisionalLoad(frame, is_new_navigation);
2865
[email protected]750fcf872011-08-03 23:10:472866 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2867 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172868}
2869
[email protected]310ebd6302011-10-10 19:06:282870void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312871 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592872}
2873
[email protected]310ebd6302011-10-10 19:06:282874void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172875 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2876 // Ignore
2877}
2878
[email protected]310ebd6302011-10-10 19:06:282879void RenderViewImpl::willSendRequest(WebFrame* frame,
2880 unsigned identifier,
2881 WebURLRequest& request,
2882 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302883 WebFrame* top_frame = frame->top();
2884 if (!top_frame)
2885 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512886 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2887 WebDataSource* top_data_source = top_frame->dataSource();
2888 WebDataSource* data_source =
2889 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222890
[email protected]78d5cfe2011-02-04 08:43:222891 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032892 GURL new_url;
2893 if (content::GetContentClient()->renderer()->WillSendRequest(
2894 frame, request_url, &new_url)) {
2895 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222896 }
2897
[email protected]2905f742011-10-13 03:51:582898 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072899 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2900 NavigationState* navigation_state = document_state->navigation_state();
2901 if (document_state) {
2902 if (document_state->is_cache_policy_override_set())
2903 request.setCachePolicy(document_state->cache_policy_override());
2904 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:302905 }
[email protected]8a3125a712010-08-09 18:58:512906
[email protected]91043a8232011-11-04 16:41:192907 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:062908 new RequestExtraData(frame->referrerPolicy(),
2909 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:192910 frame->identifier(),
2911 frame->parent() == top_frame,
2912 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:482913 transition_type,
2914 navigation_state->transferred_request_child_id(),
2915 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:572916
[email protected]007733c2011-11-17 00:34:072917 DocumentState* top_document_state =
2918 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:572919 // TODO(gavinp): separate out prefetching and prerender field trials
2920 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:072921 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:572922 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2923 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:072924 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512925
[email protected]3d9689372009-09-10 04:29:172926 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132927 request.setHasUserGesture(frame->isProcessingUserGesture());
2928
[email protected]0a8db0d2011-04-13 15:15:402929 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132930 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172931}
2932
[email protected]310ebd6302011-10-10 19:06:282933void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:172934 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492935
[email protected]3d9689372009-09-10 04:29:172936 // Only do this for responses that correspond to a provisional data source
2937 // of the top-most frame. If we have a provisional data source, then we
2938 // can't have any sub-resources yet, so we know that this response must
2939 // correspond to a frame load.
2940 if (!frame->provisionalDataSource() || frame->parent())
2941 return;
2942
2943 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082944 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172945 if (frame->isViewSourceModeEnabled())
2946 return;
2947
[email protected]007733c2011-11-17 00:34:072948 DocumentState* document_state =
2949 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:082950 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532951
[email protected]972ebdff2010-06-10 22:59:072952 // Record page load flags.
[email protected]007733c2011-11-17 00:34:072953 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2954 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
2955 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:572956 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:072957 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
2958 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092959 // Whether or not the http status code actually corresponds to an error is
2960 // only checked when the page is done loading, if |use_error_page| is
2961 // still true.
[email protected]007733c2011-11-17 00:34:072962 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172963}
2964
[email protected]310ebd6302011-10-10 19:06:282965void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:172966 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:072967 DocumentState* document_state =
2968 DocumentState::FromDataSource(frame->dataSource());
2969 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172970 return;
2971
[email protected]7bfc153f2011-09-23 22:00:202972 // Do not show error page when DevTools is attached.
2973 if (devtools_agent_->IsAttached())
2974 return;
2975
[email protected]06333afe2011-02-24 14:55:092976 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:072977 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:082978 if (http_status_code == 404) {
2979 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412980 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172981
[email protected]b6cb3a842011-06-24 18:28:412982 const GURL& error_page_url =
2983 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092984 if (error_page_url.is_valid()) {
2985 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472986 original_error.domain = "http";
2987 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412988 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172989
[email protected]007733c2011-11-17 00:34:072990 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:092991 new AltErrorPageResourceFetcher(
2992 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:082993 base::Bind(&RenderViewImpl::AltErrorPageFinished,
2994 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:092995 return;
2996 }
2997 }
[email protected]3d9689372009-09-10 04:29:172998
[email protected]e6a2ce52011-10-08 01:40:132999 std::string error_domain;
3000 if (content::GetContentClient()->renderer()->HasErrorPage(
3001 http_status_code, &error_domain)) {
3002 WebURLError error;
3003 error.unreachableURL = frame->document().url();
3004 error.domain = WebString::fromUTF8(error_domain);
3005 error.reason = http_status_code;
3006
3007 LoadNavigationErrorPage(
3008 frame, frame->dataSource()->request(), error, std::string(), true);
3009 }
[email protected]3d9689372009-09-10 04:29:173010}
3011
[email protected]310ebd6302011-10-10 19:06:283012void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173013 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3014 // Ignore
3015}
3016
[email protected]310ebd6302011-10-10 19:06:283017void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173018 WebFrame* frame, const WebURLRequest& request,
3019 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003020 // The recipients of this message have no use for data: URLs: they don't
3021 // affect the page's insecure content list and are not in the disk cache. To
3022 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3023 // filter them out here.
3024 GURL url(request.url());
3025 if (url.SchemeIs("data"))
3026 return;
3027
[email protected]3d9689372009-09-10 04:29:173028 // Let the browser know we loaded a resource from the memory cache. This
3029 // message is needed to display the correct SSL indicators.
3030 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3031 routing_id_,
[email protected]84703292011-10-28 20:44:003032 url,
[email protected]70435962011-08-02 20:13:283033 response.securityInfo(),
3034 request.httpMethod().utf8(),
3035 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173036}
3037
[email protected]310ebd6302011-10-10 19:06:283038void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293039 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3040}
3041
[email protected]310ebd6302011-10-10 19:06:283042void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023043 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293044 Send(new ViewHostMsg_DidRunInsecureContent(
3045 routing_id_,
[email protected]92771112011-01-20 00:13:023046 origin.toString().utf8(),
3047 target));
[email protected]e3d60e5d2009-09-25 21:08:293048}
3049
[email protected]310ebd6302011-10-10 19:06:283050void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033051 webkit_glue::WebURLLoaderImpl* loader_impl =
3052 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3053 loader_impl->UpdateRoutingId(routing_id_);
3054}
3055
[email protected]310ebd6302011-10-10 19:06:283056void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173057 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3058}
3059
[email protected]310ebd6302011-10-10 19:06:283060void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3061 v8::Handle<v8::Context> context,
3062 int world_id) {
[email protected]5bc10932011-09-21 21:03:303063 content::GetContentClient()->renderer()->DidCreateScriptContext(
3064 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283065}
3066
[email protected]310ebd6302011-10-10 19:06:283067void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3068 v8::Handle<v8::Context> context,
3069 int world_id) {
[email protected]5bc10932011-09-21 21:03:303070 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3071 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283072}
3073
[email protected]310ebd6302011-10-10 19:06:283074void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073075 // We don't always want to send the change messages over IPC, only if we've
3076 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3077 // message.
3078 if (!send_preferred_size_changes_ || !webview())
3079 return;
3080
[email protected]705243f2010-05-05 19:58:073081 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3082 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533083
3084 // In the presence of zoom, these sizes are still reported as if unzoomed,
3085 // so we need to adjust.
3086 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3087 size.set_width(static_cast<int>(size.width() * zoom_factor));
3088 size.set_height(static_cast<int>(size.height() * zoom_factor));
3089
[email protected]6b5576cb2011-12-05 08:23:003090 if (!size.height())
3091 size.set_height(preferred_size_.height());
3092
[email protected]705243f2010-05-05 19:58:073093 if (size == preferred_size_)
3094 return;
[email protected]c27324b2009-11-19 22:44:293095
[email protected]705243f2010-05-05 19:58:073096 preferred_size_ = size;
3097 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3098 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173099}
3100
[email protected]273558fb2012-01-12 15:03:513101void RenderViewImpl::EnsureMediaStreamImpl() {
3102#if defined(ENABLE_P2P_APIS)
3103 if (!p2p_socket_dispatcher_)
3104 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3105#endif
3106
3107 if (!media_stream_dispatcher_)
3108 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3109
3110 if (!media_stream_impl_.get()) {
3111 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3112 media_stream_impl_ = new MediaStreamImpl(
3113 media_stream_dispatcher_,
3114 p2p_socket_dispatcher_,
3115 RenderThreadImpl::current()->video_capture_impl_manager(),
3116 factory);
3117 }
3118}
3119
[email protected]310ebd6302011-10-10 19:06:283120void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3121 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313122 if (webview()->mainFrame() != frame)
3123 return;
3124 WebView* frameView = frame->view();
3125 if (!frameView)
3126 return;
3127
3128 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3129 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3130
3131 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3132 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3133 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3134 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3135
3136 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3137 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3138 }
3139}
3140
[email protected]310ebd6302011-10-10 19:06:283141void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313142 WebSize offset = frame->scrollOffset();
3143 WebSize minimum_offset = frame->minimumScrollOffset();
3144 WebSize maximum_offset = frame->maximumScrollOffset();
3145
3146 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3147 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3148
3149 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3150 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3151 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3152 routing_id_, is_pinned_to_left, is_pinned_to_right));
3153
3154 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3155 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3156 }
3157}
3158
[email protected]310ebd6302011-10-10 19:06:283159void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493160 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313161
3162 if (webview()->mainFrame() == frame)
3163 UpdateScrollState(frame);
3164}
3165
[email protected]310ebd6302011-10-10 19:06:283166void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313167 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493168}
3169
[email protected]310ebd6302011-10-10 19:06:283170void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3171 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113172 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3173 if (!count)
3174 active_match_ordinal = 0;
3175
3176 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3177 routing_id_,
3178 request_id,
3179 count,
3180 gfx::Rect(),
3181 active_match_ordinal,
3182 final_update);
3183
[email protected]8922e1f2009-10-03 05:01:263184 // If we have a message that has been queued up, then we should just replace
3185 // it. The ACK from the browser will make sure it gets sent when the browser
3186 // wants it.
3187 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263188 queued_find_reply_message_.reset(msg);
3189 } else {
3190 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113191 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263192 }
3193}
3194
[email protected]310ebd6302011-10-10 19:06:283195void RenderViewImpl::reportFindInPageSelection(int request_id,
3196 int active_match_ordinal,
3197 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263198 // Send the search result over to the browser process.
3199 Send(new ViewHostMsg_Find_Reply(routing_id_,
3200 request_id,
3201 -1,
3202 selection_rect,
3203 active_match_ordinal,
3204 false));
3205}
3206
[email protected]310ebd6302011-10-10 19:06:283207void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223208 WebFrame* frame,
3209 WebFileSystem::Type type,
3210 long long size,
[email protected]d275d7a2010-11-03 01:34:493211 bool create,
[email protected]2b06a992010-08-21 05:48:223212 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083213 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223214
[email protected]b6cb3a842011-06-24 18:28:413215 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563216 if (origin.isUnique()) {
3217 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083218 callbacks->didFail(WebKit::WebFileErrorAbort);
3219 return;
3220 }
[email protected]2b06a992010-08-21 05:48:223221
[email protected]c5a272d2010-09-27 18:37:083222 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3223 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493224 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223225}
3226
[email protected]310ebd6302011-10-10 19:06:283227void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403228 WebFrame* frame,
3229 WebStorageQuotaType type,
3230 WebStorageQuotaCallbacks* callbacks) {
3231 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413232 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563233 if (origin.isUnique()) {
3234 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403235 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3236 return;
3237 }
3238 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533239 GURL(origin.toString()),
3240 static_cast<quota::StorageType>(type),
3241 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403242}
3243
[email protected]310ebd6302011-10-10 19:06:283244void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403245 WebFrame* frame,
3246 WebStorageQuotaType type,
3247 unsigned long long requested_size,
3248 WebStorageQuotaCallbacks* callbacks) {
3249 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413250 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563251 if (origin.isUnique()) {
3252 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403253 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3254 return;
3255 }
3256 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533257 routing_id(), GURL(origin.toString()),
3258 static_cast<quota::StorageType>(type), requested_size,
3259 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403260}
3261
[email protected]8b5af492011-11-28 21:50:583262void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153263 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063264 string16 title = service.title();
3265 if (title.empty())
3266 title = webview()->mainFrame()->document().title();
3267
[email protected]8b5af492011-11-28 21:50:583268 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3269 service.action(),
3270 service.type(),
3271 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063272 title,
[email protected]8b5af492011-11-28 21:50:583273 service.disposition()));
3274}
3275
[email protected]ffc8bed2012-01-21 01:23:153276void RenderViewImpl::dispatchIntent(
3277 WebFrame* frame, const WebIntentRequest& intentRequest) {
3278 webkit_glue::WebIntentData intent_data(intentRequest.intent());
3279 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583280 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153281 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583282}
3283
[email protected]18d5be92011-07-25 18:00:193284// WebKit::WebPageSerializerClient implementation ------------------------------
3285
[email protected]310ebd6302011-10-10 19:06:283286void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193287 const WebURL& frame_url,
3288 const WebCString& data,
3289 WebPageSerializerClient::PageSerializationStatus status) {
3290 Send(new ViewHostMsg_SendSerializedHtmlData(
3291 routing_id(),
3292 frame_url,
3293 data.data(),
3294 static_cast<int32>(status)));
3295}
3296
[email protected]a2ef54c2011-10-10 16:20:313297// content::RenderView implementation ------------------------------------------
3298
[email protected]310ebd6302011-10-10 19:06:283299bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313300 return RenderWidget::Send(message);
3301}
3302
[email protected]310ebd6302011-10-10 19:06:283303int RenderViewImpl::GetRoutingId() const {
[email protected]a2ef54c2011-10-10 16:20:313304 return routing_id_;
3305}
3306
[email protected]310ebd6302011-10-10 19:06:283307int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313308 return page_id_;
3309}
3310
[email protected]310ebd6302011-10-10 19:06:283311gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313312 return size();
3313}
3314
[email protected]310ebd6302011-10-10 19:06:283315gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313316 return host_window();
3317}
3318
[email protected]310ebd6302011-10-10 19:06:283319WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313320 return webkit_preferences_;
3321}
3322
[email protected]310ebd6302011-10-10 19:06:283323WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313324 return webview();
3325}
3326
[email protected]310ebd6302011-10-10 19:06:283327WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313328 if (!webview())
3329 return WebNode();
3330 WebFrame* focused_frame = webview()->focusedFrame();
3331 if (focused_frame) {
3332 WebDocument doc = focused_frame->document();
3333 if (!doc.isNull())
3334 return doc.focusedNode();
3335 }
3336
3337 return WebNode();
3338}
3339
[email protected]310ebd6302011-10-10 19:06:283340WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313341 return context_menu_node_;
3342}
3343
[email protected]310ebd6302011-10-10 19:06:283344bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313345 bool is_editable_node = false;
3346 if (!node.isNull()) {
3347 if (node.isContentEditable()) {
3348 is_editable_node = true;
3349 } else if (node.isElementNode()) {
3350 is_editable_node =
3351 node.toConst<WebElement>().isTextFormControlElement();
3352 }
3353 }
3354 return is_editable_node;
3355}
3356
[email protected]310ebd6302011-10-10 19:06:283357WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313358 WebKit::WebFrame* frame,
3359 const webkit::WebPluginInfo& info,
3360 const WebKit::WebPluginParams& params) {
3361 bool pepper_plugin_was_registered = false;
3362 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3363 pepper_delegate_.CreatePepperPluginModule(info,
3364 &pepper_plugin_was_registered));
3365 if (pepper_plugin_was_registered) {
3366 if (!pepper_module)
3367 return NULL;
3368 return new webkit::ppapi::WebPluginImpl(
3369 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3370 }
3371
[email protected]34b27e442012-01-20 20:07:413372#if defined(USE_AURA)
3373 return NULL;
3374#else
[email protected]a2ef54c2011-10-10 16:20:313375 return new webkit::npapi::WebPluginImpl(
3376 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413377#endif
[email protected]a2ef54c2011-10-10 16:20:313378}
3379
[email protected]310ebd6302011-10-10 19:06:283380void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3381 const string16& jscript,
3382 int id,
3383 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313384 v8::Handle<v8::Value> result;
3385 WebFrame* web_frame = GetChildFrame(frame_xpath);
3386 if (web_frame)
3387 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3388 if (notify_result) {
3389 ListValue list;
3390 if (!result.IsEmpty() && web_frame) {
3391 v8::HandleScope handle_scope;
3392 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3393 v8::Context::Scope context_scope(context);
3394 V8ValueConverterImpl converter;
3395 converter.set_allow_date(true);
3396 converter.set_allow_regexp(true);
3397 list.Set(0, converter.FromV8Value(result, context));
3398 } else {
3399 list.Set(0, Value::CreateNullValue());
3400 }
3401 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3402 }
3403}
3404
[email protected]310ebd6302011-10-10 19:06:283405bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313406 return (!send_preferred_size_changes_ ||
3407 (disable_scrollbars_size_limit_.width() <= width ||
3408 disable_scrollbars_size_limit_.height() <= height));
3409}
3410
[email protected]310ebd6302011-10-10 19:06:283411int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313412 return enabled_bindings_;
3413}
3414
[email protected]310ebd6302011-10-10 19:06:283415bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313416 return send_content_state_immediately_;
3417}
3418
[email protected]310ebd6302011-10-10 19:06:283419float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313420 return filtered_time_per_frame();
3421}
3422
[email protected]310ebd6302011-10-10 19:06:283423void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3424 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313425 showContextMenu(frame, data);
3426}
3427
[email protected]310ebd6302011-10-10 19:06:283428WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313429 return visibilityState();
3430}
3431
[email protected]310ebd6302011-10-10 19:06:283432void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3433 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313434 return runModalAlertDialog(frame, message);
3435}
3436
[email protected]310ebd6302011-10-10 19:06:283437void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313438 WebKit::WebFrame* frame,
3439 const WebKit::WebURLRequest& request,
3440 WebKit::WebNavigationPolicy policy) {
3441 loadURLExternally(frame, request, policy);
3442}
3443
3444// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513445
[email protected]310ebd6302011-10-10 19:06:283446webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533447 const FilePath& file_path,
3448 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593449 if (!PluginChannelHost::IsListening())
3450 return NULL;
3451
[email protected]00c39612010-03-06 02:53:283452 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463453 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323454#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223455 return webkit::npapi::WebPluginDelegateImpl::Create(
3456 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093457#else
[email protected]7398dcc2011-09-06 21:40:323458 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223459 NOTIMPLEMENTED();
3460 return NULL;
[email protected]7b6616f2010-01-14 18:07:553461#endif
[email protected]f103ab72009-09-02 17:10:593462 }
3463
[email protected]4e0616e2010-05-28 14:55:533464 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593465}
3466
[email protected]310ebd6302011-10-10 19:06:283467void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033468#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273469 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593470#endif
3471}
3472
[email protected]310ebd6302011-10-10 19:06:283473void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033474#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273475 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593476#endif
3477 CleanupWindowInPluginMoves(window);
3478}
3479
[email protected]310ebd6302011-10-10 19:06:283480void RenderViewImpl::DidMovePlugin(
3481 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593482 SchedulePluginMove(move);
3483}
3484
[email protected]310ebd6302011-10-10 19:06:283485void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593486 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523487 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593488}
3489
[email protected]310ebd6302011-10-10 19:06:283490void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593491 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523492 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593493}
3494
[email protected]310ebd6302011-10-10 19:06:283495WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513496 return &cookie_jar_;
3497}
3498
[email protected]a9288f52011-11-17 05:18:163499void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073500 Send(new ViewHostMsg_MediaNotification(routing_id_,
3501 reinterpret_cast<int64>(player),
3502 player->hasVideo(),
3503 player->hasAudio(),
3504 true));
3505}
3506
[email protected]a9288f52011-11-17 05:18:163507void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073508 Send(new ViewHostMsg_MediaNotification(routing_id_,
3509 reinterpret_cast<int64>(player),
3510 player->hasVideo(),
3511 player->hasAudio(),
3512 false));
3513}
3514
[email protected]a9288f52011-11-17 05:18:163515void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073516 DidPause(player);
3517}
3518
[email protected]310ebd6302011-10-10 19:06:283519void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293520 if (!webview())
3521 return;
3522
[email protected]26aa0482009-09-30 16:55:273523 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173524 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293525 return;
[email protected]ca948a22009-06-25 19:36:173526
3527 Send(new ViewHostMsg_UpdateState(
3528 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293529}
3530
[email protected]310ebd6302011-10-10 19:06:283531void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363532 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003533 if (!frame)
3534 return;
[email protected]b781ff282011-08-20 06:19:363535
[email protected]b781ff282011-08-20 06:19:363536 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003537 if (!webview()->caretOrSelectionRange(&location, &length))
3538 return;
3539
3540 string16 text;
3541 size_t offset;
3542 ui::Range range(location, location + length);
3543
3544 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3545 // If current focused element is editable, we will send 100 more chars
3546 // before and after selection. It is for input method surrounding text
3547 // feature.
3548 if (location > kExtraCharsBeforeAndAfterSelection)
3549 offset = location - kExtraCharsBeforeAndAfterSelection;
3550 else
3551 offset = 0;
3552 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3553 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3554 if (!webrange.isNull())
3555 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3556 } else {
3557 offset = location;
3558 text = frame->selectionAsText();
[email protected]e8cdf3532011-10-29 00:50:523559 // http://crbug.com/101435
3560 // In some case, frame->selectionAsText() returned text's length is not
3561 // equal to the length returned from webview()->caretOrSelectionRange().
3562 // So we have to set the range according to text.length().
3563 range.set_end(range.start() + text.length());
[email protected]b781ff282011-08-20 06:19:363564 }
3565
[email protected]b781ff282011-08-20 06:19:363566 // Sometimes we get repeated didChangeSelection calls from webkit when
3567 // the selection hasn't actually changed. We don't want to report these
3568 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003569 if (selection_text_offset_ != offset ||
3570 selection_range_ != range ||
3571 selection_text_ != text) {
3572 selection_text_ = text;
3573 selection_text_offset_ = offset;
3574 selection_range_ = range;
3575 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3576 }
[email protected]b781ff282011-08-20 06:19:363577}
3578
[email protected]310ebd6302011-10-10 19:06:283579GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3580 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553581 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293582 // If the URL that failed was secure, then the embedding web page was not
3583 // expecting a network attacker to be able to manipulate its contents. As
3584 // we fetch alternate error pages over HTTP, we would be allowing a network
3585 // attacker to manipulate the contents of the response if we tried to use
3586 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153587 return GURL();
initial.commit09911bf2008-07-26 23:55:293588 }
3589
3590 // Grab the base URL from the browser process.
3591 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153592 return GURL();
initial.commit09911bf2008-07-26 23:55:293593
3594 // Strip query params from the failed URL.
3595 GURL::Replacements remove_params;
3596 remove_params.ClearUsername();
3597 remove_params.ClearPassword();
3598 remove_params.ClearQuery();
3599 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553600 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503601 std::string spec_to_send = url_to_send.spec();
3602 // Notify link doctor of the url truncation by sending of "?" at the end.
3603 if (failed_url.has_query())
3604 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293605
3606 // Construct the query params to send to link doctor.
3607 std::string params(alternate_error_page_url_.query());
3608 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023609 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293610 params.append("&sourceid=chrome");
3611 params.append("&error=");
3612 switch (error_type) {
3613 case DNS_ERROR:
3614 params.append("dnserror");
3615 break;
3616
3617 case HTTP_404:
3618 params.append("http404");
3619 break;
3620
[email protected]5df266ac2008-10-15 19:50:133621 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333622 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133623 break;
3624
initial.commit09911bf2008-07-26 23:55:293625 default:
3626 NOTREACHED() << "unknown ErrorPageType";
3627 }
3628
3629 // OK, build the final url to return.
3630 GURL::Replacements link_doctor_params;
3631 link_doctor_params.SetQueryStr(params);
3632 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3633 return url;
3634}
3635
[email protected]310ebd6302011-10-10 19:06:283636GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593637 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3638 return GURL();
3639 else
3640 return creator_url_;
3641}
3642
[email protected]310ebd6302011-10-10 19:06:283643WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273644 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313645 web_ui_bindings_.reset(new WebUIBindings(
3646 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463647 }
[email protected]c50008512011-02-03 01:17:273648 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463649}
3650
[email protected]310ebd6302011-10-10 19:06:283651WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013652 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493653}
3654
[email protected]310ebd6302011-10-10 19:06:283655void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3656 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273657 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493658
[email protected]872542532011-06-23 00:43:163659 // Check if the plugin still exists in the document.
3660 if (main_frame->document().isPluginDocument() &&
3661 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493662 if (options.findNext) {
3663 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013664 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493665 } else {
[email protected]afdbd142010-07-10 08:01:233666 if (GetWebPluginFromPluginDocument()->startFind(
3667 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493668 } else {
[email protected]e7c58a32010-08-13 19:47:113669 // Send "no results".
3670 Send(new ViewHostMsg_Find_Reply(routing_id_,
3671 request_id,
3672 0,
3673 gfx::Rect(),
3674 0,
3675 true));
[email protected]24a7f3c2010-03-25 08:26:493676 }
3677 }
3678 return;
3679 }
3680
[email protected]b4bb2502009-10-01 22:35:273681 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273682 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293683 WebFrame* search_frame = focused_frame; // start searching focused frame.
3684
3685 bool multi_frame = (frame_after_main != main_frame);
3686
3687 // If we have multiple frames, we don't want to wrap the search within the
3688 // frame, so we check here if we only have main_frame in the chain.
3689 bool wrap_within_frame = !multi_frame;
3690
[email protected]b3f2b912009-04-09 16:18:523691 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293692 bool result = false;
3693
[email protected]7830da3e2009-11-06 16:27:263694 // If something is selected when we start searching it means we cannot just
3695 // increment the current match ordinal; we need to re-generate it.
3696 WebRange current_selection = focused_frame->selectionRange();
3697
initial.commit09911bf2008-07-26 23:55:293698 do {
[email protected]dd7daa82009-08-10 05:46:453699 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593700 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293701
3702 if (!result) {
3703 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223704 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293705
3706 // Find the next frame, but skip the invisible ones.
3707 do {
3708 // What is the next frame to search? (we might be going backwards). Note
3709 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593710 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273711 search_frame->traverseNext(true) :
3712 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453713 } while (!search_frame->hasVisibleContent() &&
3714 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293715
[email protected]884db412008-11-24 23:46:503716 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223717 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293718
3719 // If we have multiple frames and we have wrapped back around to the
3720 // focused frame, we need to search it once more allowing wrap within
3721 // the frame, otherwise it will report 'no match' if the focused frame has
3722 // reported matches, but no frames after the focused_frame contain a
3723 // match for the search word(s).
3724 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453725 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593726 request_id, search_text, options, true, // Force wrapping.
3727 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293728 }
3729 }
3730
[email protected]26aa0482009-09-30 16:55:273731 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293732 } while (!result && search_frame != focused_frame);
3733
[email protected]7830da3e2009-11-06 16:27:263734 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293735 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453736 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293737 } else {
3738 // If nothing is found, set result to "0 of 0", otherwise, set it to
3739 // "-1 of 1" to indicate that we found at least one item, but we don't know
3740 // yet what is active.
3741 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3742 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293743
[email protected]4f3dc372009-02-24 00:10:293744 // If we find no matches then this will be our last status update.
3745 // Otherwise the scoping effort will send more results.
3746 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293747
[email protected]4f3dc372009-02-24 00:10:293748 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403749 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593750 request_id,
[email protected]4f3dc372009-02-24 00:10:293751 match_count,
3752 selection_rect,
3753 ordinal,
3754 final_status_update));
initial.commit09911bf2008-07-26 23:55:293755
initial.commit09911bf2008-07-26 23:55:293756 // Scoping effort begins, starting with the mainframe.
3757 search_frame = main_frame;
3758
[email protected]dd7daa82009-08-10 05:46:453759 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293760
3761 do {
3762 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453763 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293764
3765 // We don't start another scoping effort unless at least one match has
3766 // been found.
3767 if (result) {
3768 // Start new scoping request. If the scoping function determines that it
3769 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453770 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593771 search_text,
3772 options,
initial.commit09911bf2008-07-26 23:55:293773 true); // reset the tickmarks
3774 }
3775
3776 // Iterate to the next frame. The frame will not necessarily scope, for
3777 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273778 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293779 } while (search_frame != main_frame);
3780 }
3781}
3782
[email protected]815dd9872011-11-23 18:40:303783void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493784 WebView* view = webview();
3785 if (!view)
3786 return;
3787
3788 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163789 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013790 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493791 return;
3792 }
3793
[email protected]815dd9872011-11-23 18:40:303794 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493795 if (clear_selection)
3796 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3797
3798 WebFrame* frame = view->mainFrame();
3799 while (frame) {
3800 frame->stopFinding(clear_selection);
3801 frame = frame->traverseNext(false);
3802 }
3803
[email protected]815dd9872011-11-23 18:40:303804 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493805 WebFrame* focused_frame = view->focusedFrame();
3806 if (focused_frame) {
3807 WebDocument doc = focused_frame->document();
3808 if (!doc.isNull()) {
3809 WebNode node = doc.focusedNode();
3810 if (!node.isNull())
3811 node.simulateClick();
3812 }
3813 }
3814 }
3815}
3816
[email protected]310ebd6302011-10-10 19:06:283817void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493818 // Check if there is any queued up request waiting to be sent.
3819 if (queued_find_reply_message_.get()) {
3820 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423821 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493822 }
3823}
3824
[email protected]54087fe2011-10-28 22:02:483825void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513826 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3827 return;
3828
[email protected]258d31122010-05-09 10:59:413829 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103830
[email protected]b75b8292010-10-01 07:28:253831 double old_zoom_level = webview()->zoomLevel();
3832 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483833 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253834 zoom_level = 0;
3835 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3836 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483837 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253838 } else {
3839 // Either the user hit the zoom factor limit and thus the zoom level is now
3840 // not a whole number, or a plugin changed it to a custom value. We want
3841 // to go to the next whole number so that the user can always get back to
3842 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483843 if ((old_zoom_level > 1 && zoom > 0) ||
3844 (old_zoom_level < 1 && zoom < 0)) {
3845 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253846 } else {
3847 // We're going towards 100%, so first go to the next whole number.
3848 zoom_level = static_cast<int>(old_zoom_level);
3849 }
3850 }
[email protected]b75b8292010-10-01 07:28:253851 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413852 zoomLevelChanged();
3853}
3854
3855void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3856 int zoom_center_x, int zoom_center_y) {
3857 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3858 kScalingIncrementForGesture);
3859}
3860
3861void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3862 int zoom_center_x,
3863 int zoom_center_y,
3864 float scaling_increment) {
3865 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3866 return;
3867
[email protected]c514d6372011-08-16 22:54:443868 double old_page_scale_factor = webview()->pageScaleFactor();
3869 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:483870 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:443871 page_scale_factor = 1.0;
3872 } else {
3873 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:413874 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:443875 }
[email protected]47578fa02011-11-02 19:34:413876 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:093877 webview()->setPageScaleFactor(page_scale_factor,
3878 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:413879 }
[email protected]40bd6582009-12-04 23:49:513880}
3881
[email protected]310ebd6302011-10-10 19:06:283882void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173883 webview()->hidePopups();
3884 webview()->setZoomLevel(false, zoom_level);
3885 zoomLevelChanged();
3886}
3887
[email protected]310ebd6302011-10-10 19:06:283888void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3889 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543890 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293891}
3892
[email protected]310ebd6302011-10-10 19:06:283893void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273894 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293895}
3896
[email protected]310ebd6302011-10-10 19:06:283897void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273898 WebString no_encoding;
3899 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183900}
3901
[email protected]310ebd6302011-10-10 19:06:283902WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453903 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273904 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453905
3906 // xpath string can represent a frame deep down the tree (across multiple
3907 // frame DOMs).
3908 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3909 // should break into 2 xpaths
3910 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413911 std::vector<string16> xpaths;
3912 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453913
[email protected]26aa0482009-09-30 16:55:273914 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413915 for (std::vector<string16>::const_iterator i = xpaths.begin();
3916 frame && i != xpaths.end(); ++i) {
3917 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293918 }
3919
[email protected]dd7daa82009-08-10 05:46:453920 return frame;
initial.commit09911bf2008-07-26 23:55:293921}
3922
[email protected]310ebd6302011-10-10 19:06:283923void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
3924 const string16& jscript,
3925 int id,
3926 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:533927 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293928}
3929
[email protected]310ebd6302011-10-10 19:06:283930void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
3931 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413932 WebFrame* frame = GetChildFrame(frame_xpath);
3933 if (!frame)
[email protected]216813952011-05-19 22:21:263934 return;
[email protected]ae461542009-06-19 19:03:413935
[email protected]01cf589c2011-07-28 18:04:033936 frame->document().insertUserStyleSheet(
3937 WebString::fromUTF8(css),
3938 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483939}
3940
[email protected]310ebd6302011-10-10 19:06:283941void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:093942 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293943}
3944
[email protected]310ebd6302011-10-10 19:06:283945void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
3946 const std::string& value) {
[email protected]e091df82011-10-11 18:13:213947 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:273948 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293949}
3950
[email protected]310ebd6302011-10-10 19:06:283951void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
3952 const gfx::Point& client_point,
3953 const gfx::Point& screen_point,
3954 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553955 WebDragOperation operation = webview()->dragTargetDragEnter(
3956 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553957 client_point,
3958 screen_point,
3959 ops);
3960
3961 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3962}
3963
[email protected]310ebd6302011-10-10 19:06:283964void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
3965 const gfx::Point& screen_point,
3966 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553967 WebDragOperation operation = webview()->dragTargetDragOver(
3968 client_point,
3969 screen_point,
3970 ops);
3971
3972 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3973}
3974
[email protected]310ebd6302011-10-10 19:06:283975void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:553976 webview()->dragTargetDragLeave();
3977}
3978
[email protected]310ebd6302011-10-10 19:06:283979void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
3980 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:553981 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573982
3983 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553984}
3985
[email protected]310ebd6302011-10-10 19:06:283986void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3987 const gfx::Point& screen_point,
3988 bool ended,
3989 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033990 if (ended) {
[email protected]26aa0482009-09-30 16:55:273991 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203992 } else {
3993 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033994 }
initial.commit09911bf2008-07-26 23:55:293995}
3996
[email protected]310ebd6302011-10-10 19:06:283997void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273998 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293999}
4000
[email protected]310ebd6302011-10-10 19:06:284001void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594002 webkit_preferences_ = prefs;
4003 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294004}
4005
[email protected]310ebd6302011-10-10 19:06:284006void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294007 alternate_error_page_url_ = url;
4008}
4009
[email protected]310ebd6302011-10-10 19:06:284010void RenderViewImpl::OnCustomContextMenuAction(
[email protected]b29aa74b2011-01-31 21:41:084011 const webkit_glue::CustomContextMenuContext& custom_context,
4012 unsigned action) {
4013 if (custom_context.is_pepper_menu)
4014 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4015 else
4016 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584017 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4018 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334019}
4020
[email protected]310ebd6302011-10-10 19:06:284021void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514022 int id,
4023 const std::vector<FilePath>& paths) {
4024 if (!enumeration_completions_[id])
4025 return;
4026
4027 WebVector<WebString> ws_file_names(paths.size());
4028 for (size_t i = 0; i < paths.size(); ++i)
4029 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4030
4031 enumeration_completions_[id]->didChooseFile(ws_file_names);
4032 enumeration_completions_.erase(id);
4033}
4034
[email protected]310ebd6302011-10-10 19:06:284035void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364036 // This could happen if we navigated to a different page before the user
4037 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474038 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364039 return;
4040
[email protected]cdaf8d02010-03-30 19:52:474041 WebVector<WebString> ws_file_names(paths.size());
4042 for (size_t i = 0; i < paths.size(); ++i)
4043 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464044
[email protected]cdaf8d02010-03-30 19:52:474045 if (file_chooser_completions_.front()->completion)
4046 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4047 file_chooser_completions_.pop_front();
4048
4049 // If there are more pending file chooser requests, schedule one now.
4050 if (!file_chooser_completions_.empty()) {
4051 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4052 file_chooser_completions_.front()->params));
4053 }
initial.commit09911bf2008-07-26 23:55:294054}
4055
[email protected]244ac1892011-12-02 17:04:474056void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4057 const gfx::Size& max_size) {
4058 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4059 if (!webview())
4060 return;
4061 webview()->enableAutoResizeMode(true, min_size, max_size);
4062}
4063
[email protected]2bf834f2011-11-17 20:02:214064void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244065 if (send_preferred_size_changes_)
4066 return;
[email protected]9fb325e2010-05-06 18:23:244067 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394068
[email protected]d812fd12011-05-27 23:05:074069 // Start off with an initial preferred size notification (in case
4070 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594071 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084072}
4073
[email protected]310ebd6302011-10-10 19:06:284074void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104075 const gfx::Size& disable_scrollbar_size_limit) {
4076 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4077}
4078
[email protected]310ebd6302011-10-10 19:06:284079void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314080 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504081 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514082 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374083 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134084#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414085 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4086 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464087 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:514088 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344089 renderer_prefs.thumb_inactive_color,
4090 renderer_prefs.thumb_active_color,
4091 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324092
[email protected]644d77e2010-01-27 01:03:104093 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324094 webview()->setScrollbarColors(
4095 renderer_prefs.thumb_inactive_color,
4096 renderer_prefs.thumb_active_color,
4097 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104098 webview()->setSelectionColors(
4099 renderer_prefs.active_selection_bg_color,
4100 renderer_prefs.active_selection_fg_color,
4101 renderer_prefs.inactive_selection_bg_color,
4102 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464103 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104104 }
[email protected]7a74e102009-09-03 00:16:564105#endif
[email protected]d051d9a2011-12-10 02:02:504106 // If the zoom level for this page matches the old zoom default, and this
4107 // is not a plugin, update the zoom level to match the new default.
4108 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4109 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4110 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4111 zoomLevelChanged();
4112 }
[email protected]80d96fa2009-06-10 22:34:514113}
4114
[email protected]310ebd6302011-10-10 19:06:284115void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4116 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284117 if (webview())
4118 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564119}
4120
[email protected]81375e872012-01-11 21:40:364121void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4122 const WebPluginAction& action) {
4123 if (webview())
4124 webview()->performPluginAction(action, location);
4125}
4126
[email protected]310ebd6302011-10-10 19:06:284127void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194128 const GURL& page_url) {
4129 // Prepare list to storage all savable resource links.
4130 std::vector<GURL> resources_list;
4131 std::vector<GURL> referrers_list;
4132 std::vector<GURL> frames_list;
4133 webkit_glue::SavableResourcesResult result(&resources_list,
4134 &referrers_list,
4135 &frames_list);
4136
[email protected]445e1042011-12-03 21:03:154137 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4138 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194139 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4140 webview(),
4141 page_url,
4142 &result,
[email protected]2a80aee2011-10-07 16:06:034143 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194144 // If something is wrong when collecting all savable resource links,
4145 // send empty list to embedder(browser) to tell it failed.
4146 referrers_list.clear();
4147 resources_list.clear();
4148 frames_list.clear();
4149 }
4150
4151 // Send result of all savable resource links to embedder.
4152 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4153 resources_list,
4154 referrers_list,
4155 frames_list));
4156}
4157
[email protected]310ebd6302011-10-10 19:06:284158void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194159 const std::vector<GURL>& links,
4160 const std::vector<FilePath>& local_paths,
4161 const FilePath& local_directory_name) {
4162
4163 // Convert std::vector of GURLs to WebVector<WebURL>
4164 WebVector<WebURL> weburl_links(links);
4165
4166 // Convert std::vector of std::strings to WebVector<WebString>
4167 WebVector<WebString> webstring_paths(local_paths.size());
4168 for (size_t i = 0; i < local_paths.size(); i++)
4169 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4170
4171 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4172 webstring_paths,
4173 webkit_glue::FilePathToWebString(
4174 local_directory_name));
4175}
4176
[email protected]310ebd6302011-10-10 19:06:284177void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274178 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474179 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294180}
4181
[email protected]310ebd6302011-10-10 19:06:284182void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]992db4c2011-05-12 15:37:154183 if (is_swapped_out_)
4184 return;
4185
4186 // Swap this RenderView out so the tab can navigate to a page rendered by a
4187 // different process. This involves running the unload handler and clearing
4188 // the page. Once WasSwappedOut is called, we also allow this process to exit
4189 // if there are no other active RenderViews in it.
4190
4191 // Send an UpdateState message before we get swapped out.
4192 SyncNavigationState();
4193
4194 // Synchronously run the unload handler before sending the ACK.
4195 webview()->dispatchUnloadEvent();
4196
4197 // Swap out and stop sending any IPC messages that are not ACKs.
4198 SetSwappedOut(true);
4199
4200 // Replace the page with a blank dummy URL. The unload handler will not be
4201 // run a second time, thanks to a check in FrameLoader::stopLoading.
4202 // TODO(creis): Need to add a better way to do this that avoids running the
4203 // beforeunload handler. For now, we just run it a second time silently.
4204 webview()->mainFrame()->loadHTMLString(std::string(),
4205 GURL("about:swappedout"),
4206 GURL("about:swappedout"),
4207 false);
4208
4209 // Just echo back the params in the ACK.
4210 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4211}
4212
[email protected]310ebd6302011-10-10 19:06:284213void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374214 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294215 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4216 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4217 // in the onunload handler from appearing. For now, we're bypassing that and
4218 // calling the FrameLoader's CloseURL method directly. This should be
4219 // revisited to avoid having two ways to close a page. Having a single way
4220 // to close that can run onunload is also useful for fixing
4221 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274222 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294223
[email protected]992db4c2011-05-12 15:37:154224 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294225}
4226
[email protected]310ebd6302011-10-10 19:06:284227void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024228#if defined(USE_AURA)
4229 // Aura doesn't care if we switch themes.
4230#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164231 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464232 if (webview())
4233 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574234#else // defined(OS_WIN)
4235 // TODO(port): we don't support theming on non-Windows platforms yet
4236 NOTIMPLEMENTED();
4237#endif
initial.commit09911bf2008-07-26 23:55:294238}
4239
[email protected]310ebd6302011-10-10 19:06:284240void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084241 if (decrement_shared_popup_at_destruction_)
4242 shared_popup_counter_->data--;
4243 shared_popup_counter_ = new SharedRenderViewCounter(0);
4244 decrement_shared_popup_at_destruction_ = false;
4245}
4246
[email protected]310ebd6302011-10-10 19:06:284247bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4248 const WebURLError& error,
4249 bool replace) {
[email protected]15d79e12009-08-02 19:23:454250 // We only show alternate error pages in the main frame. They are
4251 // intended to assist the user when navigating, so there is not much
4252 // value in showing them for failed subframes. Ideally, we would be
4253 // able to use the TYPED transition type for this, but that flag is
4254 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454255 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454256 return false;
4257
4258 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374259 // connection failure.
[email protected]15d79e12009-08-02 19:23:454260 int ec = error.reason;
4261 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4262 ec != net::ERR_CONNECTION_FAILED &&
4263 ec != net::ERR_CONNECTION_REFUSED &&
4264 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374265 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454266 return false;
4267
4268 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554269 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454270 if (!error_page_url.is_valid())
4271 return false;
4272
4273 // Load an empty page first so there is an immediate response to the error,
4274 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454275 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364276 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454277 error.unreachableURL,
4278 replace);
4279
4280 // Now, create a fetcher for the error page and associate it with the data
4281 // source we just created via the LoadHTMLString call. That way if another
4282 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074283 DocumentState* document_state =
4284 DocumentState::FromDataSource(frame->provisionalDataSource());
4285 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454286 new AltErrorPageResourceFetcher(
4287 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084288 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4289 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454290 return true;
4291}
4292
[email protected]310ebd6302011-10-10 19:06:284293void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4294 const WebURLError& original_error,
4295 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454296 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094297 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554298 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094299 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454300}
4301
[email protected]310ebd6302011-10-10 19:06:284302void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004303 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474304 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004305}
4306
[email protected]310ebd6302011-10-10 19:06:284307void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094308 const gfx::Rect& resizer_rect,
4309 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104310 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474311 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104312 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204313 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314314 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104315 }
[email protected]dd6afca2011-08-13 03:44:314316 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104317 }
4318
[email protected]ee41e7d22011-10-14 19:34:094319 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004320}
[email protected]0aa477bd2009-03-23 22:21:434321
[email protected]310ebd6302011-10-10 19:06:284322void RenderViewImpl::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014323 // Notify the pepper plugins that we started painting.
4324 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284325}
4326
[email protected]310ebd6302011-10-10 19:06:284327void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284328 // Notify any pepper plugins that we painted. This will call into the plugin,
4329 // and we it may ask to close itself as a result. This will, in turn, modify
4330 // our set, possibly invalidating the iterator. So we iterate on a copy that
4331 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014332 pepper_delegate_.ViewFlushedPaint();
4333
[email protected]00c39612010-03-06 02:53:284334 WebFrame* main_frame = webview()->mainFrame();
4335
4336 // If we have a provisional frame we are between the start and commit stages
4337 // of loading and we don't want to save stats.
4338 if (!main_frame->provisionalDataSource()) {
4339 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074340 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284341
[email protected]05c8e502010-08-15 15:13:524342 // TODO(jar): The following code should all be inside a method, probably in
4343 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284344 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074345 if (document_state->first_paint_time().is_null()) {
4346 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284347 }
[email protected]007733c2011-11-17 00:34:074348 if (document_state->first_paint_after_load_time().is_null() &&
4349 !document_state->finish_load_time().is_null()) {
4350 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284351 }
4352 }
4353}
4354
[email protected]310ebd6302011-10-10 19:06:284355void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084356 RenderWidget::OnSwapBuffersPosted();
4357}
4358
[email protected]310ebd6302011-10-10 19:06:284359void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244360 RenderWidget::OnSwapBuffersComplete();
4361}
4362
[email protected]310ebd6302011-10-10 19:06:284363void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244364 RenderWidget::OnSwapBuffersAborted();
4365}
4366
[email protected]310ebd6302011-10-10 19:06:284367webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154368 const gfx::Rect& paint_bounds,
4369 TransportDIB** dib,
4370 gfx::Rect* location,
4371 gfx::Rect* clip) {
4372 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4373 paint_bounds, dib, location, clip);
4374}
4375
[email protected]310ebd6302011-10-10 19:06:284376gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074377 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434378 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524379}
4380
[email protected]310ebd6302011-10-10 19:06:284381void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164382 if (webview())
[email protected]26aa0482009-09-30 16:55:274383 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164384}
4385
[email protected]310ebd6302011-10-10 19:06:284386void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144387 if (webview())
[email protected]b4bb2502009-10-01 22:35:274388 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144389
4390 SetBackground(background);
4391}
4392
[email protected]310ebd6302011-10-10 19:06:284393void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344394 if (webview())
[email protected]b4bb2502009-10-01 22:35:274395 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264396
4397#if defined(OS_MACOSX)
4398 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4399 for (plugin_it = plugin_delegates_.begin();
4400 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4401 (*plugin_it)->SetWindowFocus(active);
4402 }
4403#endif
[email protected]8c66c5a2009-07-22 17:26:344404}
4405
[email protected]6ce7abc52010-02-02 18:40:144406#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284407void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144408 // Inform plugins that their container has changed visibility.
4409 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4410 for (plugin_it = plugin_delegates_.begin();
4411 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4412 (*plugin_it)->SetContainerVisibility(visible);
4413 }
4414}
[email protected]1e6e3c992010-02-08 15:52:134415
[email protected]310ebd6302011-10-10 19:06:284416void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4417 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134418 // Inform plugins that their window's frame has changed.
4419 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4420 for (plugin_it = plugin_delegates_.begin();
4421 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4422 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4423 }
4424}
[email protected]935d63d2010-10-15 23:31:554425
[email protected]310ebd6302011-10-10 19:06:284426void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4427 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134428 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554429 // applies to it or not, so inform all the delegates.
4430 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4431 for (plugin_it = plugin_delegates_.begin();
4432 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134433 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554434 }
4435}
[email protected]6ce7abc52010-02-02 18:40:144436#endif // OS_MACOSX
4437
[email protected]310ebd6302011-10-10 19:06:284438void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484439 const EditCommands& edit_commands) {
4440 edit_commands_ = edit_commands;
4441}
4442
[email protected]310ebd6302011-10-10 19:06:284443void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594444 // We need to grab a pointer to the doomed WebView before we destroy it.
4445 WebView* doomed = webview();
4446 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494447 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594448}
4449
[email protected]310ebd6302011-10-10 19:06:284450void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484451 edit_commands_.clear();
4452}
4453
[email protected]310ebd6302011-10-10 19:06:284454bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:114455 pepper_delegate_.WillHandleMouseEvent();
4456
4457 // If the mouse is locked, only the current owner of the mouse lock can
4458 // process mouse events.
4459 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374460}
4461
[email protected]310ebd6302011-10-10 19:06:284462void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514463 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064464}
4465
[email protected]310ebd6302011-10-10 19:06:284466void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244467 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4468}
4469
[email protected]310ebd6302011-10-10 19:06:284470void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434471 RenderWidget::OnWasHidden();
4472
[email protected]a6939ca42011-02-18 17:58:074473 if (webview()) {
4474 webview()->settings()->setMinimumTimerInterval(
4475 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444476 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074477 }
4478
[email protected]204f1df2012-01-04 20:21:134479 // Inform PPAPI plugins that their page is no longer visible.
4480 pepper_delegate_.PageVisibilityChanged(false);
4481
[email protected]a6939ca42011-02-18 17:58:074482#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134483 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434484 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4485 for (plugin_it = plugin_delegates_.begin();
4486 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4487 (*plugin_it)->SetContainerVisibility(false);
4488 }
[email protected]a6939ca42011-02-18 17:58:074489#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434490}
4491
[email protected]310ebd6302011-10-10 19:06:284492void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434493 RenderWidget::OnWasRestored(needs_repainting);
4494
[email protected]a6939ca42011-02-18 17:58:074495 if (webview()) {
4496 webview()->settings()->setMinimumTimerInterval(
4497 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444498 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074499 }
4500
[email protected]204f1df2012-01-04 20:21:134501 // Inform PPAPI plugins that their page is visible.
4502 pepper_delegate_.PageVisibilityChanged(true);
4503
[email protected]a6939ca42011-02-18 17:58:074504#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134505 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434506 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4507 for (plugin_it = plugin_delegates_.begin();
4508 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4509 (*plugin_it)->SetContainerVisibility(true);
4510 }
[email protected]784ea1ab2010-09-18 00:02:344511#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074512}
[email protected]1e6e3c992010-02-08 15:52:134513
[email protected]310ebd6302011-10-10 19:06:284514bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384515 if (WebWidgetHandlesCompositorScheduling())
4516 return false;
4517
[email protected]65225772011-05-12 21:10:244518 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]6d2435e2012-02-01 23:29:374519 if (!context)
4520 return false;
4521 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4522 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4523 std::string::npos;
[email protected]65225772011-05-12 21:10:244524}
4525
[email protected]310ebd6302011-10-10 19:06:284526void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134527 RenderWidget::OnSetFocus(enable);
4528
[email protected]7d3c02c2010-05-05 23:10:314529 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074530 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134531 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4532 for (plugin_it = plugin_delegates_.begin();
4533 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344534#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314535 // RenderWidget's call to setFocus can cause the underlying webview's
4536 // activation state to change just like a call to setIsActive.
4537 if (enable)
4538 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344539#endif
[email protected]7d3c02c2010-05-05 23:10:314540 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134541 }
[email protected]589621b2010-09-23 22:01:074542
4543 // Notify all Pepper plugins.
4544 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134545 }
4546}
[email protected]941e4552010-02-01 21:23:434547
[email protected]310ebd6302011-10-10 19:06:284548void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004549 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504550 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574551}
4552
[email protected]73bf95812011-10-12 11:38:324553void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004554 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324555}
4556
[email protected]3f783362011-10-21 22:40:504557void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4558 UpdateSelectionBounds();
4559}
4560
[email protected]b25b3ee2012-01-13 05:19:544561bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4562 if (!pepper_delegate_.IsPluginFocused())
4563 return false;
4564 *rect = pepper_delegate_.GetCaretBounds();
4565 return true;
4566}
4567
[email protected]73bf95812011-10-12 11:38:324568void RenderViewImpl::PpapiPluginCancelComposition() {
4569 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4570 ui::Range range(ui::Range::InvalidRange());
4571 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4572}
4573
[email protected]310ebd6302011-10-10 19:06:284574void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574575 const string16& text,
4576 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4577 int selection_start,
4578 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324579 if (pepper_delegate_.IsPluginFocused()) {
4580 // When a PPAPI plugin has focus, we bypass WebKit.
4581 pepper_delegate_.OnImeSetComposition(text,
4582 underlines,
4583 selection_start,
4584 selection_end);
4585 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234586#if defined(OS_WIN)
4587 // When a plug-in has focus, we create platform-specific IME data used by
4588 // our IME emulator and send it directly to the focused plug-in, i.e. we
4589 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4590 // instance ID is the same one as the specified ID.)
4591 if (focused_plugin_id_ >= 0) {
4592 std::vector<int> clauses;
4593 std::vector<int> target;
4594 for (size_t i = 0; i < underlines.size(); ++i) {
4595 clauses.push_back(underlines[i].startOffset);
4596 clauses.push_back(underlines[i].endOffset);
4597 if (underlines[i].thick) {
4598 target.clear();
4599 target.push_back(underlines[i].startOffset);
4600 target.push_back(underlines[i].endOffset);
4601 }
4602 }
4603 std::set<WebPluginDelegateProxy*>::iterator it;
4604 for (it = plugin_delegates_.begin();
4605 it != plugin_delegates_.end(); ++it) {
4606 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4607 focused_plugin_id_);
4608 }
4609 return;
4610 }
4611#endif
[email protected]56ea1a62011-05-30 07:05:574612 RenderWidget::OnImeSetComposition(text,
4613 underlines,
4614 selection_start,
4615 selection_end);
4616 }
4617}
4618
[email protected]4de6d1692011-10-12 08:45:444619void RenderViewImpl::OnImeConfirmComposition(
4620 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574621 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324622 // When a PPAPI plugin has focus, we bypass WebKit.
4623 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574624 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234625#if defined(OS_WIN)
4626 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4627 // plug-ins. When we send IME text directly to plug-ins, we should not send
4628 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444629 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234630 if (focused_plugin_id_ >= 0) {
4631 std::set<WebPluginDelegateProxy*>::iterator it;
4632 for (it = plugin_delegates_.begin();
4633 it != plugin_delegates_.end(); ++it) {
4634 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4635 }
4636 return;
4637 }
4638#endif
[email protected]ebd28ac2011-10-13 18:49:054639 if (replacement_range.IsValid() && webview()) {
4640 // Select the text in |replacement_range|, it will then be replaced by
4641 // text added by the call to RenderWidget::OnImeConfirmComposition().
4642 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164643 WebRange webrange = WebRange::fromDocumentRange(
4644 frame, replacement_range.start(), replacement_range.length());
4645 if (!webrange.isNull())
4646 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054647 }
4648 }
[email protected]4de6d1692011-10-12 08:45:444649 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574650 }
4651}
4652
[email protected]310ebd6302011-10-10 19:06:284653ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324654 return pepper_delegate_.IsPluginFocused() ?
4655 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4656}
4657
[email protected]3f783362011-10-21 22:40:504658void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4659 if (pepper_delegate_.IsPluginFocused()) {
4660 // TODO(kinaba) http://crbug.com/101101
4661 // Current Pepper IME API does not handle selection bounds. So we simply
4662 // use the caret position as an empty range for now. It will be updated
4663 // after Pepper API equips features related to surrounding text retrieval.
4664 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4665 *start = caret;
4666 *end = caret;
4667 return;
4668 }
4669 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454670}
4671
[email protected]310ebd6302011-10-10 19:06:284672bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324673 return pepper_delegate_.IsPluginFocused() ?
4674 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574675}
4676
[email protected]e6ae0f6c2011-10-04 10:39:234677#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284678void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234679 if (focused)
4680 focused_plugin_id_ = plugin_id;
4681 else
4682 focused_plugin_id_ = -1;
4683}
4684#endif
4685
[email protected]43f28f832010-02-03 02:28:484686#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284687void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134688 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4689 focused, plugin_id);
4690 Send(msg);
4691}
4692
[email protected]310ebd6302011-10-10 19:06:284693void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134694 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554695 // This message can be sent during event-handling, and needs to be delivered
4696 // within that context.
4697 msg->set_unblock(true);
4698 Send(msg);
4699}
4700
[email protected]310ebd6302011-10-10 19:06:284701gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234702 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484703 gfx::PluginWindowHandle window = NULL;
4704 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234705 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114706 if (window) {
4707 fake_plugin_window_handles_.insert(window);
4708 }
[email protected]43f28f832010-02-03 02:28:484709 return window;
4710}
4711
[email protected]310ebd6302011-10-10 19:06:284712void RenderViewImpl::DestroyFakePluginWindowHandle(
4713 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114714 if (window && fake_plugin_window_handles_.find(window) !=
4715 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484716 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114717 fake_plugin_window_handles_.erase(window);
4718 }
[email protected]43f28f832010-02-03 02:28:484719}
4720
[email protected]310ebd6302011-10-10 19:06:284721void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4722 gfx::PluginWindowHandle window,
4723 int32 width,
4724 int32 height,
4725 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334726 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484727 routing_id(), window, width, height, io_surface_identifier));
4728}
4729
[email protected]310ebd6302011-10-10 19:06:284730void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334731 gfx::PluginWindowHandle window,
4732 int32 width,
4733 int32 height,
4734 TransportDIB::Handle transport_dib) {
4735 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074736 routing_id(), window, width, height, transport_dib));
4737}
4738
[email protected]310ebd6302011-10-10 19:06:284739TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334740 size_t size) {
[email protected]1aef98132010-02-23 18:00:074741 TransportDIB::Handle dib_handle;
4742 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384743 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074744 return dib_handle;
4745 // Return an invalid handle if Send() fails.
4746 return TransportDIB::DefaultHandleValue();
4747}
4748
[email protected]310ebd6302011-10-10 19:06:284749void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4750 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074751 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4752}
4753
[email protected]310ebd6302011-10-10 19:06:284754void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144755 gfx::PluginWindowHandle window, uint64 surface_id) {
4756 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4757 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484758}
4759#endif
[email protected]58c321d2010-02-19 12:11:284760
[email protected]310ebd6302011-10-10 19:06:284761bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234762 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474763 WebFileChooserCompletion* completion) {
4764 static const size_t kMaximumPendingFileChooseRequests = 4;
4765 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4766 // This sanity check prevents too many file choose requests from getting
4767 // queued which could DoS the user. Getting these is most likely a
4768 // programming error (there are many ways to DoS the user so it's not
4769 // considered a "real" security check), either in JS requesting many file
4770 // choosers to pop up, or in a plugin.
4771 //
4772 // TODO(brettw) we might possibly want to require a user gesture to open
4773 // a file picker, which will address this issue in a better way.
4774 return false;
4775 }
4776
4777 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4778 new PendingFileChooser(params, completion)));
4779 if (file_chooser_completions_.size() == 1) {
4780 // Actually show the browse dialog when this is the first request.
4781 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4782 }
4783 return true;
4784}
4785
[email protected]310ebd6302011-10-10 19:06:284786WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514787 if (!geolocation_dispatcher_)
4788 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4789 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254790}
[email protected]61c9f032010-03-31 23:04:194791
[email protected]310ebd6302011-10-10 19:06:284792WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114793 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224794#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514795 if (!speech_input_dispatcher_)
4796 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224797#endif
[email protected]676126f72011-01-15 00:03:514798 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114799}
4800
[email protected]310ebd6302011-10-10 19:06:284801WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514802 if (!device_orientation_dispatcher_)
4803 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4804 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534805}
4806
[email protected]310ebd6302011-10-10 19:06:284807void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4808 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254809 // For now, don't remember plugin zoom values. We don't want to mix them with
4810 // normal web content (i.e. a fixed layout plugin would usually want them
4811 // different).
4812 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4813
[email protected]b75b8292010-10-01 07:28:254814 int minimum_percent = static_cast<int>(
4815 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4816 int maximum_percent = static_cast<int>(
4817 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254818
4819 Send(new ViewHostMsg_UpdateZoomLimits(
4820 routing_id_, minimum_percent, maximum_percent, remember));
4821}
4822
[email protected]310ebd6302011-10-10 19:06:284823void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254824 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084825 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:254826 // Tell the browser which url got zoomed so it can update the menu and the
4827 // saved values if necessary
4828 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084829 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414830 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254831}
4832
[email protected]310ebd6302011-10-10 19:06:284833void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4834 const WebString& base_url,
4835 const WebString& url,
4836 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484837 GURL base(base_url);
4838 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4839 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4840 return;
4841 }
[email protected]f1a29a02011-10-06 23:08:444842 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4843 UTF16ToUTF8(scheme),
4844 absolute_url,
4845 title));
[email protected]a6d36cc2011-02-23 00:39:484846}
4847
[email protected]310ebd6302011-10-10 19:06:284848WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444849 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4850 WebKit::WebPageVisibilityStateHidden :
4851 WebKit::WebPageVisibilityStateVisible;
4852 WebKit::WebPageVisibilityState override_state = current_state;
4853 if (content::GetContentClient()->renderer()->
4854 ShouldOverridePageVisibilityState(this,
4855 &override_state))
4856 return override_state;
4857 return current_state;
[email protected]94dec932011-05-26 20:04:214858}
4859
[email protected]273558fb2012-01-12 15:03:514860WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
4861 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
4862 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
4863 return NULL;
4864 EnsureMediaStreamImpl();
4865 return media_stream_impl_;
4866}
4867
[email protected]310ebd6302011-10-10 19:06:284868bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194869 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454870 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194871 if (frame->parent() != NULL)
4872 return false;
4873
[email protected]f0a3d0b2010-08-06 22:51:534874 // Navigations initiated within Webkit are not sent out to the external host
4875 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274876 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134877 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534878 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134879 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334880 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534881 return false;
4882
[email protected]2fc22d12010-12-02 23:08:164883 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324884 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014885 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164886 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014887 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324888 // The opener relationship between the new window and the parent allows the
4889 // new window to script the parent and vice versa. This is not allowed if
4890 // the origins of the two domains are different. This can be treated as a
4891 // top level navigation and routed back to the host.
4892 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274893 if (!opener) {
[email protected]86965362011-04-21 18:42:514894 return true;
[email protected]d19ea342011-04-20 20:31:134895 } else {
[email protected]b6cb3a842011-06-24 18:28:414896 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324897 return true;
4898 }
4899 }
[email protected]61c9f032010-03-31 23:04:194900 return false;
4901}
[email protected]2b06a992010-08-21 05:48:224902
[email protected]310ebd6302011-10-10 19:06:284903void RenderViewImpl::OnAsyncFileOpened(
4904 base::PlatformFileError error_code,
4905 IPC::PlatformFileForTransit file_for_transit,
4906 int message_id) {
[email protected]27a9ef32010-09-10 04:06:244907 pepper_delegate_.OnAsyncFileOpened(
4908 error_code,
4909 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4910 message_id);
4911}
[email protected]caf706f2010-10-26 17:54:084912
[email protected]310ebd6302011-10-10 19:06:284913void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:474914 int request_id,
4915 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434916 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474917 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4918 broker_process_handle,
4919 handle);
[email protected]eb415bf0e2011-04-14 02:45:424920}
4921
[email protected]caf706f2010-10-26 17:54:084922#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284923void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154924 if (external_popup_menu_ == NULL) {
4925 // Crash reports from the field indicate that we can be notified with a
4926 // NULL external popup menu (we probably get notified twice).
4927 // If you hit this please file a bug against jcivelli and include the page
4928 // and steps to repro.
4929 NOTREACHED();
4930 return;
4931 }
[email protected]caf706f2010-10-26 17:54:084932 external_popup_menu_->DidSelectItem(selected_index);
4933 external_popup_menu_.reset();
4934}
4935#endif
[email protected]bb461532010-11-26 21:50:234936
[email protected]1b4209f2011-01-07 00:25:404937#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:284938void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:404939 int request_id,
4940 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:494941 const PP_NetAddress_Private& local_addr,
4942 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:404943 pepper_delegate_.OnConnectTcpACK(
4944 request_id,
4945 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4946 local_addr,
4947 remote_addr);
4948}
4949#endif
[email protected]a6097f42011-01-10 08:50:514950
[email protected]310ebd6302011-10-10 19:06:284951void RenderViewImpl::OnContextMenuClosed(
[email protected]b29aa74b2011-01-31 21:41:084952 const webkit_glue::CustomContextMenuContext& custom_context) {
4953 if (custom_context.is_pepper_menu)
4954 pepper_delegate_.OnContextMenuClosed(custom_context);
4955 else
4956 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104957}
[email protected]5a7b15a2011-08-22 22:48:184958
[email protected]310ebd6302011-10-10 19:06:284959void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:184960 if (!webview())
4961 return;
4962 WebFrame* main_frame = webview()->mainFrame();
4963 if (!main_frame)
4964 return;
4965 main_frame->enableViewSourceMode(true);
4966}
[email protected]67bfb83f2011-09-22 03:36:374967
[email protected]310ebd6302011-10-10 19:06:284968bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:084969 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:404970}
[email protected]7f3c7af2011-10-20 22:52:514971
[email protected]64d0e192011-12-09 14:44:204972void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:514973 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:184974#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:204975 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:184976#endif
[email protected]7f3c7af2011-10-20 22:52:514977}