blob: 3a241856d1d42b9015c7dc004ae6c4ae0a1db94c [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]c26ad882012-02-07 06:41:2034#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]a2ef54c2011-10-10 16:20:3135#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5136#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1037#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0038#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4039#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0540#include "content/common/request_extra_data.h"
[email protected]778574e2011-03-21 22:03:5041#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2142#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4843#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2944#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5145#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2346#include "content/public/common/file_chooser_params.h"
[email protected]a1d29162011-10-14 17:14:0347#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3448#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0749#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3250#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4451#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3652#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1953#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0254#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1555#include "content/renderer/dom_automation_controller.h"
[email protected]55722152011-03-22 01:33:5356#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1957#include "content/renderer/geolocation_dispatcher.h"
[email protected]1784b2f2011-11-24 10:53:4858#include "content/renderer/idle_user_detector.h"
[email protected]0d9989d2011-12-21 20:26:0059#include "content/renderer/web_intents_host.h"
[email protected]07161902011-11-11 09:57:4260#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0261#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0862#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3763#include "content/renderer/media/audio_renderer_impl.h"
[email protected]273558fb2012-01-12 15:03:5164#include "content/renderer/media/media_stream_dependency_factory.h"
65#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4066#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4867#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4068#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4869#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]4a19be92011-09-22 14:25:0270#include "content/renderer/mhtml_generator.h"
[email protected]217690d2012-01-27 07:33:1171#include "content/renderer/mouse_lock_dispatcher.h"
[email protected]230b7ef2011-03-16 22:30:1972#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3773#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3574#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0575#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4476#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4477#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3278#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0179#include "content/renderer/renderer_webapplicationcachehost_impl.h"
80#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1981#include "content/renderer/speech_input_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3282#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1983#include "content/renderer/v8_value_converter_impl.h"
[email protected]663bd9e2011-03-21 01:07:0184#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3585#include "content/renderer/webplugin_delegate_proxy.h"
86#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4987#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4188#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2789#include "media/base/message_loop_factory_impl.h"
[email protected]e1d69d762011-12-13 05:12:1890#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2991#include "net/base/escape.h"
92#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0493#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5794#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3795#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:3796#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3797#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3798#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
99#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37100#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
101#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
102#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
103#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
104#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37105#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37106#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57107#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58108#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44109#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58110#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14111#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37112#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19113#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37114#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36115#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37119#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17123#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37124#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37125#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40126#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51127#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08128#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]273558fb2012-01-12 15:03:51134#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08136#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]e6e90dc2011-12-03 00:01:37139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26145#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47146#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38147#include "ui/gfx/native_widget_types.h"
148#include "ui/gfx/point.h"
149#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55150#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04151#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]9c4bf232011-12-15 02:25:08152#include "webkit/forms/form_data.h"
153#include "webkit/forms/form_field.h"
154#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43155#include "webkit/glue/alt_error_page_resource_fetcher.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
[email protected]2149cc622012-02-14 01:12:12328NOINLINE static void CrashIntentionally() {
329 // NOTE(shess): Crash directly rather than using NOTREACHED() so
330 // that the signature is easier to triage in crash reports.
331 volatile int* zero = NULL;
332 *zero = 0;
333}
334
[email protected]8bf1048012012-02-08 01:22:18335static void MaybeHandleDebugURL(const GURL& url) {
336 if (!url.SchemeIs(chrome::kChromeUIScheme))
337 return;
338 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12339 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18340 } else if (url == GURL(chrome::kChromeUIKillURL)) {
341 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
342 } else if (url == GURL(chrome::kChromeUIHangURL)) {
343 for (;;) {
344 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
345 }
346 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
347 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
348 }
349}
350
initial.commit09911bf2008-07-26 23:55:29351///////////////////////////////////////////////////////////////////////////////
352
[email protected]310ebd6302011-10-10 19:06:28353struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23354 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47355 WebFileChooserCompletion* c)
356 : params(p),
357 completion(c) {
358 }
[email protected]8caadeb2011-11-22 02:45:23359 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47360 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
361};
362
[email protected]217690d2012-01-27 07:33:11363namespace {
364
365class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
366 public:
367 WebWidgetLockTarget (WebKit::WebWidget* webwidget)
368 : webwidget_(webwidget) {}
369
370 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
371 if (succeeded)
372 webwidget_->didAcquirePointerLock();
373 else
374 webwidget_->didNotAcquirePointerLock();
375 }
376
377 virtual void OnMouseLockLost() OVERRIDE {
378 webwidget_->didLosePointerLock();
379 }
380
381 virtual bool HandleMouseLockedInputEvent(
382 const WebKit::WebMouseEvent &event) OVERRIDE {
383 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
384 return false;
385 }
386
387 private:
388 WebKit::WebWidget* webwidget_;
389};
390
[email protected]86cd9472012-02-03 19:51:05391int64 ExtractPostId(const WebHistoryItem& item) {
392 if (item.isNull())
393 return -1;
394
395 if (item.httpBody().isNull())
396 return -1;
397
398 return item.httpBody().identifier();
399}
400
[email protected]217690d2012-01-27 07:33:11401} // namespace
402
[email protected]daf82f82011-10-31 22:35:31403RenderViewImpl::RenderViewImpl(
404 gfx::NativeViewId parent_hwnd,
405 int32 opener_id,
406 const content::RendererPreferences& renderer_prefs,
407 const WebPreferences& webkit_prefs,
408 SharedRenderViewCounter* counter,
409 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56410 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31411 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46412 const string16& frame_name,
413 int32 next_page_id)
[email protected]380244092011-10-07 17:26:27414 : RenderWidget(WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51415 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02416 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09417 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02418 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24419 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21420 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02421 opened_by_user_gesture_(true),
422 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24423 page_id_(-1),
424 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46425 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00426 history_list_offset_(-1),
427 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02428 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55429 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31430 cached_is_main_frame_pinned_to_left_(false),
431 cached_is_main_frame_pinned_to_right_(false),
432 cached_has_main_frame_horizontal_scrollbar_(false),
433 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]05a980d7a2012-02-07 22:16:42434 context_has_swapbuffers_complete_callback_(false),
435 queried_for_swapbuffers_complete_callback_(false),
[email protected]3354d3e2010-06-10 19:53:02436 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51437 geolocation_dispatcher_(NULL),
438 speech_input_dispatcher_(NULL),
439 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51440 media_stream_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18441 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41442 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32443 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11444 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08445 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18446 handling_select_range_(false),
447#if defined(OS_WIN)
448 focused_plugin_id_(-1),
449#endif
450 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51451 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56452 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51453 if (opener_id != MSG_ROUTING_NONE)
454 opener_id_ = opener_id;
455
[email protected]74ce1ad2011-12-16 21:51:46456 // Ensure we start with a valid next_page_id_ from the browser.
457 DCHECK_GE(next_page_id_, 0);
458
[email protected]21b3a6ae2011-11-30 00:45:29459#if defined(ENABLE_NOTIFICATIONS)
460 notification_provider_ = new NotificationProvider(this);
461#else
462 notification_provider_ = NULL;
463#endif
464
[email protected]11fee2332011-03-29 20:36:35465 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11466 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35467
[email protected]676126f72011-01-15 00:03:51468 if (counter) {
469 shared_popup_counter_ = counter;
470 shared_popup_counter_->data++;
471 decrement_shared_popup_at_destruction_ = true;
472 } else {
473 shared_popup_counter_ = new SharedRenderViewCounter(0);
474 decrement_shared_popup_at_destruction_ = false;
475 }
476
[email protected]380244092011-10-07 17:26:27477 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51478 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47479 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51480 AddRef();
481
482 // If this is a popup, we must wait for the CreatingNew_ACK message before
483 // completing initialization. Otherwise, we can finish it now.
484 if (opener_id == MSG_ROUTING_NONE) {
485 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55486 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51487 }
488
[email protected]34c61bd52011-05-02 19:38:33489 g_view_map.Get().insert(std::make_pair(webview(), this));
490 webkit_preferences_.Apply(webview());
491 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35492 if (!frame_name.empty())
493 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33494 webview()->settings()->setMinimumTimerInterval(
495 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
496 webkit_glue::kForegroundTabTimerInterval);
497
498 OnSetRendererPrefs(renderer_prefs);
499
[email protected]676126f72011-01-15 00:03:51500 host_window_ = parent_hwnd;
501
[email protected]a026daa2011-04-20 15:49:51502#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51503 if (!p2p_socket_dispatcher_)
504 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51505#endif
[email protected]cae8c8492011-03-03 11:12:18506
[email protected]5b87e782012-02-09 18:19:32507#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02508 if (!media_stream_dispatcher_)
509 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32510#endif
[email protected]735873d2012-01-25 23:31:02511
[email protected]8f6a3b852011-07-19 16:48:56512 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32513#if defined(OS_MACOSX)
514 new TextInputClientObserver(this);
515#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56516
[email protected]217690d2012-01-27 07:33:11517 // The next group of objects all implement RenderViewObserver, so are deleted
518 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41519 devtools_agent_ = new DevToolsAgent(this);
[email protected]063afcb2011-09-29 07:54:32520 renderer_accessibility_ = new RendererAccessibility(this);
[email protected]217690d2012-01-27 07:33:11521 mouse_lock_dispatcher_ = new MouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40522 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32523
[email protected]1784b2f2011-11-24 10:53:48524 new IdleUserDetector(this);
525
[email protected]766a7082012-02-03 23:39:15526 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
527 if (command_line.HasSwitch(switches::kDomAutomationController))
528 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
529
[email protected]e48869a2011-04-01 19:56:03530 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29531}
532
[email protected]310ebd6302011-10-10 19:06:28533RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03534 history_page_ids_.clear();
535
[email protected]0aa55312008-10-17 21:53:08536 if (decrement_shared_popup_at_destruction_)
537 shared_popup_counter_->data--;
538
[email protected]a1128322009-10-06 18:38:46539 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47540 while (!file_chooser_completions_.empty()) {
541 if (file_chooser_completions_.front()->completion) {
542 file_chooser_completions_.front()->completion->didChooseFile(
543 WebVector<WebString>());
544 }
545 file_chooser_completions_.pop_front();
546 }
[email protected]a1128322009-10-06 18:38:46547
[email protected]83dde542009-09-11 20:59:55548#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11549 // Destroy all fake plugin window handles on the browser side.
550 while (!fake_plugin_window_handles_.empty()) {
551 // Make sure no NULL plugin window handles were inserted into this list.
552 DCHECK(*fake_plugin_window_handles_.begin());
553 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
554 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
555 }
[email protected]83dde542009-09-11 20:59:55556#endif
[email protected]98324892009-09-09 21:16:05557
[email protected]60c42a8c72009-10-09 04:08:59558#ifndef NDEBUG
559 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49560 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59561 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
562 DCHECK_NE(this, it->second) << "Failed to call Close?";
563#endif
[email protected]676126f72011-01-15 00:03:51564
[email protected]273558fb2012-01-12 15:03:51565 // MediaStreamImpl holds weak references to RenderViewObserver objects,
566 // ensure it's deleted before the observers.
567 media_stream_impl_ = NULL;
568
[email protected]310ebd6302011-10-10 19:06:28569 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51570 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59571}
572
573/*static*/
[email protected]310ebd6302011-10-10 19:06:28574RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31575 ViewMap* views = g_view_map.Pointer();
576 ViewMap::iterator it = views->find(webview);
577 return it == views->end() ? NULL : it->second;
578}
579
580/*static*/
581content::RenderView*
582 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28583 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31584}
585
586/*static*/
587void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49588 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59589 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
590 if (!visitor->Visit(it->second))
591 return;
592 }
593}
594
595/*static*/
[email protected]310ebd6302011-10-10 19:06:28596RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15597 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08598 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31599 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08600 const WebPreferences& webkit_prefs,
601 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34602 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56603 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26604 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46605 const string16& frame_name,
606 int32 next_page_id) {
initial.commit09911bf2008-07-26 23:55:29607 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28608 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51609 parent_hwnd,
610 opener_id,
611 renderer_prefs,
612 webkit_prefs,
613 counter,
614 routing_id,
[email protected]9f4f3322012-01-18 22:29:56615 surface_id,
[email protected]676126f72011-01-15 00:03:51616 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46617 frame_name,
618 next_page_id); // adds reference
initial.commit09911bf2008-07-26 23:55:29619}
620
[email protected]273558fb2012-01-12 15:03:51621WebKit::WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
622 WebKit::WebPeerConnectionHandlerClient* client) {
623 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
624 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
625 return NULL;
626 EnsureMediaStreamImpl();
[email protected]5b87e782012-02-09 18:19:32627 if (!media_stream_impl_.get())
628 return NULL;
[email protected]273558fb2012-01-12 15:03:51629 return media_stream_impl_->CreatePeerConnectionHandler(client);
630}
631
[email protected]310ebd6302011-10-10 19:06:28632void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51633 observers_.AddObserver(observer);
634}
635
[email protected]310ebd6302011-10-10 19:06:28636void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
637 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51638 observers_.RemoveObserver(observer);
639}
640
[email protected]310ebd6302011-10-10 19:06:28641WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26642 return static_cast<WebKit::WebView*>(webwidget());
643}
644
[email protected]310ebd6302011-10-10 19:06:28645void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40646 if (!enabled) {
647 load_progress_tracker_.reset(NULL);
648 return;
649 }
650 if (load_progress_tracker_ == NULL)
651 load_progress_tracker_.reset(new LoadProgressTracker(this));
652}
653
[email protected]310ebd6302011-10-10 19:06:28654void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51655 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29656}
657
[email protected]310ebd6302011-10-10 19:06:28658void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26659 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30660 // If the renderer is visible, set initial visibility and focus state.
661 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34662#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30663 delegate->SetContainerVisibility(true);
664 if (webview() && webview()->isActive())
665 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34666#endif
[email protected]49232292010-09-03 19:07:30667 }
[email protected]784ea1ab2010-09-18 00:02:34668 // Plugins start assuming the content has focus (so that they work in
669 // environments where RenderView isn't hosting them), so we always have to
670 // set the initial state. See webplugin_delegate_impl.h for details.
671 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26672}
673
[email protected]310ebd6302011-10-10 19:06:28674void RenderViewImpl::UnregisterPluginDelegate(
675 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26676 plugin_delegates_.erase(delegate);
677}
[email protected]d8fd6fa2010-02-01 15:54:26678
[email protected]310ebd6302011-10-10 19:06:28679bool RenderViewImpl::GetPluginInfo(const GURL& url,
680 const GURL& page_url,
681 const std::string& mime_type,
682 webkit::WebPluginInfo* plugin_info,
683 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08684 bool found = false;
685 Send(new ViewHostMsg_GetPluginInfo(
686 routing_id_, url, page_url, mime_type, &found, plugin_info,
687 actual_mime_type));
688 return found;
689}
690
[email protected]310ebd6302011-10-10 19:06:28691bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27692 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27693 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41694 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26695
[email protected]676126f72011-01-15 00:03:51696 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
697 RenderViewObserver* observer;
698 while ((observer = it.GetNext()) != NULL)
699 if (observer->OnMessageReceived(message))
700 return true;
[email protected]b2abac72009-02-26 12:39:28701
[email protected]a95986a82010-12-24 06:19:28702 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40703 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28704 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29705 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
706 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56707 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29708 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
709 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
710 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
711 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27712#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35713 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27714#endif
initial.commit09911bf2008-07-26 23:55:29715 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15716 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29717 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
718 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
719 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08720 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29721 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15722 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29723 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49724 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
725 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17726 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17727 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41728 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54729 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
730 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29731 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18732 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
733 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29734 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48735 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55736 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
737 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
738 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
739 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
740 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
741 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
742 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45743 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40744 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29745 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19746 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
747 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29748 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
749 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
750 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51751 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
752 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29753 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04754 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15755 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29756 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
757 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08758 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
759 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00760 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16761 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14762 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25763 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
764 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47765 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]cda45c02010-02-25 19:28:10766 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
767 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51768 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56769 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36770 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34771 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14772#if defined(OS_MACOSX)
773 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13774 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13775 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
776 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14777#endif
[email protected]446705872009-09-10 07:22:48778 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33779 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33780 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
781 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24782 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42783 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
784 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19785 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
786 OnGetAllSavableResourceLinksForCurrentPage)
787 IPC_MESSAGE_HANDLER(
788 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
789 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08790#if defined(OS_MACOSX)
791 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
792#endif
[email protected]521b2482011-01-15 00:10:10793 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51794 // TODO(viettrungluu): Move to a separate message filter.
795#if defined(ENABLE_FLAPPER_HACKS)
796 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
797#endif
[email protected]54ca3ca892011-06-07 21:14:54798#if defined(OS_MACOSX)
799 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
800#endif
[email protected]9e1ad4b2011-08-14 16:49:19801 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
802 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18803 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51804 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19805
initial.commit09911bf2008-07-26 23:55:29806 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28807 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29808 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40809
810 if (!msg_is_ok) {
811 // The message had a handler, but its deserialization failed.
812 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28813 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40814 }
815
[email protected]a95986a82010-12-24 06:19:28816 return handled;
initial.commit09911bf2008-07-26 23:55:29817}
818
[email protected]310ebd6302011-10-10 19:06:28819void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:18820 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:29821 if (!webview())
822 return;
823
[email protected]440a0e52011-09-13 17:38:58824 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
825
[email protected]007733c2011-11-17 00:34:07826 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03827
828 // If this is a stale back/forward (due to a recent navigation the browser
829 // didn't know about), ignore it.
830 if (IsBackForwardToStaleEntry(params, is_reload))
831 return;
832
[email protected]992db4c2011-05-12 15:37:15833 // Swap this renderer back in if necessary.
834 if (is_swapped_out_)
835 SetSwappedOut(false);
836
[email protected]3cc72b12010-03-18 23:03:00837 history_list_offset_ = params.current_history_list_offset;
838 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03839 if (history_list_length_ >= 0)
840 history_page_ids_.resize(history_list_length_, -1);
841 if (params.pending_history_list_offset >= 0 &&
842 params.pending_history_list_offset < history_list_length_)
843 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00844
[email protected]38b592902011-04-16 02:08:42845 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29846
[email protected]26aa0482009-09-30 16:55:27847 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45848 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29849 // We cannot reload if we do not have any history state. This happens, for
850 // example, when recovering from a crash. Our workaround here is a bit of
851 // a hack since it means that reload after a crashed tab does not cause an
852 // end-to-end cache validation.
853 is_reload = false;
854 }
855
[email protected]007733c2011-11-17 00:34:07856 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
857 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50858
[email protected]04d3c6e2009-05-22 17:00:13859 // If we are reloading, then WebKit will use the history state of the current
860 // page, so we should just ignore any given history state. Otherwise, if we
861 // have history state, then we need to navigate to it, which corresponds to a
862 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55863 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29864 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02865 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29866 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55867 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13868 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58869 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45870 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17871 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13872 } else {
873 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28874 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29875
[email protected]e6f546c32009-07-01 17:12:55876 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23877 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13878
[email protected]dd7daa82009-08-10 05:46:45879 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55880 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13881
[email protected]445e1042011-12-03 21:03:15882 if (params.referrer.url.is_valid()) {
883 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
884 params.referrer.policy,
885 params.url,
886 WebString::fromUTF8(params.referrer.url.spec()));
887 if (!referrer.isEmpty())
888 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28889 }
[email protected]04d3c6e2009-05-22 17:00:13890
[email protected]52c68652010-12-07 17:47:04891 if (!params.extra_headers.empty()) {
892 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
893 params.extra_headers.end(), "\n");
894 i.GetNext(); ) {
895 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
896 WebString::fromUTF8(i.values()));
897 }
898 }
899
[email protected]dd7daa82009-08-10 05:46:45900 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50901 }
902
[email protected]77f17a82009-05-21 04:42:54903 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07904 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29905}
906
[email protected]310ebd6302011-10-10 19:06:28907bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03908 const ViewMsg_Navigate_Params& params,
909 bool is_reload) {
910 // Make sure this isn't a back/forward to an entry we have already cropped
911 // or replaced from our history, before the browser knew about it. If so,
912 // a new navigation has committed in the mean time, and we can ignore this.
913 bool is_back_forward = !is_reload && !params.state.empty();
914
915 // Note: if the history_list_length_ is 0 for a back/forward, we must be
916 // restoring from a previous session. We'll update our state in OnNavigate.
917 if (!is_back_forward || history_list_length_ <= 0)
918 return false;
919
920 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
921
922 // Check for whether the forward history has been cropped due to a recent
923 // navigation the browser didn't know about.
924 if (params.pending_history_list_offset >= history_list_length_)
925 return true;
926
927 // Check for whether this entry has been replaced with a new one.
928 int expected_page_id =
929 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44930 if (expected_page_id > 0 && params.page_id != expected_page_id) {
931 if (params.page_id < expected_page_id)
932 return true;
933
934 // Otherwise we've removed an earlier entry and should have shifted all
935 // entries left. For now, it's ok to lazily update the list.
936 // TODO(creis): Notify all live renderers when we remove entries from
937 // the front of the list, so that we don't hit this case.
938 history_page_ids_[params.pending_history_list_offset] = params.page_id;
939 }
[email protected]d466b8a2011-07-15 21:48:03940
941 return false;
942}
943
initial.commit09911bf2008-07-26 23:55:29944// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28945void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44946 if (webview()) {
947 WebFrame* main_frame = webview()->mainFrame();
948 // Stop the alt error page fetcher. If we let it continue it may complete
949 // and cause RenderViewHostManager to swap to this RenderView, even though
950 // it may no longer be active.
951 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
952 StopAltErrorPageFetcher(main_frame->dataSource());
953 main_frame->stopLoading();
954 }
initial.commit09911bf2008-07-26 23:55:29955}
956
[email protected]ecbf10d2010-02-18 13:03:29957// Reload current focused frame.
958// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28959void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29960 if (webview() && webview()->focusedFrame()) {
961 // We always obey the cache (ignore_cache=false) here.
962 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
963 // a cache-ignoring reload of the frame.
964 webview()->focusedFrame()->reload(false);
965 }
[email protected]1dda4022010-01-28 18:24:56966}
967
[email protected]310ebd6302011-10-10 19:06:28968void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27969 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29970}
971
[email protected]310ebd6302011-10-10 19:06:28972void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:25973 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27974 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25975 return;
976
[email protected]26aa0482009-09-30 16:55:27977 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45978 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25979}
980
[email protected]310ebd6302011-10-10 19:06:28981void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:29982 // Check if there is a targeturl waiting to be sent.
983 if (target_url_status_ == TARGET_PENDING) {
984 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
985 pending_target_url_));
986 }
987
988 target_url_status_ = TARGET_NONE;
989}
990
[email protected]310ebd6302011-10-10 19:06:28991void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:29992 if (!webview())
993 return;
994
[email protected]26aa0482009-09-30 16:55:27995 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29996}
997
[email protected]310ebd6302011-10-10 19:06:28998void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:29999 if (!webview())
1000 return;
1001
[email protected]26aa0482009-09-30 16:55:271002 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291003}
1004
[email protected]310ebd6302011-10-10 19:06:281005void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291006 if (!webview())
1007 return;
1008
[email protected]26aa0482009-09-30 16:55:271009 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291010}
1011
[email protected]310ebd6302011-10-10 19:06:281012void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291013 if (!webview())
1014 return;
1015
[email protected]f6b1856b2011-06-29 22:02:531016 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1017 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291018}
1019
[email protected]c0cc3092009-09-12 08:27:271020#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281021void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351022 if (!webview())
1023 return;
1024
1025 // Since the find pasteboard supports only plain text, this can be simpler
1026 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271027 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351028 if (frame->hasSelection()) {
1029 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271030 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171031 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351032 }
[email protected]a954bf72009-09-12 07:30:351033}
[email protected]c0cc3092009-09-12 08:27:271034#endif
[email protected]a954bf72009-09-12 07:30:351035
[email protected]310ebd6302011-10-10 19:06:281036void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291037 if (!webview())
1038 return;
1039
[email protected]26aa0482009-09-30 16:55:271040 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291041}
1042
[email protected]44bf7002011-10-16 02:46:151043void RenderViewImpl::OnPasteAndMatchStyle() {
1044 if (!webview())
1045 return;
1046
1047 webview()->focusedFrame()->executeCommand(
1048 WebString::fromUTF8("PasteAndMatchStyle"));
1049}
1050
[email protected]310ebd6302011-10-10 19:06:281051void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291052 if (!webview())
1053 return;
1054
[email protected]1ff7a032010-02-03 02:46:031055 WebFrame* frame = webview()->focusedFrame();
1056 if (!frame->hasSelection())
1057 frame->selectWordAroundCaret();
1058 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291059}
1060
[email protected]310ebd6302011-10-10 19:06:281061void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291062 if (!webview())
1063 return;
1064
[email protected]26aa0482009-09-30 16:55:271065 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291066}
1067
[email protected]310ebd6302011-10-10 19:06:281068void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291069 if (!webview())
1070 return;
1071
[email protected]26aa0482009-09-30 16:55:271072 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221073 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291074}
1075
[email protected]310ebd6302011-10-10 19:06:281076void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1077 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081078 if (!webview())
1079 return;
1080
1081 handling_select_range_ = true;
1082 webview()->focusedFrame()->selectRange(start, end);
1083 handling_select_range_ = false;
1084}
1085
[email protected]310ebd6302011-10-10 19:06:281086void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1087 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191088 DCHECK(history_length >= 0);
1089 DCHECK(history_list_offset_ == history_list_length_ - 1);
1090 DCHECK(minimum_page_id >= -1);
1091
1092 // Generate the new list.
1093 std::vector<int32> new_history_page_ids(history_length, -1);
1094 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1095 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1096 continue;
1097 new_history_page_ids.push_back(history_page_ids_[i]);
1098 }
1099 new_history_page_ids.swap(history_page_ids_);
1100
1101 // Update indexes.
1102 history_list_length_ = history_page_ids_.size();
1103 history_list_offset_ = history_list_length_ - 1;
1104}
1105
1106
[email protected]310ebd6302011-10-10 19:06:281107void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291108 if (!webview())
1109 return;
[email protected]26aa0482009-09-30 16:55:271110 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291111}
1112
[email protected]54ca3ca892011-06-07 21:14:541113#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281114void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331115 if (!webview())
1116 return;
1117 if (in_live_resize)
1118 webview()->willStartLiveResize();
1119 else
1120 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541121}
1122#endif
1123
[email protected]310ebd6302011-10-10 19:06:281124void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1125 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091126 WebKit::WebNode node = GetFocusedNode();
1127 if (!node.isNull()) {
1128 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191129 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511130 }
1131}
1132
initial.commit09911bf2008-07-26 23:55:291133///////////////////////////////////////////////////////////////////////////////
1134
1135// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281136void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451137 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291138 DCHECK(ds);
1139
[email protected]726985e22009-06-18 21:09:281140 const WebURLRequest& request = ds->request();
1141 const WebURLRequest& original_request = ds->originalRequest();
1142 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291143
[email protected]007733c2011-11-17 00:34:071144 DocumentState* document_state = DocumentState::FromDataSource(ds);
1145 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291146
1147 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281148 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291149 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051150 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291151 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071152 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191153 params.socket_address.set_host(response.remoteIPAddress().utf8());
1154 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031155 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091156 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071157 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291158 // SSL state specified in the request takes precedence over the one in the
1159 // response.
1160 // So far this is only intended for error pages that are not expected to be
1161 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281162 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071163 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291164 } else {
[email protected]726985e22009-06-18 21:09:281165 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291166 }
1167
1168 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281169 if (ds->hasUnreachableURL()) {
1170 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291171 } else {
[email protected]726985e22009-06-18 21:09:281172 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291173 }
1174
[email protected]5f9b8712011-11-23 08:55:571175 if (frame->document().baseURL() != params.url)
1176 params.base_url = frame->document().baseURL();
1177
[email protected]726985e22009-06-18 21:09:281178 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241179 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041180 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291181
[email protected]007733c2011-11-17 00:34:071182 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351183 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071184 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291185
1186 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071187 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291188 if (password_form_data)
1189 params.password_form = *password_form_data;
1190
1191 params.gesture = navigation_gesture_;
1192 navigation_gesture_ = NavigationGestureUnknown;
1193
[email protected]0f38dc4552011-02-25 11:24:001194 // Make navigation state a part of the FrameNavigate message so that commited
1195 // entry had it at all times.
1196 const WebHistoryItem& item = frame->currentHistoryItem();
1197 if (!item.isNull()) {
1198 params.content_state = webkit_glue::HistoryItemToString(item);
1199 } else {
1200 params.content_state =
1201 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1202 }
1203
[email protected]dd7daa82009-08-10 05:46:451204 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291205 // Top-level navigation.
1206
[email protected]b75b8292010-10-01 07:28:251207 // Set zoom level, but don't do it for full-page plugin since they don't use
1208 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011209 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541210 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251211 if (webview()->mainFrame()->document().isPluginDocument()) {
1212 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251213 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251214 } else {
1215 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251216 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251217 }
1218
[email protected]f85f0702010-01-30 09:31:011219 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511220 // This zoom level was merely recorded transiently for this load. We can
1221 // erase it now. If at some point we reload this page, the browser will
1222 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011223 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511224 }
1225
[email protected]b75b8292010-10-01 07:28:251226 // Reset the zoom limits in case a plugin had changed them previously. This
1227 // will also call us back which will cause us to send a message to
1228 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251229 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011230 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1231 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251232
initial.commit09911bf2008-07-26 23:55:291233 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551234 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291235
[email protected]daa8c58e2009-06-15 17:21:101236 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581237 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291238 // If the main frame does a load, it should not be reported as a subframe
1239 // navigation. This can occur in the following case:
1240 // 1. You're on a site with frames.
1241 // 2. You do a subframe navigation. This is stored with transition type
1242 // MANUAL_SUBFRAME.
1243 // 3. You navigate to some non-frame site, say, google.com.
1244 // 4. You navigate back to the page from step 2. Since it was initially
1245 // MANUAL_SUBFRAME, it will be that same transition type here.
1246 // We don't want that, because any navigation that changes the toplevel
1247 // frame should be tracked as a toplevel navigation (this allows us to
1248 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581249 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291250 }
1251
initial.commit09911bf2008-07-26 23:55:291252 // If we have a valid consumed client redirect source,
1253 // the page contained a client redirect (meta refresh, document.loc...),
1254 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151255 if (completed_client_redirect_src_.url.is_valid()) {
1256 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291257 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581258 params.transition = static_cast<content::PageTransition>(
1259 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291260 } else {
1261 // Bug 654101: the referrer will be empty on https->http transitions. It
1262 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151263 params.referrer = Referrer(GURL(
1264 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
1265 getReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291266 }
1267
[email protected]726985e22009-06-18 21:09:281268 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051269 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291270 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051271 params.post_id = ExtractPostId(item);
1272 }
initial.commit09911bf2008-07-26 23:55:291273
[email protected]c2a797d2009-09-21 16:46:321274 // Save some histogram data so we can compute the average memory used per
1275 // page load of the glyphs.
1276 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1277 webkit_glue::GetGlyphPageCount());
1278
[email protected]15cf526b2010-02-12 06:33:491279 // This message needs to be sent before any of allowScripts(),
1280 // allowImages(), allowPlugins() is called for the new page, so that when
1281 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1282 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291283 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1284 } else {
1285 // Subframe navigation: the type depends on whether this navigation
1286 // generated a new session history entry. When they do generate a session
1287 // history entry, it means the user initiated the navigation and we should
1288 // mark it as such. This test checks if this is the first time UpdateURL
1289 // has been called since WillNavigateToURL was called to initiate the load.
1290 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581291 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291292 else
[email protected]2905f742011-10-13 03:51:581293 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291294
initial.commit09911bf2008-07-26 23:55:291295 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1296 }
1297
1298 last_page_id_sent_to_browser_ =
1299 std::max(last_page_id_sent_to_browser_, page_id_);
1300
1301 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101302 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581303 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291304}
1305
1306// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281307void RenderViewImpl::UpdateTitle(WebFrame* frame,
1308 const string16& title,
1309 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461310 // Ignore all but top level navigations.
1311 if (frame->parent())
1312 return;
1313
1314 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1315 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1316 title_direction));
initial.commit09911bf2008-07-26 23:55:291317}
1318
[email protected]310ebd6302011-10-10 19:06:281319void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1320 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291321 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271322 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291323 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301324 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291325 last_encoding_name_ = encoding_name;
1326
[email protected]e38f40152008-09-12 23:08:301327 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291328 }
1329}
1330
[email protected]e15f680732010-11-23 22:30:201331// Sends the last committed session history state to the browser so it will be
1332// saved before we navigate to a new page. This must be called *before* the
1333// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281334void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291335 // If we have a valid page ID at this point, then it corresponds to the page
1336 // we are navigating away from. Otherwise, this is the first navigation, so
1337 // there is no past session history to record.
1338 if (page_id_ == -1)
1339 return;
1340
[email protected]ca948a22009-06-25 19:36:171341 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271342 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171343 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291344 return;
[email protected]ca948a22009-06-25 19:36:171345
1346 Send(new ViewHostMsg_UpdateState(
1347 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291348}
1349
[email protected]310ebd6302011-10-10 19:06:281350void RenderViewImpl::OpenURL(WebFrame* frame,
1351 const GURL& url,
[email protected]445e1042011-12-03 21:03:151352 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281353 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171354 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581355 routing_id_,
1356 url,
1357 referrer,
1358 NavigationPolicyToDisposition(policy),
1359 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171360}
1361
[email protected]79dbc662009-09-04 05:42:511362// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291363
[email protected]310ebd6302011-10-10 19:06:281364void RenderViewImpl::LoadNavigationErrorPage(
1365 WebFrame* frame,
1366 const WebURLRequest& failed_request,
1367 const WebURLError& error,
1368 const std::string& html,
1369 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581370 std::string alt_html;
1371 const std::string* error_html;
1372
1373 if (!html.empty()) {
1374 error_html = &html;
1375 } else {
1376 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1377 failed_request, error, &alt_html, NULL);
1378 error_html = &alt_html;
1379 }
1380
1381 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361382 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251383 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551384 replace);
initial.commit09911bf2008-07-26 23:55:291385}
1386
[email protected]269f86d2011-12-07 02:43:471387bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281388 const string16& message,
1389 const string16& default_value,
1390 const GURL& frame_url,
1391 string16* result) {
initial.commit09911bf2008-07-26 23:55:291392 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411393 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291394 if (!result)
1395 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291396
[email protected]12636df2009-09-28 22:32:211397 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1398 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291399 return success;
1400}
1401
[email protected]310ebd6302011-10-10 19:06:281402bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571403 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1404 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1405 // it is particularly important that we do not call willEnterModalLoop as
1406 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441407 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1408 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571409
1410 message->EnableMessagePumping(); // Runs a nested message loop.
1411 return Send(message);
1412}
1413
[email protected]48c9cf2d2009-09-16 16:47:521414// WebKit::WebViewClient ------------------------------------------------------
1415
[email protected]310ebd6302011-10-10 19:06:281416WebView* RenderViewImpl::createView(
[email protected]844acf372011-01-14 10:49:271417 WebFrame* creator,
1418 const WebURLRequest& request,
1419 const WebWindowFeatures& features,
1420 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521421 // Check to make sure we aren't overloading on popups.
1422 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1423 return NULL;
1424
[email protected]8ab04652010-06-12 02:47:261425 ViewHostMsg_CreateWindow_Params params;
1426 params.opener_id = routing_id_;
1427 params.user_gesture = creator->isProcessingUserGesture();
1428 params.window_container_type = WindowFeaturesToContainerType(features);
1429 params.session_storage_namespace_id = session_storage_namespace_id_;
1430 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111431 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411432 params.opener_url = creator->document().url();
1433 params.opener_security_origin =
1434 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111435 if (!request.isNull())
1436 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261437
[email protected]48c9cf2d2009-09-16 16:47:521438 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561439 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341440 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261441 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521442
[email protected]380244092011-10-07 17:26:271443 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261444 new ViewHostMsg_CreateWindow(params,
1445 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561446 &surface_id,
[email protected]8ab04652010-06-12 02:47:261447 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211448 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521449 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521450
[email protected]310ebd6302011-10-10 19:06:281451 RenderViewImpl* view = RenderViewImpl::Create(
1452 0,
1453 routing_id_,
1454 renderer_preferences_,
1455 webkit_preferences_,
1456 shared_popup_counter_,
1457 routing_id,
[email protected]9f4f3322012-01-18 22:29:561458 surface_id,
[email protected]310ebd6302011-10-10 19:06:281459 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461460 frame_name,
1461 1);
[email protected]8ab04652010-06-12 02:47:261462 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521463
[email protected]007a848b2009-10-26 15:55:461464 // Record whether the creator frame is trying to suppress the opener field.
1465 view->opener_suppressed_ = opener_suppressed;
1466
[email protected]48c9cf2d2009-09-16 16:47:521467 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411468 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521469 if (!creator_url.is_valid() || !creator_url.IsStandard())
1470 creator_url = GURL();
1471 view->creator_url_ = creator_url;
1472
1473 // Copy over the alternate error page URL so we can have alt error pages in
1474 // the new render view (we don't need the browser to send the URL back down).
1475 view->alternate_error_page_url_ = alternate_error_page_url_;
1476
1477 return view->webview();
1478}
1479
[email protected]310ebd6302011-10-10 19:06:281480WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]380244092011-10-07 17:26:271481 RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521482 return widget->webwidget();
1483}
1484
[email protected]310ebd6302011-10-10 19:06:281485WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441486 // TODO(jcivelli): Remove this deprecated method when its been removed from
1487 // the WebViewClient interface. It's been replaced by
1488 // createExternalPopupMenu.
1489 NOTREACHED();
1490 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521491}
1492
[email protected]310ebd6302011-10-10 19:06:281493WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081494 const WebPopupMenuInfo& popup_menu_info,
1495 WebExternalPopupMenuClient* popup_menu_client) {
1496 DCHECK(!external_popup_menu_.get());
1497 external_popup_menu_.reset(
1498 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1499 return external_popup_menu_.get();
1500}
1501
[email protected]310ebd6302011-10-10 19:06:281502RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521503 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531504 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421505 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411506 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531507 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271508 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391509 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561510 return widget;
[email protected]79c7bed2010-09-14 22:28:391511}
1512
[email protected]310ebd6302011-10-10 19:06:281513WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1514 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341515 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391516 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291517 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1518 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1519 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341520}
1521
[email protected]7e8b4d12012-01-20 23:39:511522WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]01e69032012-01-31 05:39:061523 const WebGraphicsContext3D::Attributes& attributes,
[email protected]7e8b4d12012-01-20 23:39:511524 bool direct) {
1525 if (!webview())
1526 return NULL;
1527 // The WebGraphicsContext3DInProcessImpl code path is used for
1528 // layout tests (though not through this code) as well as for
1529 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511530 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571531 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
1532 attributes, webview(), direct);
[email protected]7e8b4d12012-01-20 23:39:511533 } else {
[email protected]b3e83de2012-02-07 03:33:281534 int surface = direct ? surface_id() : 0;
1535
1536 GURL url;
1537 if (webview()->mainFrame())
1538 url = GURL(webview()->mainFrame()->document().url());
1539
1540 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client;
1541 if (direct)
1542 swap_client = AsWeakPtr();
1543
1544 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1545 new WebGraphicsContext3DCommandBufferImpl(
1546 surface, url, swap_client));
1547
1548 if (!context->Initialize(attributes))
[email protected]56200f012012-02-03 23:13:571549 return NULL;
1550 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511551 }
[email protected]7e8b4d12012-01-20 23:39:511552}
1553
[email protected]310ebd6302011-10-10 19:06:281554void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521555 const WebConsoleMessage& message, const WebString& source_name,
1556 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081557 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511558 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081559 case WebConsoleMessage::LevelTip:
1560 log_severity = logging::LOG_VERBOSE;
1561 break;
1562 case WebConsoleMessage::LevelLog:
1563 log_severity = logging::LOG_INFO;
1564 break;
1565 case WebConsoleMessage::LevelWarning:
1566 log_severity = logging::LOG_WARNING;
1567 break;
1568 case WebConsoleMessage::LevelError:
1569 log_severity = logging::LOG_ERROR;
1570 break;
1571 default:
1572 NOTREACHED();
1573 }
1574
[email protected]48c9cf2d2009-09-16 16:47:521575 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081576 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311577 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521578 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311579 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521580}
1581
[email protected]310ebd6302011-10-10 19:06:281582void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421583 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521584}
1585
[email protected]310ebd6302011-10-10 19:06:281586WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511587 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021588}
1589
[email protected]310ebd6302011-10-10 19:06:281590bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121591 const WebString& path,
1592 WebFileChooserCompletion* chooser_completion) {
1593 int id = enumeration_completion_id_++;
1594 enumeration_completions_[id] = chooser_completion;
1595 return Send(new ViewHostMsg_EnumerateDirectory(
1596 routing_id_,
1597 id,
1598 webkit_glue::WebStringToFilePath(path)));
1599}
1600
[email protected]310ebd6302011-10-10 19:06:281601void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521602 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141603 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521604 return;
1605 }
1606
1607 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521608
1609 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311610
1611 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521612}
1613
[email protected]310ebd6302011-10-10 19:06:281614void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521615 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141616 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521617 return;
1618 }
1619
1620 is_loading_ = false;
1621
1622 // NOTE: For now we're doing the safest thing, and sending out notification
1623 // when done loading. This currently isn't an issue as the favicon is only
1624 // displayed when done loading. Ideally we would send notification when
1625 // finished parsing the head, but webkit doesn't support that yet.
1626 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521627 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1628
[email protected]90109412010-12-15 17:14:241629 if (load_progress_tracker_ != NULL)
1630 load_progress_tracker_->DidStopLoading();
1631
[email protected]93b9d692011-04-13 00:44:311632 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521633}
1634
[email protected]310ebd6302011-10-10 19:06:281635void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1636 double load_progress) {
[email protected]90109412010-12-15 17:14:241637 if (load_progress_tracker_ != NULL)
1638 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1639}
1640
[email protected]310ebd6302011-10-10 19:06:281641bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061642#if defined(OS_MACOSX)
1643 return true;
1644#else
1645 return false;
1646#endif
1647}
1648
[email protected]310ebd6302011-10-10 19:06:281649bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031650#if defined(OS_WIN)
1651 return true;
1652#else
1653 return false;
1654#endif
1655}
1656
[email protected]310ebd6302011-10-10 19:06:281657void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081658 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031659 return;
[email protected]4fb60142011-08-09 02:22:081660 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011661
[email protected]b781ff282011-08-20 06:19:361662 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031663}
1664
[email protected]310ebd6302011-10-10 19:06:281665void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121666 const std::string& name = UTF16ToUTF8(command_name);
1667 if (StartsWithASCII(name, "Move", true) ||
1668 StartsWithASCII(name, "Insert", true) ||
1669 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031670 return;
[email protected]f1a29a02011-10-06 23:08:441671 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031672}
1673
[email protected]310ebd6302011-10-10 19:06:281674bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101675 if (edit_commands_.empty())
1676 return false;
1677
[email protected]26aa0482009-09-30 16:55:271678 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101679 if (!frame)
1680 return false;
1681
1682 EditCommands::iterator it = edit_commands_.begin();
1683 EditCommands::iterator end = edit_commands_.end();
1684
[email protected]507b33ea2009-09-29 03:56:511685 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101686 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331687 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1688 // key (but it's the exception). Once one edit command is not executed, it
1689 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101690 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1691 WebString::fromUTF8(it->value)))
1692 break;
[email protected]507b33ea2009-09-29 03:56:511693 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101694 }
1695
[email protected]507b33ea2009-09-29 03:56:511696 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101697}
1698
[email protected]310ebd6302011-10-10 19:06:281699bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351700 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471701 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351702 // Do not open the file dialog in a hidden RenderView.
1703 if (is_hidden())
1704 return false;
[email protected]8caadeb2011-11-22 02:45:231705 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261706 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231707 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261708 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231709 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501710 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231711 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261712 else
[email protected]8caadeb2011-11-22 02:45:231713 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471714 ipc_params.title = params.title;
1715 ipc_params.default_file_name =
1716 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461717 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1718 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1719 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471720
1721 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461722}
1723
[email protected]269f86d2011-12-07 02:43:471724void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1725 const WebString& message) {
1726 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411727 message,
1728 string16(),
[email protected]b6cb3a842011-06-24 18:28:411729 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521730 NULL);
1731}
1732
[email protected]269f86d2011-12-07 02:43:471733bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1734 const WebString& message) {
1735 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411736 message,
1737 string16(),
[email protected]b6cb3a842011-06-24 18:28:411738 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521739 NULL);
1740}
1741
[email protected]269f86d2011-12-07 02:43:471742bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1743 const WebString& message,
1744 const WebString& default_value,
1745 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411746 string16 result;
[email protected]269f86d2011-12-07 02:43:471747 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411748 message,
1749 default_value,
[email protected]b6cb3a842011-06-24 18:28:411750 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521751 &result);
1752 if (ok)
[email protected]4f5ce842011-05-27 19:34:411753 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521754 return ok;
1755}
1756
[email protected]310ebd6302011-10-10 19:06:281757bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521758 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151759 // If we are swapping out, we have already run the beforeunload handler.
1760 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1761 // at all, to avoid running it twice.
1762 if (is_swapped_out_)
1763 return true;
1764
[email protected]48c9cf2d2009-09-16 16:47:521765 bool success = false;
1766 // This is an ignored return value, but is included so we can accept the same
1767 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411768 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211769 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411770 routing_id_, frame->document().url(), message,
1771 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521772 return success;
1773}
1774
[email protected]310ebd6302011-10-10 19:06:281775void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441776 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:511777 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:371778
1779 // frame is NULL if invoked by BlockedPlugin.
1780 if (frame)
1781 params.frame_id = frame->identifier();
1782
[email protected]db803aae2011-03-05 02:00:421783 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271784 // it. We replace it with an empty GURL so the appropriate items are disabled
1785 // in the context menu.
1786 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1787 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421788 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271789 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101790 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291791 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441792}
1793
[email protected]310ebd6302011-10-10 19:06:281794void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261795 // TODO(darin): Remove once WebKit roll is complete.
1796 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471797}
1798
[email protected]310ebd6302011-10-10 19:06:281799void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261800 // TODO(darin): Remove once WebKit roll is complete.
1801 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471802}
1803
[email protected]310ebd6302011-10-10 19:06:281804void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521805}
1806
[email protected]310ebd6302011-10-10 19:06:281807void RenderViewImpl::UpdateTargetURL(const GURL& url,
1808 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581809 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521810 if (latest_url == target_url_)
1811 return;
[email protected]163f8242009-10-30 20:19:551812
[email protected]48c9cf2d2009-09-16 16:47:521813 // Tell the browser to display a destination link.
1814 if (target_url_status_ == TARGET_INFLIGHT ||
1815 target_url_status_ == TARGET_PENDING) {
1816 // If we have a request in-flight, save the URL to be sent when we
1817 // receive an ACK to the in-flight request. We can happily overwrite
1818 // any existing pending sends.
1819 pending_target_url_ = latest_url;
1820 target_url_status_ = TARGET_PENDING;
1821 } else {
[email protected]c85f0212011-11-04 16:54:411822 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1823 // see |ParamTraits<GURL>|.
1824 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1825 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521826 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1827 target_url_ = latest_url;
1828 target_url_status_ = TARGET_INFLIGHT;
1829 }
1830}
1831
[email protected]310ebd6302011-10-10 19:06:281832void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311833 int delay;
1834 if (send_content_state_immediately_)
1835 delay = 0;
1836 else if (is_hidden())
1837 delay = kDelaySecondsForContentStateSyncHidden;
1838 else
1839 delay = kDelaySecondsForContentStateSync;
1840
1841 if (nav_state_sync_timer_.IsRunning()) {
1842 // The timer is already running. If the delay of the timer maches the amount
1843 // we want to delay by, then return. Otherwise stop the timer so that it
1844 // gets started with the right delay.
1845 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1846 return;
1847 nav_state_sync_timer_.Stop();
1848 }
1849
[email protected]d323a172011-09-02 18:23:021850 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281851 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311852}
1853
[email protected]310ebd6302011-10-10 19:06:281854void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551855 mouse_over_url_ = GURL(url);
1856 UpdateTargetURL(mouse_over_url_, focus_url_);
1857}
1858
[email protected]310ebd6302011-10-10 19:06:281859void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551860 focus_url_ = GURL(url);
1861 UpdateTargetURL(focus_url_, mouse_over_url_);
1862}
1863
[email protected]310ebd6302011-10-10 19:06:281864void RenderViewImpl::startDragging(const WebDragData& data,
1865 WebDragOperationsMask mask,
1866 const WebImage& image,
1867 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411868#if WEBKIT_USING_SKIA
1869 SkBitmap bitmap(image.getSkBitmap());
1870#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331871 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411872#endif
1873
[email protected]59f4f2fa2011-03-23 01:00:551874 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521875 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411876 mask,
1877 bitmap,
1878 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521879}
1880
[email protected]310ebd6302011-10-10 19:06:281881bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451882 return renderer_preferences_.can_accept_load_drops;
1883}
1884
[email protected]310ebd6302011-10-10 19:06:281885void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521886 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1887}
1888
[email protected]310ebd6302011-10-10 19:06:281889void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521890 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1891}
1892
[email protected]310ebd6302011-10-10 19:06:281893void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511894 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071895
[email protected]38b592902011-04-16 02:08:421896 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491897}
1898
[email protected]169d4282011-11-30 19:33:591899void RenderViewImpl::didUpdateLayout() {
1900 // We don't always want to set up a timer, only if we've been put in that
1901 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1902 // message.
1903 if (!send_preferred_size_changes_ || !webview())
1904 return;
1905
1906 if (check_preferred_size_timer_.IsRunning())
1907 return;
1908 check_preferred_size_timer_.Start(FROM_HERE,
1909 TimeDelta::FromMilliseconds(0), this,
1910 &RenderViewImpl::CheckPreferredSize);
1911}
1912
[email protected]310ebd6302011-10-10 19:06:281913void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521914 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1915}
1916
[email protected]310ebd6302011-10-10 19:06:281917int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001918 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521919}
1920
[email protected]310ebd6302011-10-10 19:06:281921int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001922 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521923}
1924
[email protected]310ebd6302011-10-10 19:06:281925void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321926 const WebAccessibilityObject& obj,
1927 WebAccessibilityNotification notification) {
1928 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1929}
1930
[email protected]310ebd6302011-10-10 19:06:281931void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141932 const WebString& value) {
1933 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1934 key.utf8(),
1935 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261936}
1937
[email protected]79dbc662009-09-04 05:42:511938// WebKit::WebWidgetClient ----------------------------------------------------
1939
[email protected]310ebd6302011-10-10 19:06:281940void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121941 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1942 // we won't have to test for user gesture anymore and we can
1943 // move that code back to render_widget.cc
1944 if (webview() && webview()->mainFrame() &&
1945 webview()->mainFrame()->isProcessingUserGesture()) {
1946 Send(new ViewHostMsg_Focus(routing_id_));
1947 }
1948}
1949
[email protected]310ebd6302011-10-10 19:06:281950void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121951 // TODO(jcivelli): see TODO above in didFocus().
1952 if (webview() && webview()->mainFrame() &&
1953 webview()->mainFrame()->isProcessingUserGesture()) {
1954 Send(new ViewHostMsg_Blur(routing_id_));
1955 }
1956}
1957
initial.commit09911bf2008-07-26 23:55:291958// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281959// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291960// point to dispatch the ShowView message.
1961//
1962// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281963// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291964//
[email protected]310ebd6302011-10-10 19:06:281965void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291966 DCHECK(!did_show_) << "received extraneous Show call";
1967 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1968
1969 if (did_show_)
1970 return;
1971 did_show_ = true;
1972
[email protected]6779aa12011-03-29 17:32:241973 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041974 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041975
[email protected]28295ec2009-10-16 05:34:331976 // Force new windows to a popup if they were not opened with a user gesture.
1977 if (!opened_by_user_gesture_) {
1978 // We exempt background tabs for compat with older versions of Chrome.
1979 // TODO(darin): This seems bogus. These should have a user gesture, so
1980 // we probably don't need this check.
1981 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1982 policy = WebKit::WebNavigationPolicyNewPopup;
1983 }
1984
initial.commit09911bf2008-07-26 23:55:291985 // NOTE: initial_pos_ may still have its default values at this point, but
1986 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1987 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281988 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1989 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291990 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241991 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291992}
1993
[email protected]310ebd6302011-10-10 19:06:281994void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:291995 DCHECK(did_show_) << "should already have shown the view";
1996
[email protected]c1f50aa2010-02-18 03:46:571997 // We must keep WebKit's shared timer running in this case in order to allow
1998 // showModalDialog to function properly.
1999 //
2000 // TODO(darin): WebKit should really be smarter about suppressing events and
2001 // timers so that we do not need to manage the shared timer in such a heavy
2002 // handed manner.
2003 //
[email protected]f1a29a02011-10-06 23:08:442004 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2005 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572006
[email protected]12636df2009-09-28 22:32:212007 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292008}
2009
[email protected]2b624c562011-10-27 22:58:262010bool RenderViewImpl::enterFullScreen() {
2011 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2012 return true;
2013}
2014
2015void RenderViewImpl::exitFullScreen() {
2016 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2017}
2018
[email protected]217690d2012-01-27 07:33:112019bool RenderViewImpl::requestPointerLock() {
2020 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2021}
2022
2023void RenderViewImpl::requestPointerUnlock() {
2024 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2025}
2026
2027bool RenderViewImpl::isPointerLocked() {
2028 return mouse_lock_dispatcher_->IsMouseLockedTo(
2029 webwidget_mouse_lock_target_.get());
2030}
2031
[email protected]3d9689372009-09-10 04:29:172032// WebKit::WebFrameClient -----------------------------------------------------
2033
[email protected]310ebd6302011-10-10 19:06:282034WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2035 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552036 WebPlugin* plugin = NULL;
2037 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2038 this, frame, params, &plugin)) {
2039 return plugin;
2040 }
2041
[email protected]a813c8e2011-10-08 01:34:112042 webkit::WebPluginInfo info;
2043 std::string mime_type;
2044 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2045 params.mimeType.utf8(), &info, &mime_type);
2046 if (!found)
2047 return NULL;
2048
2049 WebPluginParams params_to_use = params;
2050 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312051 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172052}
2053
[email protected]310ebd6302011-10-10 19:06:282054WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422055 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372056 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422057
[email protected]30447b62009-11-13 01:13:372058 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512059 bool exists = false;
[email protected]30447b62009-11-13 01:13:372060 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512061 ViewHostMsg_CreateWorker_Params params;
2062 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512063 params.name = name;
2064 params.document_id = document_id;
2065 params.render_view_route_id = routing_id_;
2066 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232067 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372068 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512069 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372070 if (url_mismatch) {
2071 return NULL;
2072 } else {
[email protected]f1a29a02011-10-06 23:08:442073 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492074 document_id,
[email protected]6de0bcf2010-02-17 22:00:512075 exists,
[email protected]30447b62009-11-13 01:13:372076 route_id,
2077 routing_id_);
2078 }
[email protected]9c00f002009-11-05 22:37:422079}
2080
[email protected]310ebd6302011-10-10 19:06:282081WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172082 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442083 FOR_EACH_OBSERVER(
2084 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172085
[email protected]bb6fd402011-12-09 02:45:442086 media::MessageLoopFactory* message_loop_factory =
2087 new media::MessageLoopFactoryImpl();
2088 media::FilterCollection* collection = new media::FilterCollection();
2089 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372090
[email protected]9e2269d2012-01-07 00:06:212091 RenderAudioSourceProvider* audio_source_provider = NULL;
2092
[email protected]3d9689372009-09-10 04:29:172093 // Add in any custom filter factories first.
2094 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2095 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212096 // audio_source_provider is a "provider" to WebKit, and a sink
2097 // from the perspective of the audio renderer.
2098 audio_source_provider = new RenderAudioSourceProvider();
2099
2100 // Add the chrome specific audio renderer, using audio_source_provider
2101 // as the sink.
2102 AudioRendererImpl* audio_renderer =
2103 new AudioRendererImpl(audio_source_provider);
2104 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172105 }
2106
[email protected]e1d69d762011-12-13 05:12:182107#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
2108 // Currently only cros/arm has any HW video decode support in
2109 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2110 // platforms. This is a startup-time optimization. When new VDA
2111 // implementations are added, relax the #if above.
[email protected]43567302012-02-16 23:21:392112 WebGraphicsContext3DCommandBufferImpl* context3d =
2113 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2114 webview()->graphicsContext3D());
2115 if (context3d && context3d->makeContextCurrent()) {
[email protected]e1d69d762011-12-13 05:12:182116 GpuChannelHost* gpu_channel_host =
2117 RenderThreadImpl::current()->EstablishGpuChannelSync(
2118 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2119 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312120 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
2121 new RendererGpuVideoDecoderFactories(
2122 gpu_channel_host, context3d->context()->AsWeakPtr())));
[email protected]e1d69d762011-12-13 05:12:182123 }
2124#endif
2125
[email protected]da952fd2012-01-13 03:49:252126 webkit_media::WebMediaPlayerImpl* media_player =
2127 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2128 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
2129 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]c4dabe452012-02-08 23:58:122130#if defined(OS_ANDROID)
2131 // TODO(qinmin): Implement for android.
2132 // http://crbug.com/113218
2133#else
[email protected]da952fd2012-01-13 03:49:252134 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562135 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252136 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]9e2269d2012-01-07 00:06:212137 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]bb6fd402011-12-09 02:45:442138 }
[email protected]c4dabe452012-02-08 23:58:122139#endif
[email protected]cec4eb82012-01-12 17:51:562140 return media_player;
[email protected]3d9689372009-09-10 04:29:172141}
2142
[email protected]310ebd6302011-10-10 19:06:282143WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212144 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232145 if (!frame || !frame->view())
2146 return NULL;
[email protected]035545f2010-04-09 13:10:212147 return new RendererWebApplicationCacheHostImpl(
2148 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442149 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212150}
2151
[email protected]310ebd6302011-10-10 19:06:282152WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382153 return &cookie_jar_;
2154}
2155
[email protected]310ebd6302011-10-10 19:06:282156void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512157 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452158}
2159
[email protected]310ebd6302011-10-10 19:06:282160void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512161 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172162}
2163
[email protected]310ebd6302011-10-10 19:06:282164void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172165 WebFrame* frame, const WebURLRequest& request,
2166 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342167 loadURLExternally(frame, request, policy, WebString());
2168}
2169
[email protected]310ebd6302011-10-10 19:06:282170void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342171 WebFrame* frame, const WebURLRequest& request,
2172 WebNavigationPolicy policy,
2173 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592174 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2175 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342176 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2177 suggested_name));
[email protected]efce17b2009-09-11 18:04:592178 } else {
[email protected]445e1042011-12-03 21:03:152179 OpenURL(frame, request.url(),
2180 Referrer(referrer, getReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592181 }
[email protected]3d9689372009-09-10 04:29:172182}
2183
[email protected]310ebd6302011-10-10 19:06:282184WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172185 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222186 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152187 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2188 if (is_swapped_out_) {
[email protected]73eb2602012-02-09 19:50:552189 // It is possible for in-progress navigations to arrive here just after we
2190 // are swapped out, including iframes. We should cancel them.
2191 if (request.url() != GURL("about:swappedout"))
2192 return WebKit::WebNavigationPolicyIgnore;
2193
2194 // Allow about:swappedout to complete.
[email protected]992db4c2011-05-12 15:37:152195 return default_policy;
2196 }
2197
[email protected]3d9689372009-09-10 04:29:172198 // Webkit is asking whether to navigate to a new URL.
2199 // This is fine normally, except if we're showing UI from one security
2200 // context and they're trying to navigate to a different context.
2201 const GURL& url = request.url();
2202
[email protected]d19ea342011-04-20 20:31:132203 // A content initiated navigation may have originated from a link-click,
2204 // script, drag-n-drop operation, etc.
2205 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072206 DocumentState::FromDataSource(frame->provisionalDataSource())->
2207 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132208
[email protected]a8c269a2011-10-25 20:17:222209 // Experimental:
2210 // If --enable-strict-site-isolation is enabled, send all top-level
2211 // navigations to the browser to let it swap processes when crossing site
2212 // boundaries. This is currently expected to break some script calls and
2213 // navigations, such as form submissions.
2214 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102215 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2216 !frame->parent() && (is_content_initiated || is_redirect)) {
2217 WebString origin_str = frame->document().securityOrigin().toString();
2218 GURL frame_url(origin_str.utf8().data());
2219 // TODO(cevans): revisit whether this origin check is still necessary once
2220 // crbug.com/101395 is fixed.
2221 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]445e1042011-12-03 21:03:152222 Referrer referrer(
2223 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2224 getReferrerPolicyFromRequest(request));
[email protected]313b80bd2011-11-23 03:49:102225 OpenURL(frame, url, referrer, default_policy);
2226 return WebKit::WebNavigationPolicyIgnore;
2227 }
[email protected]a8c269a2011-10-25 20:17:222228 }
2229
[email protected]3d9689372009-09-10 04:29:172230 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302231 // navigations.
[email protected]5f000f272012-01-19 05:25:082232 if (is_content_initiated) {
2233 bool browser_handles_top_level_requests =
2234 renderer_preferences_.browser_handles_top_level_requests &&
2235 IsNonLocalTopLevelNavigation(url, frame, type);
2236 if (browser_handles_top_level_requests ||
2237 renderer_preferences_.browser_handles_all_requests) {
2238 Referrer referrer(
2239 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2240 getReferrerPolicyFromRequest(request));
2241 // Reset these counters as the RenderView could be reused for the next
2242 // navigation.
2243 page_id_ = -1;
2244 last_page_id_sent_to_browser_ = -1;
2245 OpenURL(frame, url, referrer, default_policy);
2246 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2247 }
[email protected]3d9689372009-09-10 04:29:172248 }
2249
[email protected]6101c342010-12-16 22:44:372250 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552251 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572252 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372253 // opening a new window). But we sometimes navigate to about:blank to clear a
2254 // tab, and we want to still allow that.
2255 //
[email protected]8f4da8c2011-02-09 19:49:572256 // Note: we do this only for GET requests because our mechanism for switching
2257 // processes only issues GET requests. In particular, POST requests don't
2258 // work, because this mechanism does not preserve form POST data. If it
2259 // becomes necessary to support process switching for POST requests, we will
2260 // need to send the request's httpBody data up to the browser process, and
2261 // issue a special POST navigation in WebKit (via
2262 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2263 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222264 if (!frame->parent() && is_content_initiated &&
[email protected]6101c342010-12-16 22:44:372265 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2266 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2267 bool send_referrer = false;
2268 bool should_fork =
[email protected]e091df82011-10-11 18:13:212269 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172270 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372271 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112272
[email protected]e48869a2011-04-01 19:56:032273 if (!should_fork) {
2274 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362275 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032276 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362277 frame, url, is_content_initiated, is_initial_navigation,
2278 &send_referrer);
[email protected]6101c342010-12-16 22:44:372279 }
2280
2281 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152282 Referrer referrer(
2283 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2284 getReferrerPolicyFromRequest(request));
2285 OpenURL(
2286 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112287 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2288 }
[email protected]3d9689372009-09-10 04:29:172289 }
2290
[email protected]43763f982011-08-26 18:33:402291 // Use the frame's original request's URL rather than the document's URL for
2292 // this check. For a popup, the document's URL may become the opener window's
2293 // URL if the opener has called document.write. See http://crbug.com/93517.
2294 GURL old_url(frame->dataSource()->request().url());
2295
[email protected]3d9689372009-09-10 04:29:172296 // Detect when a page is "forking" a new tab that can be safely rendered in
2297 // its own process. This is done by sites like Gmail that try to open links
2298 // in new windows without script connections back to the original page. We
2299 // treat such cases as browser navigations (in which we will create a new
2300 // renderer for a cross-site navigation), rather than WebKit navigations.
2301 //
2302 // We use the following heuristic to decide whether to fork a new page in its
2303 // own process:
2304 // The parent page must open a new tab to about:blank, set the new tab's
2305 // window.opener to null, and then redirect the tab to a cross-site URL using
2306 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462307 //
2308 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2309 // (see below).
[email protected]3d9689372009-09-10 04:29:172310 bool is_fork =
2311 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582312 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172313 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522314 historyBackListCount() < 1 &&
2315 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172316 // The parent page must have set the child's window.opener to null before
2317 // redirecting to the desired URL.
2318 frame->opener() == NULL &&
2319 // Must be a top-level frame.
2320 frame->parent() == NULL &&
2321 // Must not have issued the request from this page.
2322 is_content_initiated &&
2323 // Must be targeted at the current tab.
2324 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2325 // Must be a JavaScript navigation, which appears as "other".
2326 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462327
2328 // Recognize if this navigation is from a link with rel=noreferrer and
2329 // target=_blank attributes, in which case the opener will be suppressed. If
2330 // so, it is safe to load cross-site pages in a separate process, so we
2331 // should let the browser handle it.
2332 bool is_noreferrer_and_blank_target =
2333 // Frame should be top level and not yet navigated.
2334 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412335 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462336 historyBackListCount() < 1 &&
2337 historyForwardListCount() < 1 &&
2338 // Links with rel=noreferrer will have no Referer field, and their
2339 // resulting frame will have its window.opener suppressed.
2340 // TODO(creis): should add a request.httpReferrer() method to help avoid
2341 // typos on the unusual spelling of Referer.
2342 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2343 opener_suppressed_ &&
2344 frame->opener() == NULL &&
2345 // Links with target=_blank will have no name.
2346 frame->name().isNull() &&
2347 // Another frame (with a non-empty creator) should have initiated the
2348 // request, targeted at this frame.
2349 !creator_url_.is_empty() &&
2350 is_content_initiated &&
2351 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2352 type == WebKit::WebNavigationTypeOther;
2353
2354 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172355 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152356 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172357 return WebKit::WebNavigationPolicyIgnore;
2358 }
2359
2360 return default_policy;
2361}
2362
[email protected]310ebd6302011-10-10 19:06:282363bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492364 WebFrame* frame, const WebURLRequest& request) {
2365 // We allow WebKit to think that everything can be handled even though
2366 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342367 return true;
2368}
2369
[email protected]310ebd6302011-10-10 19:06:282370WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492371 WebFrame* frame, const WebURLRequest& request) {
2372 NOTREACHED(); // Since we said we can handle all requests.
2373 return WebURLError();
2374}
2375
[email protected]310ebd6302011-10-10 19:06:282376WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492377 WebFrame* frame, const WebURLRequest& request) {
2378 WebURLError error;
2379 error.domain = WebString::fromUTF8(net::kErrorDomain);
2380 error.reason = net::ERR_ABORTED;
2381 error.unreachableURL = request.url();
2382 return error;
[email protected]7b7a7dc2009-10-19 02:23:342383}
2384
[email protected]310ebd6302011-10-10 19:06:282385void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492386 WebFrame*, const WebURLError&) {
2387 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342388}
2389
[email protected]310ebd6302011-10-10 19:06:282390void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432391 const WebKit::WebFormElement& form) {
2392 // Some login forms have onSubmit handlers that put a hash of the password
2393 // into a hidden field and then clear the password. (Issue 28910.)
2394 // This method gets called before any of those handlers run, so save away
2395 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072396 DocumentState* document_state =
2397 DocumentState::FromDataSource(frame->dataSource());
2398 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432399 PasswordFormDomManager::CreatePasswordForm(form));
2400}
2401
[email protected]310ebd6302011-10-10 19:06:282402void RenderViewImpl::willSubmitForm(WebFrame* frame,
2403 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072404 DocumentState* document_state =
2405 DocumentState::FromDataSource(frame->provisionalDataSource());
2406 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172407
[email protected]2905f742011-10-13 03:51:582408 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2409 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172410
2411 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352412 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072413 document_state->set_searchable_form_url(web_searchable_form_data.url());
2414 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212415 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432416 PasswordForm* password_form_data =
2417 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072418 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432419
[email protected]098c95cb2011-04-28 16:49:012420 // In order to save the password that the user actually typed and not one
2421 // that may have gotten transformed by the site prior to submit, recover it
2422 // from the form contents already stored by |willSendSubmitEvent| into the
2423 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2424 // which is what we're storing into now.)
2425 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072426 DocumentState* old_document_state =
2427 DocumentState::FromDataSource(frame->dataSource());
2428 if (old_document_state) {
2429 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432430 if (old_form_data && old_form_data->action == password_form_data->action)
2431 password_form_data->password_value = old_form_data->password_value;
2432 }
2433 }
[email protected]3d9689372009-09-10 04:29:172434
[email protected]2a5b1732011-04-01 23:55:552435 FOR_EACH_OBSERVER(
2436 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172437}
2438
[email protected]310ebd6302011-10-10 19:06:282439void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172440 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2441 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382442 FOR_EACH_OBSERVER(
2443 RenderViewObserver, observers_,
2444 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172445}
2446
[email protected]310ebd6302011-10-10 19:06:282447void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382448 FOR_EACH_OBSERVER(
2449 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172450}
2451
[email protected]310ebd6302011-10-10 19:06:282452void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172453 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152454 if (!frame->parent()) {
2455 WebDataSource* ds = frame->provisionalDataSource();
2456 // If there's no provisional data source, it's a reference fragment
2457 // navigation.
2458 completed_client_redirect_src_ = Referrer(
2459 from, ds ? getReferrerPolicyFromRequest(ds->request()) :
2460 frame->referrerPolicy());
2461 }
[email protected]eb0bff942011-04-07 22:08:382462 FOR_EACH_OBSERVER(
2463 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172464}
2465
[email protected]310ebd6302011-10-10 19:06:282466void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072467 DocumentState* document_state = DocumentState::FromDataSource(ds);
2468 if (!document_state) {
2469 document_state = new DocumentState;
2470 ds->setExtraData(document_state);
2471 }
2472
[email protected]3d9689372009-09-10 04:29:172473 // The rest of RenderView assumes that a WebDataSource will always have a
2474 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072475 bool content_initiated = !pending_navigation_params_.get();
2476 if (content_initiated)
2477 document_state->set_navigation_state(
2478 NavigationState::CreateContentInitiated());
2479 else
2480 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512481
[email protected]007733c2011-11-17 00:34:072482 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512483 // navigating from a page that used prefetching using a link on that
2484 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072485 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512486 // this value appropriately.
2487 // TODO(gavinp): catch the important case of navigation in a new
2488 // renderer process.
2489 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302490 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522491 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512492 const GURL referrer(
2493 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2494 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072495 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512496 old_frame->dataSource())->was_prefetcher()) {
2497 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2498 WebDataSource* old_frame_ds = old_frame->dataSource();
2499 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072500 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512501 break;
2502 }
2503 }
2504 }
2505 }
2506 }
2507
[email protected]4c1b6f0b2010-02-07 16:38:182508 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522509 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512510 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182511 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072512 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182513 break;
2514 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072515 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182516 break;
2517 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072518 document_state->set_load_type(
2519 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182520 break;
2521 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072522 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182523 break;
2524 }
2525 }
[email protected]fa7b6b542009-11-03 05:02:302526
[email protected]946a0032011-03-31 18:42:282527 FOR_EACH_OBSERVER(
2528 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172529}
2530
[email protected]007733c2011-11-17 00:34:072531void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2532 DocumentState* document_state) {
2533 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2534
2535 if (document_state->request_time().is_null())
2536 document_state->set_request_time(params.request_time);
2537
2538 // A navigation resulting from loading a javascript URL should not be treated
2539 // as a browser initiated event. Instead, we want it to look as if the page
2540 // initiated any load resulting from JS execution.
2541 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2542 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2543 params.page_id,
2544 params.pending_history_list_offset,
2545 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482546 navigation_state->set_transferred_request_child_id(
2547 params.transferred_request_child_id);
2548 navigation_state->set_transferred_request_request_id(
2549 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072550 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2551 // We're doing a load of a page that was restored from the last session.
2552 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2553 // which can result in stale data for pages that are set to expire. We
2554 // explicitly override that by setting the policy here so that as
2555 // necessary we load from the network.
2556 document_state->set_cache_policy_override(
2557 WebURLRequest::UseProtocolCachePolicy);
2558 }
2559 document_state->set_navigation_state(navigation_state);
2560 } else {
2561 document_state->set_navigation_state(
2562 NavigationState::CreateContentInitiated());
2563 }
2564
2565 if (IsReload(params))
2566 document_state->set_load_type(DocumentState::RELOAD);
2567 else if (!params.state.empty())
2568 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2569 else
2570 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2571
2572 pending_navigation_params_.reset();
2573}
2574
[email protected]310ebd6302011-10-10 19:06:282575void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172576 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072577 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172578
[email protected]3d9689372009-09-10 04:29:172579 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072580 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172581 double event_time = ds->triggeringEventTime();
2582 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072583 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172584 }
2585
[email protected]05c8e502010-08-15 15:13:522586 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072587 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522588
[email protected]3d9689372009-09-10 04:29:172589 bool is_top_most = !frame->parent();
2590 if (is_top_most) {
2591 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132592 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172593
2594 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152595 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172596 } else if (frame->parent()->isLoading()) {
2597 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002598 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072599 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582600 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172601 }
2602
[email protected]28685da92011-02-07 21:49:172603 FOR_EACH_OBSERVER(
2604 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2605
[email protected]3d9689372009-09-10 04:29:172606 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592607 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262608 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172609}
2610
[email protected]310ebd6302011-10-10 19:06:282611void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2612 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172613 if (frame->parent())
2614 return;
2615 // Received a redirect on the main frame.
2616 WebDataSource* data_source = frame->provisionalDataSource();
2617 if (!data_source) {
2618 // Should only be invoked when we have a data source.
2619 NOTREACHED();
2620 return;
2621 }
2622 std::vector<GURL> redirects;
2623 GetRedirectChain(data_source, &redirects);
2624 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512625 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592626 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172627 }
2628}
2629
[email protected]310ebd6302011-10-10 19:06:282630void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2631 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172632 // Notify the browser that we failed a provisional load with an error.
2633 //
2634 // Note: It is important this notification occur before DidStopLoading so the
2635 // SSL manager can react to the provisional load failure before being
2636 // notified the load stopped.
2637 //
2638 WebDataSource* ds = frame->provisionalDataSource();
2639 DCHECK(ds);
2640
2641 const WebURLRequest& failed_request = ds->request();
2642
[email protected]28685da92011-02-07 21:49:172643 FOR_EACH_OBSERVER(
2644 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2645
[email protected]3d9689372009-09-10 04:29:172646 bool show_repost_interstitial =
2647 (error.reason == net::ERR_CACHE_MISS &&
2648 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582649
2650 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2651 params.frame_id = frame->identifier();
2652 params.is_main_frame = !frame->parent();
2653 params.error_code = error.reason;
2654 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2655 failed_request,
2656 error,
2657 NULL,
2658 &params.error_description);
2659 params.url = error.unreachableURL;
2660 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172661 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582662 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172663
2664 // Don't display an error page if this is simply a cancelled load. Aside
2665 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2666 if (error.reason == net::ERR_ABORTED)
2667 return;
[email protected]b553edd52012-01-10 12:15:232668 // Don't display an error message if the request was handled by an
2669 // external protocol handler.
2670 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2671 return;
[email protected]3d9689372009-09-10 04:29:172672
2673 // Make sure we never show errors in view source mode.
2674 frame->enableViewSourceMode(false);
2675
[email protected]007733c2011-11-17 00:34:072676 DocumentState* document_state = DocumentState::FromDataSource(ds);
2677 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172678
2679 // If this is a failed back/forward/reload navigation, then we need to do a
2680 // 'replace' load. This is necessary to avoid messing up session history.
2681 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2682 // as session history is concerned.
2683 //
2684 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2685 // the page id.
2686 //
2687 bool replace =
2688 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582689 navigation_state->transition_type() ==
2690 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172691
2692 // If we failed on a browser initiated request, then make sure that our error
2693 // page load is regarded as the same browser initiated request.
2694 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072695 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2696 pending_navigation_params_->page_id =
2697 navigation_state->pending_page_id();
2698 pending_navigation_params_->pending_history_list_offset =
2699 navigation_state->pending_history_list_offset();
2700 pending_navigation_params_->transition =
2701 navigation_state->transition_type();
2702 pending_navigation_params_->request_time =
2703 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172704 }
2705
2706 // Provide the user with a more helpful error page?
2707 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2708 return;
2709
2710 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082711 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172712}
2713
[email protected]310ebd6302011-10-10 19:06:282714void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172715 WebFrame* frame, const char* data, size_t data_len,
2716 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072717 DocumentState* document_state =
2718 DocumentState::FromDataSource(frame->dataSource());
2719 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172720}
2721
[email protected]310ebd6302011-10-10 19:06:282722void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2723 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072724 DocumentState* document_state =
2725 DocumentState::FromDataSource(frame->dataSource());
2726 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172727
[email protected]007733c2011-11-17 00:34:072728 if (document_state->commit_load_time().is_null())
2729 document_state->set_commit_load_time(Time::Now());
2730
[email protected]3d9689372009-09-10 04:29:172731 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202732 // When we perform a new navigation, we need to update the last committed
2733 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172734 UpdateSessionHistory(frame);
2735
2736 // We bump our Page ID to correspond with the new session history entry.
2737 page_id_ = next_page_id_++;
2738
[email protected]3cc72b12010-03-18 23:03:002739 // Advance our offset in session history, applying the length limit. There
2740 // is now no forward history.
2741 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102742 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2743 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002744 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032745 history_page_ids_.resize(history_list_length_, -1);
2746 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172747 } else {
2748 // Inspect the navigation_state on this frame to see if the navigation
2749 // corresponds to a session history navigation... Note: |frame| may or
2750 // may not be the toplevel frame, but for the case of capturing session
2751 // history, the first committed frame suffices. We keep track of whether
2752 // we've seen this commit before so that only capture session history once
2753 // per navigation.
2754 //
2755 // Note that we need to check if the page ID changed. In the case of a
2756 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2757 // previous URL and the current page ID, which would be wrong.
2758 if (navigation_state->pending_page_id() != -1 &&
2759 navigation_state->pending_page_id() != page_id_ &&
2760 !navigation_state->request_committed()) {
2761 // This is a successful session history navigation!
2762 UpdateSessionHistory(frame);
2763 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002764
2765 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032766
2767 // If the history list is valid, our list of page IDs should be correct.
2768 DCHECK(history_list_length_ <= 0 ||
2769 history_list_offset_ < 0 ||
2770 history_list_offset_ >= history_list_length_ ||
2771 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172772 }
2773 }
2774
[email protected]28685da92011-02-07 21:49:172775 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2776 DidCommitProvisionalLoad(frame, is_new_navigation));
2777
[email protected]3d9689372009-09-10 04:29:172778 // Remember that we've already processed this request, so we don't update
2779 // the session history again. We do this regardless of whether this is
2780 // a session history navigation, because if we attempted a session history
2781 // navigation without valid HistoryItem state, WebCore will think it is a
2782 // new navigation.
2783 navigation_state->set_request_committed(true);
2784
2785 UpdateURL(frame);
2786
2787 // If this committed load was initiated by a client redirect, we're
2788 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152789 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172790
2791 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272792 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172793}
2794
[email protected]310ebd6302011-10-10 19:06:282795void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102796 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2797 DidClearWindowObject(frame));
2798
[email protected]b6cb3a842011-06-24 18:28:412799 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212800 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252801 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2802 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272803 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172804 }
[email protected]766a7082012-02-03 23:39:152805
2806 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
2807 if (!dom_automation_controller_.get())
2808 dom_automation_controller_.reset(new DomAutomationController());
2809 dom_automation_controller_->set_message_sender(
2810 static_cast<content::RenderView*>(this));
2811 dom_automation_controller_->set_routing_id(routing_id());
2812 dom_automation_controller_->BindToJavascript(frame,
2813 "domAutomationController");
2814 }
[email protected]3d9689372009-09-10 04:29:172815}
2816
[email protected]310ebd6302011-10-10 19:06:282817void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172818 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412819 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252820 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272821 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172822 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2823 }
[email protected]e48869a2011-04-01 19:56:032824
2825 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2826 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172827}
2828
[email protected]310ebd6302011-10-10 19:06:282829void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2830 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462831 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172832
2833 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272834 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172835}
2836
[email protected]310ebd6302011-10-10 19:06:282837void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132838 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2839 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582840}
2841
[email protected]310ebd6302011-10-10 19:06:282842void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172843 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072844 DocumentState* document_state = DocumentState::FromDataSource(ds);
2845 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172846
[email protected]622474d2010-11-04 09:21:082847 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172848
[email protected]28685da92011-02-07 21:49:172849 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2850 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172851
2852 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272853 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172854}
2855
[email protected]310ebd6302011-10-10 19:06:282856void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082857 if (webview()->mainFrame() == frame) {
2858 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2859 page_id_));
2860 }
[email protected]3d9689372009-09-10 04:29:172861}
2862
[email protected]310ebd6302011-10-10 19:06:282863void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312864 WebDataSource* ds = frame->dataSource();
2865 DCHECK(ds);
2866
2867
[email protected]28685da92011-02-07 21:49:172868 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312869
2870 const WebURLRequest& failed_request = ds->request();
2871 string16 error_description;
2872 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2873 failed_request,
2874 error,
2875 NULL,
2876 &error_description);
2877 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2878 frame->identifier(),
2879 failed_request.url(),
2880 !frame->parent(),
2881 error.reason,
2882 error_description));
[email protected]3d9689372009-09-10 04:29:172883}
2884
[email protected]310ebd6302011-10-10 19:06:282885void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172886 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072887 DocumentState* document_state = DocumentState::FromDataSource(ds);
2888 if (document_state->finish_load_time().is_null())
2889 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412890
[email protected]676126f72011-01-15 00:03:512891 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172892
[email protected]1a55c5be2011-11-29 11:36:312893 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2894 frame->identifier(),
2895 ds->request().url(),
2896 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172897}
2898
[email protected]310ebd6302011-10-10 19:06:282899void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172900 WebFrame* frame, bool is_new_navigation) {
2901 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072902 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172903 // update the ExtraData on the datasource so that others who read the
2904 // ExtraData will get the new NavigationState. Similarly, if we did not
2905 // initiate this navigation, then we need to take care to reset any pre-
2906 // existing navigation state to a content-initiated navigation state.
2907 // DidCreateDataSource conveniently takes care of this for us.
2908 didCreateDataSource(frame, frame->dataSource());
2909
[email protected]007733c2011-11-17 00:34:072910 DocumentState* document_state =
2911 DocumentState::FromDataSource(frame->dataSource());
2912 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092913 new_state->set_was_within_same_page(true);
2914
[email protected]3d9689372009-09-10 04:29:172915 didCommitProvisionalLoad(frame, is_new_navigation);
2916
[email protected]750fcf872011-08-03 23:10:472917 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2918 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172919}
2920
[email protected]310ebd6302011-10-10 19:06:282921void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312922 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592923}
2924
[email protected]310ebd6302011-10-10 19:06:282925void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172926 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2927 // Ignore
2928}
2929
[email protected]310ebd6302011-10-10 19:06:282930void RenderViewImpl::willSendRequest(WebFrame* frame,
2931 unsigned identifier,
2932 WebURLRequest& request,
2933 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302934 WebFrame* top_frame = frame->top();
2935 if (!top_frame)
2936 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512937 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2938 WebDataSource* top_data_source = top_frame->dataSource();
2939 WebDataSource* data_source =
2940 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222941
[email protected]78d5cfe2011-02-04 08:43:222942 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032943 GURL new_url;
2944 if (content::GetContentClient()->renderer()->WillSendRequest(
2945 frame, request_url, &new_url)) {
2946 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222947 }
2948
[email protected]2905f742011-10-13 03:51:582949 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072950 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2951 NavigationState* navigation_state = document_state->navigation_state();
2952 if (document_state) {
2953 if (document_state->is_cache_policy_override_set())
2954 request.setCachePolicy(document_state->cache_policy_override());
2955 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:302956 }
[email protected]8a3125a712010-08-09 18:58:512957
[email protected]91043a8232011-11-04 16:41:192958 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:062959 new RequestExtraData(frame->referrerPolicy(),
2960 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:192961 frame->identifier(),
2962 frame->parent() == top_frame,
2963 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:482964 transition_type,
2965 navigation_state->transferred_request_child_id(),
2966 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:572967
[email protected]007733c2011-11-17 00:34:072968 DocumentState* top_document_state =
2969 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:572970 // TODO(gavinp): separate out prefetching and prerender field trials
2971 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:072972 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:572973 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2974 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:072975 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512976
[email protected]3d9689372009-09-10 04:29:172977 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132978 request.setHasUserGesture(frame->isProcessingUserGesture());
2979
[email protected]0a8db0d2011-04-13 15:15:402980 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132981 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172982}
2983
[email protected]310ebd6302011-10-10 19:06:282984void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:172985 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492986
[email protected]3d9689372009-09-10 04:29:172987 // Only do this for responses that correspond to a provisional data source
2988 // of the top-most frame. If we have a provisional data source, then we
2989 // can't have any sub-resources yet, so we know that this response must
2990 // correspond to a frame load.
2991 if (!frame->provisionalDataSource() || frame->parent())
2992 return;
2993
2994 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082995 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172996 if (frame->isViewSourceModeEnabled())
2997 return;
2998
[email protected]007733c2011-11-17 00:34:072999 DocumentState* document_state =
3000 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083001 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533002
[email protected]972ebdff2010-06-10 22:59:073003 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073004 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3005 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
3006 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573007 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073008 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3009 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093010 // Whether or not the http status code actually corresponds to an error is
3011 // only checked when the page is done loading, if |use_error_page| is
3012 // still true.
[email protected]007733c2011-11-17 00:34:073013 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173014}
3015
[email protected]310ebd6302011-10-10 19:06:283016void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173017 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073018 DocumentState* document_state =
3019 DocumentState::FromDataSource(frame->dataSource());
3020 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173021 return;
3022
[email protected]7bfc153f2011-09-23 22:00:203023 // Do not show error page when DevTools is attached.
3024 if (devtools_agent_->IsAttached())
3025 return;
3026
[email protected]06333afe2011-02-24 14:55:093027 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073028 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083029 if (http_status_code == 404) {
3030 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413031 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173032
[email protected]b6cb3a842011-06-24 18:28:413033 const GURL& error_page_url =
3034 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093035 if (error_page_url.is_valid()) {
3036 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473037 original_error.domain = "http";
3038 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413039 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173040
[email protected]007733c2011-11-17 00:34:073041 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093042 new AltErrorPageResourceFetcher(
3043 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083044 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3045 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093046 return;
3047 }
3048 }
[email protected]3d9689372009-09-10 04:29:173049
[email protected]e6a2ce52011-10-08 01:40:133050 std::string error_domain;
3051 if (content::GetContentClient()->renderer()->HasErrorPage(
3052 http_status_code, &error_domain)) {
3053 WebURLError error;
3054 error.unreachableURL = frame->document().url();
3055 error.domain = WebString::fromUTF8(error_domain);
3056 error.reason = http_status_code;
3057
3058 LoadNavigationErrorPage(
3059 frame, frame->dataSource()->request(), error, std::string(), true);
3060 }
[email protected]3d9689372009-09-10 04:29:173061}
3062
[email protected]310ebd6302011-10-10 19:06:283063void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173064 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3065 // Ignore
3066}
3067
[email protected]310ebd6302011-10-10 19:06:283068void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173069 WebFrame* frame, const WebURLRequest& request,
3070 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003071 // The recipients of this message have no use for data: URLs: they don't
3072 // affect the page's insecure content list and are not in the disk cache. To
3073 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3074 // filter them out here.
3075 GURL url(request.url());
3076 if (url.SchemeIs("data"))
3077 return;
3078
[email protected]3d9689372009-09-10 04:29:173079 // Let the browser know we loaded a resource from the memory cache. This
3080 // message is needed to display the correct SSL indicators.
3081 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3082 routing_id_,
[email protected]84703292011-10-28 20:44:003083 url,
[email protected]70435962011-08-02 20:13:283084 response.securityInfo(),
3085 request.httpMethod().utf8(),
3086 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173087}
3088
[email protected]310ebd6302011-10-10 19:06:283089void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293090 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3091}
3092
[email protected]310ebd6302011-10-10 19:06:283093void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023094 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293095 Send(new ViewHostMsg_DidRunInsecureContent(
3096 routing_id_,
[email protected]92771112011-01-20 00:13:023097 origin.toString().utf8(),
3098 target));
[email protected]e3d60e5d2009-09-25 21:08:293099}
3100
[email protected]310ebd6302011-10-10 19:06:283101void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033102 webkit_glue::WebURLLoaderImpl* loader_impl =
3103 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3104 loader_impl->UpdateRoutingId(routing_id_);
3105}
3106
[email protected]310ebd6302011-10-10 19:06:283107void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173108 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3109}
3110
[email protected]310ebd6302011-10-10 19:06:283111void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3112 v8::Handle<v8::Context> context,
3113 int world_id) {
[email protected]5bc10932011-09-21 21:03:303114 content::GetContentClient()->renderer()->DidCreateScriptContext(
3115 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283116}
3117
[email protected]310ebd6302011-10-10 19:06:283118void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3119 v8::Handle<v8::Context> context,
3120 int world_id) {
[email protected]5bc10932011-09-21 21:03:303121 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3122 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283123}
3124
[email protected]310ebd6302011-10-10 19:06:283125void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073126 // We don't always want to send the change messages over IPC, only if we've
3127 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3128 // message.
3129 if (!send_preferred_size_changes_ || !webview())
3130 return;
3131
[email protected]705243f2010-05-05 19:58:073132 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3133 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533134
3135 // In the presence of zoom, these sizes are still reported as if unzoomed,
3136 // so we need to adjust.
3137 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3138 size.set_width(static_cast<int>(size.width() * zoom_factor));
3139 size.set_height(static_cast<int>(size.height() * zoom_factor));
3140
[email protected]6b5576cb2011-12-05 08:23:003141 if (!size.height())
3142 size.set_height(preferred_size_.height());
3143
[email protected]705243f2010-05-05 19:58:073144 if (size == preferred_size_)
3145 return;
[email protected]c27324b2009-11-19 22:44:293146
[email protected]705243f2010-05-05 19:58:073147 preferred_size_ = size;
3148 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3149 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173150}
3151
[email protected]273558fb2012-01-12 15:03:513152void RenderViewImpl::EnsureMediaStreamImpl() {
3153#if defined(ENABLE_P2P_APIS)
3154 if (!p2p_socket_dispatcher_)
3155 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3156#endif
3157
[email protected]5b87e782012-02-09 18:19:323158#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513159 if (!media_stream_dispatcher_)
3160 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3161
3162 if (!media_stream_impl_.get()) {
3163 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3164 media_stream_impl_ = new MediaStreamImpl(
3165 media_stream_dispatcher_,
3166 p2p_socket_dispatcher_,
3167 RenderThreadImpl::current()->video_capture_impl_manager(),
3168 factory);
3169 }
[email protected]5b87e782012-02-09 18:19:323170#endif
[email protected]273558fb2012-01-12 15:03:513171}
3172
[email protected]310ebd6302011-10-10 19:06:283173void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3174 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313175 if (webview()->mainFrame() != frame)
3176 return;
3177 WebView* frameView = frame->view();
3178 if (!frameView)
3179 return;
3180
3181 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3182 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3183
3184 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3185 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3186 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3187 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3188
3189 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3190 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3191 }
3192}
3193
[email protected]310ebd6302011-10-10 19:06:283194void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313195 WebSize offset = frame->scrollOffset();
3196 WebSize minimum_offset = frame->minimumScrollOffset();
3197 WebSize maximum_offset = frame->maximumScrollOffset();
3198
3199 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3200 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3201
3202 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3203 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3204 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3205 routing_id_, is_pinned_to_left, is_pinned_to_right));
3206
3207 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3208 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3209 }
3210}
3211
[email protected]310ebd6302011-10-10 19:06:283212void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493213 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313214
3215 if (webview()->mainFrame() == frame)
3216 UpdateScrollState(frame);
3217}
3218
[email protected]310ebd6302011-10-10 19:06:283219void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313220 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493221}
3222
[email protected]ea931252012-02-15 22:01:033223void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3224 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3225}
3226
[email protected]310ebd6302011-10-10 19:06:283227void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3228 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113229 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3230 if (!count)
3231 active_match_ordinal = 0;
3232
3233 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3234 routing_id_,
3235 request_id,
3236 count,
3237 gfx::Rect(),
3238 active_match_ordinal,
3239 final_update);
3240
[email protected]8922e1f2009-10-03 05:01:263241 // If we have a message that has been queued up, then we should just replace
3242 // it. The ACK from the browser will make sure it gets sent when the browser
3243 // wants it.
3244 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263245 queued_find_reply_message_.reset(msg);
3246 } else {
3247 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113248 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263249 }
3250}
3251
[email protected]310ebd6302011-10-10 19:06:283252void RenderViewImpl::reportFindInPageSelection(int request_id,
3253 int active_match_ordinal,
3254 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263255 // Send the search result over to the browser process.
3256 Send(new ViewHostMsg_Find_Reply(routing_id_,
3257 request_id,
3258 -1,
3259 selection_rect,
3260 active_match_ordinal,
3261 false));
3262}
3263
[email protected]310ebd6302011-10-10 19:06:283264void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223265 WebFrame* frame,
3266 WebFileSystem::Type type,
3267 long long size,
[email protected]d275d7a2010-11-03 01:34:493268 bool create,
[email protected]2b06a992010-08-21 05:48:223269 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083270 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223271
[email protected]b6cb3a842011-06-24 18:28:413272 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563273 if (origin.isUnique()) {
3274 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083275 callbacks->didFail(WebKit::WebFileErrorAbort);
3276 return;
3277 }
[email protected]2b06a992010-08-21 05:48:223278
[email protected]c5a272d2010-09-27 18:37:083279 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3280 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493281 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223282}
3283
[email protected]310ebd6302011-10-10 19:06:283284void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403285 WebFrame* frame,
3286 WebStorageQuotaType type,
3287 WebStorageQuotaCallbacks* callbacks) {
3288 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413289 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563290 if (origin.isUnique()) {
3291 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403292 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3293 return;
3294 }
3295 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533296 GURL(origin.toString()),
3297 static_cast<quota::StorageType>(type),
3298 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403299}
3300
[email protected]310ebd6302011-10-10 19:06:283301void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403302 WebFrame* frame,
3303 WebStorageQuotaType type,
3304 unsigned long long requested_size,
3305 WebStorageQuotaCallbacks* callbacks) {
3306 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413307 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563308 if (origin.isUnique()) {
3309 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403310 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3311 return;
3312 }
3313 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533314 routing_id(), GURL(origin.toString()),
3315 static_cast<quota::StorageType>(type), requested_size,
3316 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403317}
3318
[email protected]8b5af492011-11-28 21:50:583319void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153320 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063321 string16 title = service.title();
3322 if (title.empty())
3323 title = webview()->mainFrame()->document().title();
3324
[email protected]8b5af492011-11-28 21:50:583325 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3326 service.action(),
3327 service.type(),
3328 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063329 title,
[email protected]8b5af492011-11-28 21:50:583330 service.disposition()));
3331}
3332
[email protected]ffc8bed2012-01-21 01:23:153333void RenderViewImpl::dispatchIntent(
3334 WebFrame* frame, const WebIntentRequest& intentRequest) {
3335 webkit_glue::WebIntentData intent_data(intentRequest.intent());
3336 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583337 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153338 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583339}
3340
[email protected]18d5be92011-07-25 18:00:193341// WebKit::WebPageSerializerClient implementation ------------------------------
3342
[email protected]310ebd6302011-10-10 19:06:283343void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193344 const WebURL& frame_url,
3345 const WebCString& data,
3346 WebPageSerializerClient::PageSerializationStatus status) {
3347 Send(new ViewHostMsg_SendSerializedHtmlData(
3348 routing_id(),
3349 frame_url,
3350 data.data(),
3351 static_cast<int32>(status)));
3352}
3353
[email protected]a2ef54c2011-10-10 16:20:313354// content::RenderView implementation ------------------------------------------
3355
[email protected]310ebd6302011-10-10 19:06:283356bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313357 return RenderWidget::Send(message);
3358}
3359
[email protected]310ebd6302011-10-10 19:06:283360int RenderViewImpl::GetRoutingId() const {
[email protected]a2ef54c2011-10-10 16:20:313361 return routing_id_;
3362}
3363
[email protected]310ebd6302011-10-10 19:06:283364int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313365 return page_id_;
3366}
3367
[email protected]310ebd6302011-10-10 19:06:283368gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313369 return size();
3370}
3371
[email protected]310ebd6302011-10-10 19:06:283372gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313373 return host_window();
3374}
3375
[email protected]310ebd6302011-10-10 19:06:283376WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313377 return webkit_preferences_;
3378}
3379
[email protected]310ebd6302011-10-10 19:06:283380WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313381 return webview();
3382}
3383
[email protected]310ebd6302011-10-10 19:06:283384WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313385 if (!webview())
3386 return WebNode();
3387 WebFrame* focused_frame = webview()->focusedFrame();
3388 if (focused_frame) {
3389 WebDocument doc = focused_frame->document();
3390 if (!doc.isNull())
3391 return doc.focusedNode();
3392 }
3393
3394 return WebNode();
3395}
3396
[email protected]310ebd6302011-10-10 19:06:283397WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313398 return context_menu_node_;
3399}
3400
[email protected]310ebd6302011-10-10 19:06:283401bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313402 bool is_editable_node = false;
3403 if (!node.isNull()) {
3404 if (node.isContentEditable()) {
3405 is_editable_node = true;
3406 } else if (node.isElementNode()) {
3407 is_editable_node =
3408 node.toConst<WebElement>().isTextFormControlElement();
3409 }
3410 }
3411 return is_editable_node;
3412}
3413
[email protected]310ebd6302011-10-10 19:06:283414WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313415 WebKit::WebFrame* frame,
3416 const webkit::WebPluginInfo& info,
3417 const WebKit::WebPluginParams& params) {
3418 bool pepper_plugin_was_registered = false;
3419 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3420 pepper_delegate_.CreatePepperPluginModule(info,
3421 &pepper_plugin_was_registered));
3422 if (pepper_plugin_was_registered) {
3423 if (!pepper_module)
3424 return NULL;
3425 return new webkit::ppapi::WebPluginImpl(
3426 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3427 }
3428
[email protected]34b27e442012-01-20 20:07:413429#if defined(USE_AURA)
3430 return NULL;
3431#else
[email protected]a2ef54c2011-10-10 16:20:313432 return new webkit::npapi::WebPluginImpl(
3433 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413434#endif
[email protected]a2ef54c2011-10-10 16:20:313435}
3436
[email protected]310ebd6302011-10-10 19:06:283437void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3438 const string16& jscript,
3439 int id,
3440 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313441 v8::Handle<v8::Value> result;
3442 WebFrame* web_frame = GetChildFrame(frame_xpath);
3443 if (web_frame)
3444 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3445 if (notify_result) {
3446 ListValue list;
3447 if (!result.IsEmpty() && web_frame) {
3448 v8::HandleScope handle_scope;
3449 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3450 v8::Context::Scope context_scope(context);
3451 V8ValueConverterImpl converter;
3452 converter.set_allow_date(true);
3453 converter.set_allow_regexp(true);
3454 list.Set(0, converter.FromV8Value(result, context));
3455 } else {
3456 list.Set(0, Value::CreateNullValue());
3457 }
3458 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3459 }
3460}
3461
[email protected]310ebd6302011-10-10 19:06:283462bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313463 return (!send_preferred_size_changes_ ||
3464 (disable_scrollbars_size_limit_.width() <= width ||
3465 disable_scrollbars_size_limit_.height() <= height));
3466}
3467
[email protected]310ebd6302011-10-10 19:06:283468int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313469 return enabled_bindings_;
3470}
3471
[email protected]310ebd6302011-10-10 19:06:283472bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313473 return send_content_state_immediately_;
3474}
3475
[email protected]310ebd6302011-10-10 19:06:283476float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313477 return filtered_time_per_frame();
3478}
3479
[email protected]310ebd6302011-10-10 19:06:283480void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3481 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313482 showContextMenu(frame, data);
3483}
3484
[email protected]310ebd6302011-10-10 19:06:283485WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313486 return visibilityState();
3487}
3488
[email protected]310ebd6302011-10-10 19:06:283489void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3490 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313491 return runModalAlertDialog(frame, message);
3492}
3493
[email protected]310ebd6302011-10-10 19:06:283494void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313495 WebKit::WebFrame* frame,
3496 const WebKit::WebURLRequest& request,
3497 WebKit::WebNavigationPolicy policy) {
3498 loadURLExternally(frame, request, policy);
3499}
3500
3501// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513502
[email protected]310ebd6302011-10-10 19:06:283503webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533504 const FilePath& file_path,
3505 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203506 if (!PluginChannelHost::IsListening()) {
3507 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593508 return NULL;
[email protected]94752ee2012-02-10 10:38:203509 }
[email protected]f103ab72009-09-02 17:10:593510
[email protected]00c39612010-03-06 02:53:283511 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463512 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323513#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223514 return webkit::npapi::WebPluginDelegateImpl::Create(
3515 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093516#else
[email protected]7398dcc2011-09-06 21:40:323517 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223518 NOTIMPLEMENTED();
3519 return NULL;
[email protected]7b6616f2010-01-14 18:07:553520#endif
[email protected]f103ab72009-09-02 17:10:593521 }
3522
[email protected]4e0616e2010-05-28 14:55:533523 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593524}
3525
[email protected]310ebd6302011-10-10 19:06:283526void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033527#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273528 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593529#endif
3530}
3531
[email protected]310ebd6302011-10-10 19:06:283532void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033533#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273534 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593535#endif
3536 CleanupWindowInPluginMoves(window);
3537}
3538
[email protected]310ebd6302011-10-10 19:06:283539void RenderViewImpl::DidMovePlugin(
3540 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593541 SchedulePluginMove(move);
3542}
3543
[email protected]310ebd6302011-10-10 19:06:283544void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593545 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523546 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593547}
3548
[email protected]310ebd6302011-10-10 19:06:283549void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593550 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523551 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593552}
3553
[email protected]310ebd6302011-10-10 19:06:283554WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513555 return &cookie_jar_;
3556}
3557
[email protected]a9288f52011-11-17 05:18:163558void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073559 Send(new ViewHostMsg_MediaNotification(routing_id_,
3560 reinterpret_cast<int64>(player),
3561 player->hasVideo(),
3562 player->hasAudio(),
3563 true));
3564}
3565
[email protected]a9288f52011-11-17 05:18:163566void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073567 Send(new ViewHostMsg_MediaNotification(routing_id_,
3568 reinterpret_cast<int64>(player),
3569 player->hasVideo(),
3570 player->hasAudio(),
3571 false));
3572}
3573
[email protected]a9288f52011-11-17 05:18:163574void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073575 DidPause(player);
3576}
3577
[email protected]310ebd6302011-10-10 19:06:283578void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293579 if (!webview())
3580 return;
3581
[email protected]26aa0482009-09-30 16:55:273582 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173583 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293584 return;
[email protected]ca948a22009-06-25 19:36:173585
3586 Send(new ViewHostMsg_UpdateState(
3587 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293588}
3589
[email protected]310ebd6302011-10-10 19:06:283590void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363591 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003592 if (!frame)
3593 return;
[email protected]b781ff282011-08-20 06:19:363594
[email protected]b781ff282011-08-20 06:19:363595 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003596 if (!webview()->caretOrSelectionRange(&location, &length))
3597 return;
3598
3599 string16 text;
3600 size_t offset;
3601 ui::Range range(location, location + length);
3602
3603 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3604 // If current focused element is editable, we will send 100 more chars
3605 // before and after selection. It is for input method surrounding text
3606 // feature.
3607 if (location > kExtraCharsBeforeAndAfterSelection)
3608 offset = location - kExtraCharsBeforeAndAfterSelection;
3609 else
3610 offset = 0;
3611 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3612 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3613 if (!webrange.isNull())
3614 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3615 } else {
3616 offset = location;
3617 text = frame->selectionAsText();
[email protected]e8cdf3532011-10-29 00:50:523618 // http://crbug.com/101435
3619 // In some case, frame->selectionAsText() returned text's length is not
3620 // equal to the length returned from webview()->caretOrSelectionRange().
3621 // So we have to set the range according to text.length().
3622 range.set_end(range.start() + text.length());
[email protected]b781ff282011-08-20 06:19:363623 }
3624
[email protected]b781ff282011-08-20 06:19:363625 // Sometimes we get repeated didChangeSelection calls from webkit when
3626 // the selection hasn't actually changed. We don't want to report these
3627 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003628 if (selection_text_offset_ != offset ||
3629 selection_range_ != range ||
3630 selection_text_ != text) {
3631 selection_text_ = text;
3632 selection_text_offset_ = offset;
3633 selection_range_ = range;
3634 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3635 }
[email protected]b781ff282011-08-20 06:19:363636}
3637
[email protected]310ebd6302011-10-10 19:06:283638GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3639 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553640 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293641 // If the URL that failed was secure, then the embedding web page was not
3642 // expecting a network attacker to be able to manipulate its contents. As
3643 // we fetch alternate error pages over HTTP, we would be allowing a network
3644 // attacker to manipulate the contents of the response if we tried to use
3645 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153646 return GURL();
initial.commit09911bf2008-07-26 23:55:293647 }
3648
3649 // Grab the base URL from the browser process.
3650 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153651 return GURL();
initial.commit09911bf2008-07-26 23:55:293652
3653 // Strip query params from the failed URL.
3654 GURL::Replacements remove_params;
3655 remove_params.ClearUsername();
3656 remove_params.ClearPassword();
3657 remove_params.ClearQuery();
3658 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553659 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503660 std::string spec_to_send = url_to_send.spec();
3661 // Notify link doctor of the url truncation by sending of "?" at the end.
3662 if (failed_url.has_query())
3663 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293664
3665 // Construct the query params to send to link doctor.
3666 std::string params(alternate_error_page_url_.query());
3667 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023668 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293669 params.append("&sourceid=chrome");
3670 params.append("&error=");
3671 switch (error_type) {
3672 case DNS_ERROR:
3673 params.append("dnserror");
3674 break;
3675
3676 case HTTP_404:
3677 params.append("http404");
3678 break;
3679
[email protected]5df266ac2008-10-15 19:50:133680 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333681 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133682 break;
3683
initial.commit09911bf2008-07-26 23:55:293684 default:
3685 NOTREACHED() << "unknown ErrorPageType";
3686 }
3687
3688 // OK, build the final url to return.
3689 GURL::Replacements link_doctor_params;
3690 link_doctor_params.SetQueryStr(params);
3691 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3692 return url;
3693}
3694
[email protected]310ebd6302011-10-10 19:06:283695GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593696 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3697 return GURL();
3698 else
3699 return creator_url_;
3700}
3701
[email protected]310ebd6302011-10-10 19:06:283702WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273703 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313704 web_ui_bindings_.reset(new WebUIBindings(
3705 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463706 }
[email protected]c50008512011-02-03 01:17:273707 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463708}
3709
[email protected]310ebd6302011-10-10 19:06:283710WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013711 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493712}
3713
[email protected]310ebd6302011-10-10 19:06:283714void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3715 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273716 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493717
[email protected]872542532011-06-23 00:43:163718 // Check if the plugin still exists in the document.
3719 if (main_frame->document().isPluginDocument() &&
3720 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493721 if (options.findNext) {
3722 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013723 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493724 } else {
[email protected]afdbd142010-07-10 08:01:233725 if (GetWebPluginFromPluginDocument()->startFind(
3726 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493727 } else {
[email protected]e7c58a32010-08-13 19:47:113728 // Send "no results".
3729 Send(new ViewHostMsg_Find_Reply(routing_id_,
3730 request_id,
3731 0,
3732 gfx::Rect(),
3733 0,
3734 true));
[email protected]24a7f3c2010-03-25 08:26:493735 }
3736 }
3737 return;
3738 }
3739
[email protected]b4bb2502009-10-01 22:35:273740 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273741 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293742 WebFrame* search_frame = focused_frame; // start searching focused frame.
3743
3744 bool multi_frame = (frame_after_main != main_frame);
3745
3746 // If we have multiple frames, we don't want to wrap the search within the
3747 // frame, so we check here if we only have main_frame in the chain.
3748 bool wrap_within_frame = !multi_frame;
3749
[email protected]b3f2b912009-04-09 16:18:523750 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293751 bool result = false;
3752
[email protected]7830da3e2009-11-06 16:27:263753 // If something is selected when we start searching it means we cannot just
3754 // increment the current match ordinal; we need to re-generate it.
3755 WebRange current_selection = focused_frame->selectionRange();
3756
initial.commit09911bf2008-07-26 23:55:293757 do {
[email protected]dd7daa82009-08-10 05:46:453758 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593759 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293760
3761 if (!result) {
3762 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223763 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293764
3765 // Find the next frame, but skip the invisible ones.
3766 do {
3767 // What is the next frame to search? (we might be going backwards). Note
3768 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593769 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273770 search_frame->traverseNext(true) :
3771 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453772 } while (!search_frame->hasVisibleContent() &&
3773 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293774
[email protected]884db412008-11-24 23:46:503775 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223776 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293777
3778 // If we have multiple frames and we have wrapped back around to the
3779 // focused frame, we need to search it once more allowing wrap within
3780 // the frame, otherwise it will report 'no match' if the focused frame has
3781 // reported matches, but no frames after the focused_frame contain a
3782 // match for the search word(s).
3783 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453784 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593785 request_id, search_text, options, true, // Force wrapping.
3786 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293787 }
3788 }
3789
[email protected]26aa0482009-09-30 16:55:273790 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293791 } while (!result && search_frame != focused_frame);
3792
[email protected]7830da3e2009-11-06 16:27:263793 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293794 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453795 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293796 } else {
3797 // If nothing is found, set result to "0 of 0", otherwise, set it to
3798 // "-1 of 1" to indicate that we found at least one item, but we don't know
3799 // yet what is active.
3800 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3801 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293802
[email protected]4f3dc372009-02-24 00:10:293803 // If we find no matches then this will be our last status update.
3804 // Otherwise the scoping effort will send more results.
3805 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293806
[email protected]4f3dc372009-02-24 00:10:293807 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403808 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593809 request_id,
[email protected]4f3dc372009-02-24 00:10:293810 match_count,
3811 selection_rect,
3812 ordinal,
3813 final_status_update));
initial.commit09911bf2008-07-26 23:55:293814
initial.commit09911bf2008-07-26 23:55:293815 // Scoping effort begins, starting with the mainframe.
3816 search_frame = main_frame;
3817
[email protected]dd7daa82009-08-10 05:46:453818 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293819
3820 do {
3821 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453822 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293823
3824 // We don't start another scoping effort unless at least one match has
3825 // been found.
3826 if (result) {
3827 // Start new scoping request. If the scoping function determines that it
3828 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453829 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593830 search_text,
3831 options,
initial.commit09911bf2008-07-26 23:55:293832 true); // reset the tickmarks
3833 }
3834
3835 // Iterate to the next frame. The frame will not necessarily scope, for
3836 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273837 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293838 } while (search_frame != main_frame);
3839 }
3840}
3841
[email protected]815dd9872011-11-23 18:40:303842void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493843 WebView* view = webview();
3844 if (!view)
3845 return;
3846
3847 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163848 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013849 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493850 return;
3851 }
3852
[email protected]815dd9872011-11-23 18:40:303853 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493854 if (clear_selection)
3855 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3856
3857 WebFrame* frame = view->mainFrame();
3858 while (frame) {
3859 frame->stopFinding(clear_selection);
3860 frame = frame->traverseNext(false);
3861 }
3862
[email protected]815dd9872011-11-23 18:40:303863 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493864 WebFrame* focused_frame = view->focusedFrame();
3865 if (focused_frame) {
3866 WebDocument doc = focused_frame->document();
3867 if (!doc.isNull()) {
3868 WebNode node = doc.focusedNode();
3869 if (!node.isNull())
3870 node.simulateClick();
3871 }
3872 }
3873 }
3874}
3875
[email protected]310ebd6302011-10-10 19:06:283876void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493877 // Check if there is any queued up request waiting to be sent.
3878 if (queued_find_reply_message_.get()) {
3879 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423880 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493881 }
3882}
3883
[email protected]54087fe2011-10-28 22:02:483884void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513885 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3886 return;
3887
[email protected]258d31122010-05-09 10:59:413888 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103889
[email protected]b75b8292010-10-01 07:28:253890 double old_zoom_level = webview()->zoomLevel();
3891 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483892 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253893 zoom_level = 0;
3894 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3895 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483896 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253897 } else {
3898 // Either the user hit the zoom factor limit and thus the zoom level is now
3899 // not a whole number, or a plugin changed it to a custom value. We want
3900 // to go to the next whole number so that the user can always get back to
3901 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483902 if ((old_zoom_level > 1 && zoom > 0) ||
3903 (old_zoom_level < 1 && zoom < 0)) {
3904 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253905 } else {
3906 // We're going towards 100%, so first go to the next whole number.
3907 zoom_level = static_cast<int>(old_zoom_level);
3908 }
3909 }
[email protected]b75b8292010-10-01 07:28:253910 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413911 zoomLevelChanged();
3912}
3913
3914void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3915 int zoom_center_x, int zoom_center_y) {
3916 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3917 kScalingIncrementForGesture);
3918}
3919
3920void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3921 int zoom_center_x,
3922 int zoom_center_y,
3923 float scaling_increment) {
3924 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3925 return;
3926
[email protected]c514d6372011-08-16 22:54:443927 double old_page_scale_factor = webview()->pageScaleFactor();
3928 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:483929 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:443930 page_scale_factor = 1.0;
3931 } else {
3932 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:413933 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:443934 }
[email protected]47578fa02011-11-02 19:34:413935 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:093936 webview()->setPageScaleFactor(page_scale_factor,
3937 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:413938 }
[email protected]40bd6582009-12-04 23:49:513939}
3940
[email protected]310ebd6302011-10-10 19:06:283941void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173942 webview()->hidePopups();
3943 webview()->setZoomLevel(false, zoom_level);
3944 zoomLevelChanged();
3945}
3946
[email protected]310ebd6302011-10-10 19:06:283947void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3948 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543949 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293950}
3951
[email protected]310ebd6302011-10-10 19:06:283952void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273953 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293954}
3955
[email protected]310ebd6302011-10-10 19:06:283956void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273957 WebString no_encoding;
3958 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183959}
3960
[email protected]310ebd6302011-10-10 19:06:283961WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453962 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273963 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453964
3965 // xpath string can represent a frame deep down the tree (across multiple
3966 // frame DOMs).
3967 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3968 // should break into 2 xpaths
3969 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413970 std::vector<string16> xpaths;
3971 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453972
[email protected]26aa0482009-09-30 16:55:273973 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413974 for (std::vector<string16>::const_iterator i = xpaths.begin();
3975 frame && i != xpaths.end(); ++i) {
3976 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293977 }
3978
[email protected]dd7daa82009-08-10 05:46:453979 return frame;
initial.commit09911bf2008-07-26 23:55:293980}
3981
[email protected]310ebd6302011-10-10 19:06:283982void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
3983 const string16& jscript,
3984 int id,
3985 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:533986 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293987}
3988
[email protected]310ebd6302011-10-10 19:06:283989void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
3990 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413991 WebFrame* frame = GetChildFrame(frame_xpath);
3992 if (!frame)
[email protected]216813952011-05-19 22:21:263993 return;
[email protected]ae461542009-06-19 19:03:413994
[email protected]01cf589c2011-07-28 18:04:033995 frame->document().insertUserStyleSheet(
3996 WebString::fromUTF8(css),
3997 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483998}
3999
[email protected]310ebd6302011-10-10 19:06:284000void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094001 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294002}
4003
[email protected]310ebd6302011-10-10 19:06:284004void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4005 const std::string& value) {
[email protected]e091df82011-10-11 18:13:214006 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:274007 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294008}
4009
[email protected]310ebd6302011-10-10 19:06:284010void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4011 const gfx::Point& client_point,
4012 const gfx::Point& screen_point,
4013 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554014 WebDragOperation operation = webview()->dragTargetDragEnter(
4015 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554016 client_point,
4017 screen_point,
4018 ops);
4019
4020 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4021}
4022
[email protected]310ebd6302011-10-10 19:06:284023void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4024 const gfx::Point& screen_point,
4025 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554026 WebDragOperation operation = webview()->dragTargetDragOver(
4027 client_point,
4028 screen_point,
4029 ops);
4030
4031 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4032}
4033
[email protected]310ebd6302011-10-10 19:06:284034void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554035 webview()->dragTargetDragLeave();
4036}
4037
[email protected]310ebd6302011-10-10 19:06:284038void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
4039 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:554040 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:574041
4042 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554043}
4044
[email protected]310ebd6302011-10-10 19:06:284045void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4046 const gfx::Point& screen_point,
4047 bool ended,
4048 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034049 if (ended) {
[email protected]26aa0482009-09-30 16:55:274050 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204051 } else {
4052 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034053 }
initial.commit09911bf2008-07-26 23:55:294054}
4055
[email protected]310ebd6302011-10-10 19:06:284056void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274057 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294058}
4059
[email protected]310ebd6302011-10-10 19:06:284060void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594061 webkit_preferences_ = prefs;
4062 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294063}
4064
[email protected]310ebd6302011-10-10 19:06:284065void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294066 alternate_error_page_url_ = url;
4067}
4068
[email protected]310ebd6302011-10-10 19:06:284069void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514070 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084071 unsigned action) {
4072 if (custom_context.is_pepper_menu)
4073 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4074 else
4075 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584076 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4077 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334078}
4079
[email protected]310ebd6302011-10-10 19:06:284080void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514081 int id,
4082 const std::vector<FilePath>& paths) {
4083 if (!enumeration_completions_[id])
4084 return;
4085
4086 WebVector<WebString> ws_file_names(paths.size());
4087 for (size_t i = 0; i < paths.size(); ++i)
4088 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4089
4090 enumeration_completions_[id]->didChooseFile(ws_file_names);
4091 enumeration_completions_.erase(id);
4092}
4093
[email protected]310ebd6302011-10-10 19:06:284094void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364095 // This could happen if we navigated to a different page before the user
4096 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474097 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364098 return;
4099
[email protected]cdaf8d02010-03-30 19:52:474100 WebVector<WebString> ws_file_names(paths.size());
4101 for (size_t i = 0; i < paths.size(); ++i)
4102 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464103
[email protected]cdaf8d02010-03-30 19:52:474104 if (file_chooser_completions_.front()->completion)
4105 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4106 file_chooser_completions_.pop_front();
4107
4108 // If there are more pending file chooser requests, schedule one now.
4109 if (!file_chooser_completions_.empty()) {
4110 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4111 file_chooser_completions_.front()->params));
4112 }
initial.commit09911bf2008-07-26 23:55:294113}
4114
[email protected]244ac1892011-12-02 17:04:474115void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4116 const gfx::Size& max_size) {
4117 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4118 if (!webview())
4119 return;
4120 webview()->enableAutoResizeMode(true, min_size, max_size);
4121}
4122
[email protected]2bf834f2011-11-17 20:02:214123void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244124 if (send_preferred_size_changes_)
4125 return;
[email protected]9fb325e2010-05-06 18:23:244126 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394127
[email protected]d812fd12011-05-27 23:05:074128 // Start off with an initial preferred size notification (in case
4129 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594130 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084131}
4132
[email protected]310ebd6302011-10-10 19:06:284133void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104134 const gfx::Size& disable_scrollbar_size_limit) {
4135 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4136}
4137
[email protected]310ebd6302011-10-10 19:06:284138void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314139 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504140 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514141 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374142 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134143#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414144 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4145 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464146 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:514147 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344148 renderer_prefs.thumb_inactive_color,
4149 renderer_prefs.thumb_active_color,
4150 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324151
[email protected]644d77e2010-01-27 01:03:104152 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324153 webview()->setScrollbarColors(
4154 renderer_prefs.thumb_inactive_color,
4155 renderer_prefs.thumb_active_color,
4156 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104157 webview()->setSelectionColors(
4158 renderer_prefs.active_selection_bg_color,
4159 renderer_prefs.active_selection_fg_color,
4160 renderer_prefs.inactive_selection_bg_color,
4161 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464162 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104163 }
[email protected]7a74e102009-09-03 00:16:564164#endif
[email protected]d051d9a2011-12-10 02:02:504165 // If the zoom level for this page matches the old zoom default, and this
4166 // is not a plugin, update the zoom level to match the new default.
4167 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4168 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4169 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4170 zoomLevelChanged();
4171 }
[email protected]80d96fa2009-06-10 22:34:514172}
4173
[email protected]310ebd6302011-10-10 19:06:284174void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4175 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284176 if (webview())
4177 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564178}
4179
[email protected]81375e872012-01-11 21:40:364180void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4181 const WebPluginAction& action) {
4182 if (webview())
4183 webview()->performPluginAction(action, location);
4184}
4185
[email protected]310ebd6302011-10-10 19:06:284186void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194187 const GURL& page_url) {
4188 // Prepare list to storage all savable resource links.
4189 std::vector<GURL> resources_list;
4190 std::vector<GURL> referrers_list;
4191 std::vector<GURL> frames_list;
4192 webkit_glue::SavableResourcesResult result(&resources_list,
4193 &referrers_list,
4194 &frames_list);
4195
[email protected]445e1042011-12-03 21:03:154196 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4197 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194198 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4199 webview(),
4200 page_url,
4201 &result,
[email protected]2a80aee2011-10-07 16:06:034202 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194203 // If something is wrong when collecting all savable resource links,
4204 // send empty list to embedder(browser) to tell it failed.
4205 referrers_list.clear();
4206 resources_list.clear();
4207 frames_list.clear();
4208 }
4209
4210 // Send result of all savable resource links to embedder.
4211 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4212 resources_list,
4213 referrers_list,
4214 frames_list));
4215}
4216
[email protected]310ebd6302011-10-10 19:06:284217void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194218 const std::vector<GURL>& links,
4219 const std::vector<FilePath>& local_paths,
4220 const FilePath& local_directory_name) {
4221
4222 // Convert std::vector of GURLs to WebVector<WebURL>
4223 WebVector<WebURL> weburl_links(links);
4224
4225 // Convert std::vector of std::strings to WebVector<WebString>
4226 WebVector<WebString> webstring_paths(local_paths.size());
4227 for (size_t i = 0; i < local_paths.size(); i++)
4228 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4229
4230 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4231 webstring_paths,
4232 webkit_glue::FilePathToWebString(
4233 local_directory_name));
4234}
4235
[email protected]310ebd6302011-10-10 19:06:284236void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274237 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474238 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294239}
4240
[email protected]310ebd6302011-10-10 19:06:284241void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]73eb2602012-02-09 19:50:554242 // Only run unload if we're not swapped out yet, but send the ack either way.
4243 if (!is_swapped_out_) {
4244 // Swap this RenderView out so the tab can navigate to a page rendered by a
4245 // different process. This involves running the unload handler and clearing
4246 // the page. Once WasSwappedOut is called, we also allow this process to
4247 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154248
[email protected]73eb2602012-02-09 19:50:554249 // Send an UpdateState message before we get swapped out.
4250 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154251
[email protected]73eb2602012-02-09 19:50:554252 // Synchronously run the unload handler before sending the ACK.
4253 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154254
[email protected]73eb2602012-02-09 19:50:554255 // Swap out and stop sending any IPC messages that are not ACKs.
4256 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154257
[email protected]73eb2602012-02-09 19:50:554258 // Replace the page with a blank dummy URL. The unload handler will not be
4259 // run a second time, thanks to a check in FrameLoader::stopLoading.
4260 // TODO(creis): Need to add a better way to do this that avoids running the
4261 // beforeunload handler. For now, we just run it a second time silently.
4262 webview()->mainFrame()->loadHTMLString(std::string(),
4263 GURL("about:swappedout"),
4264 GURL("about:swappedout"),
4265 false);
4266 }
[email protected]992db4c2011-05-12 15:37:154267
4268 // Just echo back the params in the ACK.
4269 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4270}
4271
[email protected]310ebd6302011-10-10 19:06:284272void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374273 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294274 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4275 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4276 // in the onunload handler from appearing. For now, we're bypassing that and
4277 // calling the FrameLoader's CloseURL method directly. This should be
4278 // revisited to avoid having two ways to close a page. Having a single way
4279 // to close that can run onunload is also useful for fixing
4280 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274281 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294282
[email protected]992db4c2011-05-12 15:37:154283 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294284}
4285
[email protected]310ebd6302011-10-10 19:06:284286void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024287#if defined(USE_AURA)
4288 // Aura doesn't care if we switch themes.
4289#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164290 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464291 if (webview())
4292 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574293#else // defined(OS_WIN)
4294 // TODO(port): we don't support theming on non-Windows platforms yet
4295 NOTIMPLEMENTED();
4296#endif
initial.commit09911bf2008-07-26 23:55:294297}
4298
[email protected]310ebd6302011-10-10 19:06:284299void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084300 if (decrement_shared_popup_at_destruction_)
4301 shared_popup_counter_->data--;
4302 shared_popup_counter_ = new SharedRenderViewCounter(0);
4303 decrement_shared_popup_at_destruction_ = false;
4304}
4305
[email protected]310ebd6302011-10-10 19:06:284306bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4307 const WebURLError& error,
4308 bool replace) {
[email protected]15d79e12009-08-02 19:23:454309 // We only show alternate error pages in the main frame. They are
4310 // intended to assist the user when navigating, so there is not much
4311 // value in showing them for failed subframes. Ideally, we would be
4312 // able to use the TYPED transition type for this, but that flag is
4313 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454314 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454315 return false;
4316
4317 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374318 // connection failure.
[email protected]15d79e12009-08-02 19:23:454319 int ec = error.reason;
4320 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4321 ec != net::ERR_CONNECTION_FAILED &&
4322 ec != net::ERR_CONNECTION_REFUSED &&
4323 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374324 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454325 return false;
4326
4327 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554328 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454329 if (!error_page_url.is_valid())
4330 return false;
4331
4332 // Load an empty page first so there is an immediate response to the error,
4333 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454334 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364335 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454336 error.unreachableURL,
4337 replace);
4338
4339 // Now, create a fetcher for the error page and associate it with the data
4340 // source we just created via the LoadHTMLString call. That way if another
4341 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074342 DocumentState* document_state =
4343 DocumentState::FromDataSource(frame->provisionalDataSource());
4344 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454345 new AltErrorPageResourceFetcher(
4346 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084347 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4348 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454349 return true;
4350}
4351
[email protected]310ebd6302011-10-10 19:06:284352void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4353 const WebURLError& original_error,
4354 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454355 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094356 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554357 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094358 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454359}
4360
[email protected]310ebd6302011-10-10 19:06:284361void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004362 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474363 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004364}
4365
[email protected]310ebd6302011-10-10 19:06:284366void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094367 const gfx::Rect& resizer_rect,
4368 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104369 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474370 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104371 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204372 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314373 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104374 }
[email protected]dd6afca2011-08-13 03:44:314375 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104376 }
4377
[email protected]ee41e7d22011-10-14 19:34:094378 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004379}
[email protected]0aa477bd2009-03-23 22:21:434380
[email protected]29ed96a2012-02-04 18:12:164381void RenderViewImpl::WillInitiatePaint() {
4382 // Notify the pepper plugins that we're about to paint.
4383 pepper_delegate_.ViewWillInitiatePaint();
4384}
4385
[email protected]310ebd6302011-10-10 19:06:284386void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164387 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014388 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284389}
4390
[email protected]310ebd6302011-10-10 19:06:284391void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284392 // Notify any pepper plugins that we painted. This will call into the plugin,
4393 // and we it may ask to close itself as a result. This will, in turn, modify
4394 // our set, possibly invalidating the iterator. So we iterate on a copy that
4395 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014396 pepper_delegate_.ViewFlushedPaint();
4397
[email protected]5b1dec8c2012-02-07 04:35:384398 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4399 // See crbug.com/112921.
4400 if (!webview())
4401 return;
4402
[email protected]00c39612010-03-06 02:53:284403 WebFrame* main_frame = webview()->mainFrame();
4404
4405 // If we have a provisional frame we are between the start and commit stages
4406 // of loading and we don't want to save stats.
4407 if (!main_frame->provisionalDataSource()) {
4408 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074409 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284410
[email protected]05c8e502010-08-15 15:13:524411 // TODO(jar): The following code should all be inside a method, probably in
4412 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284413 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074414 if (document_state->first_paint_time().is_null()) {
4415 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284416 }
[email protected]007733c2011-11-17 00:34:074417 if (document_state->first_paint_after_load_time().is_null() &&
4418 !document_state->finish_load_time().is_null()) {
4419 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284420 }
4421 }
4422}
4423
[email protected]310ebd6302011-10-10 19:06:284424void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084425 RenderWidget::OnSwapBuffersPosted();
4426}
4427
[email protected]310ebd6302011-10-10 19:06:284428void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244429 RenderWidget::OnSwapBuffersComplete();
4430}
4431
[email protected]310ebd6302011-10-10 19:06:284432void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244433 RenderWidget::OnSwapBuffersAborted();
4434}
4435
[email protected]310ebd6302011-10-10 19:06:284436webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154437 const gfx::Rect& paint_bounds,
4438 TransportDIB** dib,
4439 gfx::Rect* location,
4440 gfx::Rect* clip) {
4441 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4442 paint_bounds, dib, location, clip);
4443}
4444
[email protected]310ebd6302011-10-10 19:06:284445gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074446 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434447 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524448}
4449
[email protected]310ebd6302011-10-10 19:06:284450void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164451 if (webview())
[email protected]26aa0482009-09-30 16:55:274452 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164453}
4454
[email protected]310ebd6302011-10-10 19:06:284455void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144456 if (webview())
[email protected]b4bb2502009-10-01 22:35:274457 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144458
4459 SetBackground(background);
4460}
4461
[email protected]310ebd6302011-10-10 19:06:284462void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344463 if (webview())
[email protected]b4bb2502009-10-01 22:35:274464 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264465
4466#if defined(OS_MACOSX)
4467 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4468 for (plugin_it = plugin_delegates_.begin();
4469 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4470 (*plugin_it)->SetWindowFocus(active);
4471 }
4472#endif
[email protected]8c66c5a2009-07-22 17:26:344473}
4474
[email protected]6ce7abc52010-02-02 18:40:144475#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284476void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144477 // Inform plugins that their container has changed visibility.
4478 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4479 for (plugin_it = plugin_delegates_.begin();
4480 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4481 (*plugin_it)->SetContainerVisibility(visible);
4482 }
4483}
[email protected]1e6e3c992010-02-08 15:52:134484
[email protected]310ebd6302011-10-10 19:06:284485void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4486 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134487 // Inform plugins that their window's frame has changed.
4488 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4489 for (plugin_it = plugin_delegates_.begin();
4490 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4491 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4492 }
4493}
[email protected]935d63d2010-10-15 23:31:554494
[email protected]310ebd6302011-10-10 19:06:284495void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4496 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134497 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554498 // applies to it or not, so inform all the delegates.
4499 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4500 for (plugin_it = plugin_delegates_.begin();
4501 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134502 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554503 }
4504}
[email protected]6ce7abc52010-02-02 18:40:144505#endif // OS_MACOSX
4506
[email protected]310ebd6302011-10-10 19:06:284507void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484508 const EditCommands& edit_commands) {
4509 edit_commands_ = edit_commands;
4510}
4511
[email protected]310ebd6302011-10-10 19:06:284512void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594513 // We need to grab a pointer to the doomed WebView before we destroy it.
4514 WebView* doomed = webview();
4515 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494516 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594517}
4518
[email protected]310ebd6302011-10-10 19:06:284519void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484520 edit_commands_.clear();
4521}
4522
[email protected]310ebd6302011-10-10 19:06:284523bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:114524 pepper_delegate_.WillHandleMouseEvent();
4525
4526 // If the mouse is locked, only the current owner of the mouse lock can
4527 // process mouse events.
4528 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374529}
4530
[email protected]310ebd6302011-10-10 19:06:284531void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514532 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064533}
4534
[email protected]310ebd6302011-10-10 19:06:284535void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244536 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4537}
4538
[email protected]310ebd6302011-10-10 19:06:284539void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434540 RenderWidget::OnWasHidden();
4541
[email protected]a6939ca42011-02-18 17:58:074542 if (webview()) {
4543 webview()->settings()->setMinimumTimerInterval(
4544 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444545 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074546 }
4547
[email protected]204f1df2012-01-04 20:21:134548 // Inform PPAPI plugins that their page is no longer visible.
4549 pepper_delegate_.PageVisibilityChanged(false);
4550
[email protected]a6939ca42011-02-18 17:58:074551#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134552 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434553 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4554 for (plugin_it = plugin_delegates_.begin();
4555 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4556 (*plugin_it)->SetContainerVisibility(false);
4557 }
[email protected]a6939ca42011-02-18 17:58:074558#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434559}
4560
[email protected]310ebd6302011-10-10 19:06:284561void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434562 RenderWidget::OnWasRestored(needs_repainting);
4563
[email protected]a6939ca42011-02-18 17:58:074564 if (webview()) {
4565 webview()->settings()->setMinimumTimerInterval(
4566 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444567 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074568 }
4569
[email protected]204f1df2012-01-04 20:21:134570 // Inform PPAPI plugins that their page is visible.
4571 pepper_delegate_.PageVisibilityChanged(true);
4572
[email protected]a6939ca42011-02-18 17:58:074573#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134574 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434575 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4576 for (plugin_it = plugin_delegates_.begin();
4577 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4578 (*plugin_it)->SetContainerVisibility(true);
4579 }
[email protected]784ea1ab2010-09-18 00:02:344580#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074581}
[email protected]1e6e3c992010-02-08 15:52:134582
[email protected]310ebd6302011-10-10 19:06:284583bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384584 if (WebWidgetHandlesCompositorScheduling())
4585 return false;
4586
[email protected]05a980d7a2012-02-07 22:16:424587 if (queried_for_swapbuffers_complete_callback_)
4588 return context_has_swapbuffers_complete_callback_;
4589
4590 queried_for_swapbuffers_complete_callback_ = true;
4591
[email protected]65225772011-05-12 21:10:244592 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:424593 if (context && context->makeContextCurrent()) {
4594 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4595 context_has_swapbuffers_complete_callback_ =
4596 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
4597 != std::string::npos;
4598 }
4599
4600 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:244601}
4602
[email protected]310ebd6302011-10-10 19:06:284603void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134604 RenderWidget::OnSetFocus(enable);
4605
[email protected]7d3c02c2010-05-05 23:10:314606 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074607 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134608 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4609 for (plugin_it = plugin_delegates_.begin();
4610 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344611#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314612 // RenderWidget's call to setFocus can cause the underlying webview's
4613 // activation state to change just like a call to setIsActive.
4614 if (enable)
4615 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344616#endif
[email protected]7d3c02c2010-05-05 23:10:314617 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134618 }
[email protected]589621b2010-09-23 22:01:074619
4620 // Notify all Pepper plugins.
4621 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134622 }
4623}
[email protected]941e4552010-02-01 21:23:434624
[email protected]310ebd6302011-10-10 19:06:284625void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004626 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504627 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574628}
4629
[email protected]73bf95812011-10-12 11:38:324630void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004631 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324632}
4633
[email protected]3f783362011-10-21 22:40:504634void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4635 UpdateSelectionBounds();
4636}
4637
[email protected]b25b3ee2012-01-13 05:19:544638bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4639 if (!pepper_delegate_.IsPluginFocused())
4640 return false;
4641 *rect = pepper_delegate_.GetCaretBounds();
4642 return true;
4643}
4644
[email protected]73bf95812011-10-12 11:38:324645void RenderViewImpl::PpapiPluginCancelComposition() {
4646 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4647 ui::Range range(ui::Range::InvalidRange());
4648 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4649}
4650
[email protected]310ebd6302011-10-10 19:06:284651void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574652 const string16& text,
4653 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4654 int selection_start,
4655 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324656 if (pepper_delegate_.IsPluginFocused()) {
4657 // When a PPAPI plugin has focus, we bypass WebKit.
4658 pepper_delegate_.OnImeSetComposition(text,
4659 underlines,
4660 selection_start,
4661 selection_end);
4662 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234663#if defined(OS_WIN)
4664 // When a plug-in has focus, we create platform-specific IME data used by
4665 // our IME emulator and send it directly to the focused plug-in, i.e. we
4666 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4667 // instance ID is the same one as the specified ID.)
4668 if (focused_plugin_id_ >= 0) {
4669 std::vector<int> clauses;
4670 std::vector<int> target;
4671 for (size_t i = 0; i < underlines.size(); ++i) {
4672 clauses.push_back(underlines[i].startOffset);
4673 clauses.push_back(underlines[i].endOffset);
4674 if (underlines[i].thick) {
4675 target.clear();
4676 target.push_back(underlines[i].startOffset);
4677 target.push_back(underlines[i].endOffset);
4678 }
4679 }
4680 std::set<WebPluginDelegateProxy*>::iterator it;
4681 for (it = plugin_delegates_.begin();
4682 it != plugin_delegates_.end(); ++it) {
4683 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4684 focused_plugin_id_);
4685 }
4686 return;
4687 }
4688#endif
[email protected]56ea1a62011-05-30 07:05:574689 RenderWidget::OnImeSetComposition(text,
4690 underlines,
4691 selection_start,
4692 selection_end);
4693 }
4694}
4695
[email protected]4de6d1692011-10-12 08:45:444696void RenderViewImpl::OnImeConfirmComposition(
4697 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574698 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324699 // When a PPAPI plugin has focus, we bypass WebKit.
4700 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574701 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234702#if defined(OS_WIN)
4703 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4704 // plug-ins. When we send IME text directly to plug-ins, we should not send
4705 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444706 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234707 if (focused_plugin_id_ >= 0) {
4708 std::set<WebPluginDelegateProxy*>::iterator it;
4709 for (it = plugin_delegates_.begin();
4710 it != plugin_delegates_.end(); ++it) {
4711 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4712 }
4713 return;
4714 }
4715#endif
[email protected]ebd28ac2011-10-13 18:49:054716 if (replacement_range.IsValid() && webview()) {
4717 // Select the text in |replacement_range|, it will then be replaced by
4718 // text added by the call to RenderWidget::OnImeConfirmComposition().
4719 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164720 WebRange webrange = WebRange::fromDocumentRange(
4721 frame, replacement_range.start(), replacement_range.length());
4722 if (!webrange.isNull())
4723 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054724 }
4725 }
[email protected]4de6d1692011-10-12 08:45:444726 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574727 }
4728}
4729
[email protected]310ebd6302011-10-10 19:06:284730ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324731 return pepper_delegate_.IsPluginFocused() ?
4732 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4733}
4734
[email protected]3f783362011-10-21 22:40:504735void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4736 if (pepper_delegate_.IsPluginFocused()) {
4737 // TODO(kinaba) http://crbug.com/101101
4738 // Current Pepper IME API does not handle selection bounds. So we simply
4739 // use the caret position as an empty range for now. It will be updated
4740 // after Pepper API equips features related to surrounding text retrieval.
4741 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4742 *start = caret;
4743 *end = caret;
4744 return;
4745 }
4746 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454747}
4748
[email protected]310ebd6302011-10-10 19:06:284749bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324750 return pepper_delegate_.IsPluginFocused() ?
4751 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574752}
4753
[email protected]e6ae0f6c2011-10-04 10:39:234754#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284755void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234756 if (focused)
4757 focused_plugin_id_ = plugin_id;
4758 else
4759 focused_plugin_id_ = -1;
4760}
4761#endif
4762
[email protected]43f28f832010-02-03 02:28:484763#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284764void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134765 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4766 focused, plugin_id);
4767 Send(msg);
4768}
4769
[email protected]310ebd6302011-10-10 19:06:284770void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134771 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554772 // This message can be sent during event-handling, and needs to be delivered
4773 // within that context.
4774 msg->set_unblock(true);
4775 Send(msg);
4776}
4777
[email protected]310ebd6302011-10-10 19:06:284778gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234779 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484780 gfx::PluginWindowHandle window = NULL;
4781 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234782 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114783 if (window) {
4784 fake_plugin_window_handles_.insert(window);
4785 }
[email protected]43f28f832010-02-03 02:28:484786 return window;
4787}
4788
[email protected]310ebd6302011-10-10 19:06:284789void RenderViewImpl::DestroyFakePluginWindowHandle(
4790 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114791 if (window && fake_plugin_window_handles_.find(window) !=
4792 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484793 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114794 fake_plugin_window_handles_.erase(window);
4795 }
[email protected]43f28f832010-02-03 02:28:484796}
4797
[email protected]310ebd6302011-10-10 19:06:284798void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4799 gfx::PluginWindowHandle window,
4800 int32 width,
4801 int32 height,
4802 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334803 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484804 routing_id(), window, width, height, io_surface_identifier));
4805}
4806
[email protected]310ebd6302011-10-10 19:06:284807void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334808 gfx::PluginWindowHandle window,
4809 int32 width,
4810 int32 height,
4811 TransportDIB::Handle transport_dib) {
4812 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074813 routing_id(), window, width, height, transport_dib));
4814}
4815
[email protected]310ebd6302011-10-10 19:06:284816TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334817 size_t size) {
[email protected]1aef98132010-02-23 18:00:074818 TransportDIB::Handle dib_handle;
4819 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384820 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074821 return dib_handle;
4822 // Return an invalid handle if Send() fails.
4823 return TransportDIB::DefaultHandleValue();
4824}
4825
[email protected]310ebd6302011-10-10 19:06:284826void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4827 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074828 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4829}
4830
[email protected]310ebd6302011-10-10 19:06:284831void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144832 gfx::PluginWindowHandle window, uint64 surface_id) {
4833 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4834 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484835}
4836#endif
[email protected]58c321d2010-02-19 12:11:284837
[email protected]310ebd6302011-10-10 19:06:284838bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234839 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474840 WebFileChooserCompletion* completion) {
4841 static const size_t kMaximumPendingFileChooseRequests = 4;
4842 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4843 // This sanity check prevents too many file choose requests from getting
4844 // queued which could DoS the user. Getting these is most likely a
4845 // programming error (there are many ways to DoS the user so it's not
4846 // considered a "real" security check), either in JS requesting many file
4847 // choosers to pop up, or in a plugin.
4848 //
4849 // TODO(brettw) we might possibly want to require a user gesture to open
4850 // a file picker, which will address this issue in a better way.
4851 return false;
4852 }
4853
4854 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4855 new PendingFileChooser(params, completion)));
4856 if (file_chooser_completions_.size() == 1) {
4857 // Actually show the browse dialog when this is the first request.
4858 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4859 }
4860 return true;
4861}
4862
[email protected]310ebd6302011-10-10 19:06:284863WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514864 if (!geolocation_dispatcher_)
4865 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4866 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254867}
[email protected]61c9f032010-03-31 23:04:194868
[email protected]310ebd6302011-10-10 19:06:284869WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114870 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224871#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514872 if (!speech_input_dispatcher_)
4873 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224874#endif
[email protected]676126f72011-01-15 00:03:514875 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114876}
4877
[email protected]310ebd6302011-10-10 19:06:284878WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514879 if (!device_orientation_dispatcher_)
4880 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4881 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534882}
4883
[email protected]310ebd6302011-10-10 19:06:284884void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4885 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254886 // For now, don't remember plugin zoom values. We don't want to mix them with
4887 // normal web content (i.e. a fixed layout plugin would usually want them
4888 // different).
4889 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4890
[email protected]b75b8292010-10-01 07:28:254891 int minimum_percent = static_cast<int>(
4892 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4893 int maximum_percent = static_cast<int>(
4894 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254895
4896 Send(new ViewHostMsg_UpdateZoomLimits(
4897 routing_id_, minimum_percent, maximum_percent, remember));
4898}
4899
[email protected]310ebd6302011-10-10 19:06:284900void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254901 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084902 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:254903 // Tell the browser which url got zoomed so it can update the menu and the
4904 // saved values if necessary
4905 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084906 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414907 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254908}
4909
[email protected]310ebd6302011-10-10 19:06:284910void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4911 const WebString& base_url,
4912 const WebString& url,
4913 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484914 GURL base(base_url);
4915 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4916 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4917 return;
4918 }
[email protected]f1a29a02011-10-06 23:08:444919 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4920 UTF16ToUTF8(scheme),
4921 absolute_url,
4922 title));
[email protected]a6d36cc2011-02-23 00:39:484923}
4924
[email protected]310ebd6302011-10-10 19:06:284925WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444926 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4927 WebKit::WebPageVisibilityStateHidden :
4928 WebKit::WebPageVisibilityStateVisible;
4929 WebKit::WebPageVisibilityState override_state = current_state;
4930 if (content::GetContentClient()->renderer()->
4931 ShouldOverridePageVisibilityState(this,
4932 &override_state))
4933 return override_state;
4934 return current_state;
[email protected]94dec932011-05-26 20:04:214935}
4936
[email protected]273558fb2012-01-12 15:03:514937WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
4938 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
4939 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
4940 return NULL;
4941 EnsureMediaStreamImpl();
4942 return media_stream_impl_;
4943}
4944
[email protected]310ebd6302011-10-10 19:06:284945bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194946 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454947 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194948 if (frame->parent() != NULL)
4949 return false;
4950
[email protected]f0a3d0b2010-08-06 22:51:534951 // Navigations initiated within Webkit are not sent out to the external host
4952 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274953 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134954 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534955 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134956 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334957 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534958 return false;
4959
[email protected]2fc22d12010-12-02 23:08:164960 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324961 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014962 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164963 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014964 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324965 // The opener relationship between the new window and the parent allows the
4966 // new window to script the parent and vice versa. This is not allowed if
4967 // the origins of the two domains are different. This can be treated as a
4968 // top level navigation and routed back to the host.
4969 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274970 if (!opener) {
[email protected]86965362011-04-21 18:42:514971 return true;
[email protected]d19ea342011-04-20 20:31:134972 } else {
[email protected]b6cb3a842011-06-24 18:28:414973 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324974 return true;
4975 }
4976 }
[email protected]61c9f032010-03-31 23:04:194977 return false;
4978}
[email protected]2b06a992010-08-21 05:48:224979
[email protected]310ebd6302011-10-10 19:06:284980void RenderViewImpl::OnAsyncFileOpened(
4981 base::PlatformFileError error_code,
4982 IPC::PlatformFileForTransit file_for_transit,
4983 int message_id) {
[email protected]27a9ef32010-09-10 04:06:244984 pepper_delegate_.OnAsyncFileOpened(
4985 error_code,
4986 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4987 message_id);
4988}
[email protected]caf706f2010-10-26 17:54:084989
[email protected]310ebd6302011-10-10 19:06:284990void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:474991 int request_id,
4992 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434993 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474994 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4995 broker_process_handle,
4996 handle);
[email protected]eb415bf0e2011-04-14 02:45:424997}
4998
[email protected]caf706f2010-10-26 17:54:084999#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285000void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155001 if (external_popup_menu_ == NULL) {
5002 // Crash reports from the field indicate that we can be notified with a
5003 // NULL external popup menu (we probably get notified twice).
5004 // If you hit this please file a bug against jcivelli and include the page
5005 // and steps to repro.
5006 NOTREACHED();
5007 return;
5008 }
[email protected]caf706f2010-10-26 17:54:085009 external_popup_menu_->DidSelectItem(selected_index);
5010 external_popup_menu_.reset();
5011}
5012#endif
[email protected]bb461532010-11-26 21:50:235013
[email protected]1b4209f2011-01-07 00:25:405014#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:285015void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:405016 int request_id,
5017 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:495018 const PP_NetAddress_Private& local_addr,
5019 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:405020 pepper_delegate_.OnConnectTcpACK(
5021 request_id,
5022 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5023 local_addr,
5024 remote_addr);
5025}
5026#endif
[email protected]a6097f42011-01-10 08:50:515027
[email protected]310ebd6302011-10-10 19:06:285028void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515029 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085030 if (custom_context.is_pepper_menu)
5031 pepper_delegate_.OnContextMenuClosed(custom_context);
5032 else
5033 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105034}
[email protected]5a7b15a2011-08-22 22:48:185035
[email protected]310ebd6302011-10-10 19:06:285036void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185037 if (!webview())
5038 return;
5039 WebFrame* main_frame = webview()->mainFrame();
5040 if (!main_frame)
5041 return;
5042 main_frame->enableViewSourceMode(true);
5043}
[email protected]67bfb83f2011-09-22 03:36:375044
[email protected]310ebd6302011-10-10 19:06:285045bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085046 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405047}
[email protected]7f3c7af2011-10-20 22:52:515048
[email protected]64d0e192011-12-09 14:44:205049void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:515050 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:185051#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:205052 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:185053#endif
[email protected]7f3c7af2011-10-20 22:52:515054}