blob: 3e9c41529aea10c2dc62c1a39f6ab1c28c7cd4e7 [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]b1cf3372011-04-20 21:28:1016#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4917#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2819#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
[email protected]7ddea9802012-02-22 23:08:0521#include "base/string_number_conversions.h"
[email protected]0a35efc2012-03-13 17:28:1322#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]16dd6e22012-03-01 19:08:2032#include "content/common/fileapi/file_system_dispatcher.h"
33#include "content/common/fileapi/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]5fa3a062012-03-21 15:39:3441#include "content/common/socket_stream_handle_data.h"
[email protected]778574e2011-03-21 22:03:5042#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2143#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0444#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4845#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2946#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5147#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2348#include "content/public/common/file_chooser_params.h"
[email protected]fb11b6a42012-03-14 07:25:1249#include "content/public/common/selected_file_info.h"
[email protected]a1d29162011-10-14 17:14:0350#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3451#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0752#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3253#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4454#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3655#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1956#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0257#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1558#include "content/renderer/dom_automation_controller.h"
[email protected]55722152011-03-22 01:33:5359#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1960#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4061#include "content/renderer/gpu/compositor_thread.h"
[email protected]1784b2f2011-11-24 10:53:4862#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0263#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4264#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0265#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0866#include "content/renderer/media/audio_message_filter.h"
[email protected]273558fb2012-01-12 15:03:5167#include "content/renderer/media/media_stream_dependency_factory.h"
68#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4069#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4870#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4071#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4872#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]4a19be92011-09-22 14:25:0273#include "content/renderer/mhtml_generator.h"
[email protected]217690d2012-01-27 07:33:1174#include "content/renderer/mouse_lock_dispatcher.h"
[email protected]230b7ef2011-03-16 22:30:1975#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3776#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3577#include "content/renderer/plugin_channel_host.h"
[email protected]0361b942012-03-14 06:42:5378#include "content/renderer/browser_plugin/browser_plugin_constants.h"
79#include "content/renderer/browser_plugin/browser_plugin_placeholder.h"
[email protected]8704f89b2011-04-15 00:30:0580#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4481#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4482#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3283#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0184#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:2085#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]663bd9e2011-03-21 01:07:0186#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]86a7d3c2011-09-12 16:45:3287#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1988#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:1389#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:0190#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3591#include "content/renderer/webplugin_delegate_proxy.h"
92#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4993#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4194#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:5095#include "media/base/message_loop_factory.h"
[email protected]37136d162012-04-09 23:39:1996#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:1897#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2998#include "net/base/escape.h"
99#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04100#include "net/http/http_util.h"
[email protected]8bd0fe62011-01-17 06:44:37101#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:37102#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:37103#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37104#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
105#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37106#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37111#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37112#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57113#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58114#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44115#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58116#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14117#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37118#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19119#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36121#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37122#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37125#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37126#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17129#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37130#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37131#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40132#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51133#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08134#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]50da23d02012-04-13 17:47:48140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
[email protected]273558fb2012-01-12 15:03:51142#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08144#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34147#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37148#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
152#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26154#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47155#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38156#include "ui/gfx/native_widget_types.h"
157#include "ui/gfx/point.h"
158#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55159#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04160#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]b928936b2012-04-13 01:16:16161#include "webkit/dom_storage/dom_storage_types.h"
[email protected]9c4bf232011-12-15 02:25:08162#include "webkit/forms/form_data.h"
163#include "webkit/forms/form_field.h"
164#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43165#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19166#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24167#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29168#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07169#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29170#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03171#include "webkit/glue/weburlloader_impl.h"
[email protected]b9fd01ba2012-02-28 01:50:40172#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51173#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16174#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50175#include "webkit/plugins/npapi/plugin_list.h"
176#include "webkit/plugins/npapi/webplugin_delegate.h"
177#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
178#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52179#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29180
[email protected]6c8afae52009-01-22 02:24:57181#if defined(OS_WIN)
182// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57183// * theming
[email protected]08397d52011-02-05 01:53:38184#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03185#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37186#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51187#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33188#elif defined(OS_MACOSX)
189#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57190#endif
191
[email protected]9892b472010-09-16 00:23:42192using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08193using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21194using WebKit::WebApplicationCacheHost;
195using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26196using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41197using WebKit::WebColor;
198using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59199using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44200using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51201using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55202using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28203using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00204using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58205using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25206using WebKit::WebDragOperation;
207using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51208using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51209using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08210using WebKit::WebExternalPopupMenu;
211using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47212using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22213using WebKit::WebFileSystem;
214using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49215using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59216using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48217using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45218using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51219using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17220using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13221using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41222using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50223using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15224using WebKit::WebIntentRequest;
225using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17226using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28227using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17228using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26229using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28230using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28231using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51232using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19233using WebKit::WebPageSerializer;
234using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48235using WebKit::WebPeerConnection00Handler;
236using WebKit::WebPeerConnection00HandlerClient;
237using WebKit::WebPeerConnectionHandler;
238using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17239using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36240using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40241using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49242using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09243using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52244using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59245using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51246using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52247using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15248using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40249using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35250using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29251using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17252using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59253using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42254using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02255using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34256using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34257using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40258using WebKit::WebStorageQuotaCallbacks;
259using WebKit::WebStorageQuotaError;
260using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28261using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51262using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52263using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24264using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28265using WebKit::WebURL;
266using WebKit::WebURLError;
267using WebKit::WebURLRequest;
268using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28269using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03270using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28271using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26272using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26273using appcache::WebApplicationCacheHostImpl;
274using base::Time;
275using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07276using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32277using content::NavigationState;
[email protected]380244092011-10-07 17:26:27278using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44279using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36280using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15281using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19282using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08283using webkit::forms::FormField;
284using webkit::forms::PasswordForm;
285using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26286using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23287using webkit_glue::ResourceFetcher;
[email protected]b9fd01ba2012-02-28 01:50:40288using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33289
initial.commit09911bf2008-07-26 23:55:29290//-----------------------------------------------------------------------------
291
[email protected]310ebd6302011-10-10 19:06:28292typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49293static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02294
[email protected]882daa92009-11-05 16:31:31295// Time, in seconds, we delay before sending content state changes (such as form
296// state and scroll position) to the browser. We delay sending changes to avoid
297// spamming the browser.
298// To avoid having tab/session restore require sending a message to get the
299// current content state during tab closing we use a shorter timeout for the
300// foreground renderer. This means there is a small window of time from which
301// content state is modified and not sent to session restore, but this is
302// better than having to wake up all renderers during shutdown.
303static const int kDelaySecondsForContentStateSyncHidden = 5;
304static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29305
[email protected]e99ef6f2011-10-16 01:13:00306static const size_t kExtraCharsBeforeAndAfterSelection = 100;
307
[email protected]0aa55312008-10-17 21:53:08308// The maximum number of popups that can be spawned from one page.
309static const int kMaximumNumberOfUnacknowledgedPopups = 25;
310
[email protected]c514d6372011-08-16 22:54:44311static const float kScalingIncrement = 0.1f;
312
[email protected]47578fa02011-11-02 19:34:41313static const float kScalingIncrementForGesture = 0.01f;
314
[email protected]726985e22009-06-18 21:09:28315static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
316 WebVector<WebURL> urls;
317 ds->redirectChain(urls);
318 result->reserve(urls.size());
319 for (size_t i = 0; i < urls.size(); ++i)
320 result->push_back(urls[i]);
321}
322
[email protected]007733c2011-11-17 00:34:07323// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44324// the AltErrorPageResourceFetcher is reset.
325static void StopAltErrorPageFetcher(WebDataSource* data_source) {
326 if (data_source) {
[email protected]007733c2011-11-17 00:34:07327 DocumentState* document_state = DocumentState::FromDataSource(data_source);
328 if (document_state)
329 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44330 }
331}
332
[email protected]007733c2011-11-17 00:34:07333static bool IsReload(const ViewMsg_Navigate_Params& params) {
334 return
335 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
336 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
337}
338
[email protected]b9fd01ba2012-02-28 01:50:40339static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]445e1042011-12-03 21:03:15340 const WebURLRequest& request) {
341 return request.extraData() ?
342 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
343 WebKit::WebReferrerPolicyDefault;
344}
345
[email protected]b9fd01ba2012-02-28 01:50:40346static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
347 const WebURLResponse& response) {
348 return static_cast<WebURLResponseExtraDataImpl*>(
349 response.extraData());
350}
351
[email protected]2149cc622012-02-14 01:12:12352NOINLINE static void CrashIntentionally() {
353 // NOTE(shess): Crash directly rather than using NOTREACHED() so
354 // that the signature is easier to triage in crash reports.
355 volatile int* zero = NULL;
356 *zero = 0;
357}
358
[email protected]8bf1048012012-02-08 01:22:18359static void MaybeHandleDebugURL(const GURL& url) {
360 if (!url.SchemeIs(chrome::kChromeUIScheme))
361 return;
362 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12363 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18364 } else if (url == GURL(chrome::kChromeUIKillURL)) {
365 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
366 } else if (url == GURL(chrome::kChromeUIHangURL)) {
367 for (;;) {
368 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
369 }
370 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
371 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
372 }
373}
374
initial.commit09911bf2008-07-26 23:55:29375///////////////////////////////////////////////////////////////////////////////
376
[email protected]310ebd6302011-10-10 19:06:28377struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23378 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47379 WebFileChooserCompletion* c)
380 : params(p),
381 completion(c) {
382 }
[email protected]8caadeb2011-11-22 02:45:23383 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47384 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
385};
386
[email protected]217690d2012-01-27 07:33:11387namespace {
388
389class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
390 public:
[email protected]82114f52012-03-20 22:53:41391 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11392 : webwidget_(webwidget) {}
393
394 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
395 if (succeeded)
396 webwidget_->didAcquirePointerLock();
397 else
398 webwidget_->didNotAcquirePointerLock();
399 }
400
401 virtual void OnMouseLockLost() OVERRIDE {
402 webwidget_->didLosePointerLock();
403 }
404
405 virtual bool HandleMouseLockedInputEvent(
406 const WebKit::WebMouseEvent &event) OVERRIDE {
407 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
408 return false;
409 }
410
411 private:
412 WebKit::WebWidget* webwidget_;
413};
414
[email protected]86cd9472012-02-03 19:51:05415int64 ExtractPostId(const WebHistoryItem& item) {
416 if (item.isNull())
417 return -1;
418
419 if (item.httpBody().isNull())
420 return -1;
421
422 return item.httpBody().identifier();
423}
424
[email protected]217690d2012-01-27 07:33:11425} // namespace
426
[email protected]daf82f82011-10-31 22:35:31427RenderViewImpl::RenderViewImpl(
428 gfx::NativeViewId parent_hwnd,
429 int32 opener_id,
430 const content::RendererPreferences& renderer_prefs,
431 const WebPreferences& webkit_prefs,
432 SharedRenderViewCounter* counter,
433 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56434 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31435 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46436 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41437 int32 next_page_id,
[email protected]8cca3da2012-03-20 08:26:34438 const WebKit::WebScreenInfo& screen_info,
[email protected]3e3c4522012-04-13 21:16:29439 bool guest,
440 AccessibilityMode accessibility_mode)
[email protected]6fd35b72012-03-01 19:46:41441 : RenderWidget(WebKit::WebPopupTypeNone, screen_info),
[email protected]676126f72011-01-15 00:03:51442 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02443 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09444 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02445 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24446 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21447 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02448 opened_by_user_gesture_(true),
449 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24450 page_id_(-1),
451 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46452 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00453 history_list_offset_(-1),
454 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02455 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55456 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31457 cached_is_main_frame_pinned_to_left_(false),
458 cached_is_main_frame_pinned_to_right_(false),
459 cached_has_main_frame_horizontal_scrollbar_(false),
460 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]05a980d7a2012-02-07 22:16:42461 context_has_swapbuffers_complete_callback_(false),
462 queried_for_swapbuffers_complete_callback_(false),
[email protected]d0fb8a72012-03-10 18:54:52463 context_is_web_graphics_context_3d_command_buffer_impl_(false),
[email protected]3354d3e2010-06-10 19:53:02464 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51465 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02466 input_tag_speech_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51467 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51468 media_stream_dispatcher_(NULL),
[email protected]1bc65a42012-04-23 09:31:25469 media_stream_impl_(NULL),
[email protected]cae8c8492011-03-03 11:12:18470 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41471 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32472 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11473 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08474 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18475 handling_select_range_(false),
476#if defined(OS_WIN)
477 focused_plugin_id_(-1),
478#endif
[email protected]8cca3da2012-03-20 08:26:34479 guest_(guest),
[email protected]3e3c4522012-04-13 21:16:29480 accessibility_mode_(accessibility_mode),
[email protected]ef5e98e2011-12-06 09:49:18481 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51482 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56483 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51484 if (opener_id != MSG_ROUTING_NONE)
485 opener_id_ = opener_id;
486
[email protected]74ce1ad2011-12-16 21:51:46487 // Ensure we start with a valid next_page_id_ from the browser.
488 DCHECK_GE(next_page_id_, 0);
489
[email protected]21b3a6ae2011-11-30 00:45:29490#if defined(ENABLE_NOTIFICATIONS)
491 notification_provider_ = new NotificationProvider(this);
492#else
493 notification_provider_ = NULL;
494#endif
495
[email protected]11fee2332011-03-29 20:36:35496 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11497 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35498
[email protected]676126f72011-01-15 00:03:51499 if (counter) {
500 shared_popup_counter_ = counter;
501 shared_popup_counter_->data++;
502 decrement_shared_popup_at_destruction_ = true;
503 } else {
504 shared_popup_counter_ = new SharedRenderViewCounter(0);
505 decrement_shared_popup_at_destruction_ = false;
506 }
507
[email protected]380244092011-10-07 17:26:27508 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51509 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47510 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51511 AddRef();
512
513 // If this is a popup, we must wait for the CreatingNew_ACK message before
514 // completing initialization. Otherwise, we can finish it now.
515 if (opener_id == MSG_ROUTING_NONE) {
516 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55517 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51518 }
519
[email protected]34c61bd52011-05-02 19:38:33520 g_view_map.Get().insert(std::make_pair(webview(), this));
521 webkit_preferences_.Apply(webview());
522 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35523 if (!frame_name.empty())
524 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33525 webview()->settings()->setMinimumTimerInterval(
526 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
527 webkit_glue::kForegroundTabTimerInterval);
528
529 OnSetRendererPrefs(renderer_prefs);
530
[email protected]676126f72011-01-15 00:03:51531 host_window_ = parent_hwnd;
532
[email protected]a026daa2011-04-20 15:49:51533#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51534 if (!p2p_socket_dispatcher_)
535 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51536#endif
[email protected]cae8c8492011-03-03 11:12:18537
[email protected]5b87e782012-02-09 18:19:32538#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02539 if (!media_stream_dispatcher_)
540 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32541#endif
[email protected]735873d2012-01-25 23:31:02542
[email protected]8f6a3b852011-07-19 16:48:56543 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32544#if defined(OS_MACOSX)
545 new TextInputClientObserver(this);
546#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56547
[email protected]217690d2012-01-27 07:33:11548 // The next group of objects all implement RenderViewObserver, so are deleted
549 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41550 devtools_agent_ = new DevToolsAgent(this);
[email protected]3e3c4522012-04-13 21:16:29551 renderer_accessibility_ = new RendererAccessibility(this, accessibility_mode);
[email protected]217690d2012-01-27 07:33:11552 mouse_lock_dispatcher_ = new MouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40553 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32554
[email protected]1784b2f2011-11-24 10:53:48555 new IdleUserDetector(this);
556
[email protected]766a7082012-02-03 23:39:15557 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
558 if (command_line.HasSwitch(switches::kDomAutomationController))
559 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
560
[email protected]5b52cd2f712012-03-28 02:12:48561 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05562
[email protected]e48869a2011-04-01 19:56:03563 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29564}
565
[email protected]310ebd6302011-10-10 19:06:28566RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03567 history_page_ids_.clear();
568
[email protected]0aa55312008-10-17 21:53:08569 if (decrement_shared_popup_at_destruction_)
570 shared_popup_counter_->data--;
571
[email protected]a1128322009-10-06 18:38:46572 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47573 while (!file_chooser_completions_.empty()) {
574 if (file_chooser_completions_.front()->completion) {
575 file_chooser_completions_.front()->completion->didChooseFile(
576 WebVector<WebString>());
577 }
578 file_chooser_completions_.pop_front();
579 }
[email protected]a1128322009-10-06 18:38:46580
[email protected]83dde542009-09-11 20:59:55581#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11582 // Destroy all fake plugin window handles on the browser side.
583 while (!fake_plugin_window_handles_.empty()) {
584 // Make sure no NULL plugin window handles were inserted into this list.
585 DCHECK(*fake_plugin_window_handles_.begin());
586 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
587 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
588 }
[email protected]83dde542009-09-11 20:59:55589#endif
[email protected]98324892009-09-09 21:16:05590
[email protected]60c42a8c72009-10-09 04:08:59591#ifndef NDEBUG
592 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49593 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59594 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
595 DCHECK_NE(this, it->second) << "Failed to call Close?";
596#endif
[email protected]676126f72011-01-15 00:03:51597
[email protected]310ebd6302011-10-10 19:06:28598 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51599 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59600}
601
602/*static*/
[email protected]310ebd6302011-10-10 19:06:28603RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31604 ViewMap* views = g_view_map.Pointer();
605 ViewMap::iterator it = views->find(webview);
606 return it == views->end() ? NULL : it->second;
607}
608
609/*static*/
610content::RenderView*
611 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28612 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31613}
614
615/*static*/
616void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49617 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59618 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
619 if (!visitor->Visit(it->second))
620 return;
621 }
622}
623
624/*static*/
[email protected]310ebd6302011-10-10 19:06:28625RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15626 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08627 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31628 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08629 const WebPreferences& webkit_prefs,
630 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34631 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56632 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26633 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46634 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41635 int32 next_page_id,
[email protected]8cca3da2012-03-20 08:26:34636 const WebKit::WebScreenInfo& screen_info,
[email protected]3e3c4522012-04-13 21:16:29637 bool guest,
638 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29639 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28640 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51641 parent_hwnd,
642 opener_id,
643 renderer_prefs,
644 webkit_prefs,
645 counter,
646 routing_id,
[email protected]9f4f3322012-01-18 22:29:56647 surface_id,
[email protected]676126f72011-01-15 00:03:51648 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46649 frame_name,
[email protected]6fd35b72012-03-01 19:46:41650 next_page_id,
[email protected]8cca3da2012-03-20 08:26:34651 screen_info,
[email protected]3e3c4522012-04-13 21:16:29652 guest,
653 accessibility_mode);
initial.commit09911bf2008-07-26 23:55:29654}
655
[email protected]50da23d02012-04-13 17:47:48656WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
657 WebPeerConnectionHandlerClient* client) {
[email protected]273558fb2012-01-12 15:03:51658 EnsureMediaStreamImpl();
[email protected]1bc65a42012-04-23 09:31:25659 if (!media_stream_impl_)
[email protected]5b87e782012-02-09 18:19:32660 return NULL;
[email protected]273558fb2012-01-12 15:03:51661 return media_stream_impl_->CreatePeerConnectionHandler(client);
662}
663
[email protected]50da23d02012-04-13 17:47:48664WebPeerConnection00Handler* RenderViewImpl::CreatePeerConnectionHandlerJsep(
665 WebPeerConnection00HandlerClient* client) {
666 EnsureMediaStreamImpl();
[email protected]1bc65a42012-04-23 09:31:25667 if (!media_stream_impl_)
[email protected]50da23d02012-04-13 17:47:48668 return NULL;
669 return media_stream_impl_->CreatePeerConnectionHandlerJsep(client);
670}
671
[email protected]310ebd6302011-10-10 19:06:28672void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51673 observers_.AddObserver(observer);
674}
675
[email protected]310ebd6302011-10-10 19:06:28676void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
677 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51678 observers_.RemoveObserver(observer);
679}
680
[email protected]310ebd6302011-10-10 19:06:28681WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26682 return static_cast<WebKit::WebView*>(webwidget());
683}
684
[email protected]310ebd6302011-10-10 19:06:28685void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40686 if (!enabled) {
687 load_progress_tracker_.reset(NULL);
688 return;
689 }
690 if (load_progress_tracker_ == NULL)
691 load_progress_tracker_.reset(new LoadProgressTracker(this));
692}
693
[email protected]310ebd6302011-10-10 19:06:28694void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51695 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29696}
697
[email protected]310ebd6302011-10-10 19:06:28698void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26699 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30700 // If the renderer is visible, set initial visibility and focus state.
701 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34702#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30703 delegate->SetContainerVisibility(true);
704 if (webview() && webview()->isActive())
705 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34706#endif
[email protected]49232292010-09-03 19:07:30707 }
[email protected]784ea1ab2010-09-18 00:02:34708 // Plugins start assuming the content has focus (so that they work in
709 // environments where RenderView isn't hosting them), so we always have to
710 // set the initial state. See webplugin_delegate_impl.h for details.
711 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26712}
713
[email protected]310ebd6302011-10-10 19:06:28714void RenderViewImpl::UnregisterPluginDelegate(
715 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26716 plugin_delegates_.erase(delegate);
717}
[email protected]d8fd6fa2010-02-01 15:54:26718
[email protected]310ebd6302011-10-10 19:06:28719bool RenderViewImpl::GetPluginInfo(const GURL& url,
720 const GURL& page_url,
721 const std::string& mime_type,
722 webkit::WebPluginInfo* plugin_info,
723 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08724 bool found = false;
725 Send(new ViewHostMsg_GetPluginInfo(
726 routing_id_, url, page_url, mime_type, &found, plugin_info,
727 actual_mime_type));
728 return found;
729}
730
[email protected]7a1ec28a2012-03-28 21:10:24731void RenderViewImpl::TransferActiveWheelFlingAnimation(
732 const WebKit::WebActiveWheelFlingParameters& params) {
733 if (webview())
734 webview()->transferActiveWheelFlingAnimation(params);
735}
736
[email protected]310ebd6302011-10-10 19:06:28737bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27738 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27739 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41740 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26741
[email protected]676126f72011-01-15 00:03:51742 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
743 RenderViewObserver* observer;
744 while ((observer = it.GetNext()) != NULL)
745 if (observer->OnMessageReceived(message))
746 return true;
[email protected]b2abac72009-02-26 12:39:28747
[email protected]a95986a82010-12-24 06:19:28748 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40749 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28750 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29751 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
752 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56753 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29754 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
755 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
756 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
757 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27758#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35759 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27760#endif
initial.commit09911bf2008-07-26 23:55:29761 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15762 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29763 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
764 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
765 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08766 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29767 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15768 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29769 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49770 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
771 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17772 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17773 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41774 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54775 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
776 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29777 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18778 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
779 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29780 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48781 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55782 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
783 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
784 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
785 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
786 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
787 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
788 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45789 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40790 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29791 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19792 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
793 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29794 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
795 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
796 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51797 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
798 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29799 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04800 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15801 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29802 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
803 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08804 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
805 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00806 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16807 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14808 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25809 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
810 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47811 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34812 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10813 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
814 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51815 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56816 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36817 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34818 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:12819 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
820 OnSetNavigationStartTime)
[email protected]6ce7abc52010-02-02 18:40:14821#if defined(OS_MACOSX)
822 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13823 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13824 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
825 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14826#endif
[email protected]446705872009-09-10 07:22:48827 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33828 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33829 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
830 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24831 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42832 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
833 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19834 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
835 OnGetAllSavableResourceLinksForCurrentPage)
836 IPC_MESSAGE_HANDLER(
837 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
838 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08839#if defined(OS_MACOSX)
840 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
841#endif
[email protected]521b2482011-01-15 00:10:10842 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51843 // TODO(viettrungluu): Move to a separate message filter.
[email protected]54ca3ca892011-06-07 21:14:54844#if defined(OS_MACOSX)
845 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
846#endif
[email protected]9e1ad4b2011-08-14 16:49:19847 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
848 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18849 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51850 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19851
initial.commit09911bf2008-07-26 23:55:29852 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28853 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29854 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40855
856 if (!msg_is_ok) {
857 // The message had a handler, but its deserialization failed.
858 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28859 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40860 }
861
[email protected]a95986a82010-12-24 06:19:28862 return handled;
initial.commit09911bf2008-07-26 23:55:29863}
864
[email protected]310ebd6302011-10-10 19:06:28865void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:18866 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:29867 if (!webview())
868 return;
869
[email protected]440a0e52011-09-13 17:38:58870 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
871
[email protected]007733c2011-11-17 00:34:07872 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03873
874 // If this is a stale back/forward (due to a recent navigation the browser
875 // didn't know about), ignore it.
876 if (IsBackForwardToStaleEntry(params, is_reload))
877 return;
878
[email protected]992db4c2011-05-12 15:37:15879 // Swap this renderer back in if necessary.
880 if (is_swapped_out_)
881 SetSwappedOut(false);
882
[email protected]3cc72b12010-03-18 23:03:00883 history_list_offset_ = params.current_history_list_offset;
884 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03885 if (history_list_length_ >= 0)
886 history_page_ids_.resize(history_list_length_, -1);
887 if (params.pending_history_list_offset >= 0 &&
888 params.pending_history_list_offset < history_list_length_)
889 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00890
[email protected]38b592902011-04-16 02:08:42891 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29892
[email protected]26aa0482009-09-30 16:55:27893 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45894 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29895 // We cannot reload if we do not have any history state. This happens, for
896 // example, when recovering from a crash. Our workaround here is a bit of
897 // a hack since it means that reload after a crashed tab does not cause an
898 // end-to-end cache validation.
899 is_reload = false;
900 }
901
[email protected]007733c2011-11-17 00:34:07902 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
903 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50904
[email protected]04d3c6e2009-05-22 17:00:13905 // If we are reloading, then WebKit will use the history state of the current
906 // page, so we should just ignore any given history state. Otherwise, if we
907 // have history state, then we need to navigate to it, which corresponds to a
908 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55909 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29910 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02911 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29912 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55913 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13914 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58915 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45916 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17917 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13918 } else {
919 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28920 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29921
[email protected]e6f546c32009-07-01 17:12:55922 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23923 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13924
[email protected]dd7daa82009-08-10 05:46:45925 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55926 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13927
[email protected]445e1042011-12-03 21:03:15928 if (params.referrer.url.is_valid()) {
929 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
930 params.referrer.policy,
931 params.url,
932 WebString::fromUTF8(params.referrer.url.spec()));
933 if (!referrer.isEmpty())
934 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28935 }
[email protected]04d3c6e2009-05-22 17:00:13936
[email protected]52c68652010-12-07 17:47:04937 if (!params.extra_headers.empty()) {
938 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
939 params.extra_headers.end(), "\n");
940 i.GetNext(); ) {
941 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
942 WebString::fromUTF8(i.values()));
943 }
944 }
[email protected]dd7daa82009-08-10 05:46:45945 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50946 }
947
[email protected]77f17a82009-05-21 04:42:54948 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07949 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29950}
951
[email protected]310ebd6302011-10-10 19:06:28952bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03953 const ViewMsg_Navigate_Params& params,
954 bool is_reload) {
955 // Make sure this isn't a back/forward to an entry we have already cropped
956 // or replaced from our history, before the browser knew about it. If so,
957 // a new navigation has committed in the mean time, and we can ignore this.
958 bool is_back_forward = !is_reload && !params.state.empty();
959
960 // Note: if the history_list_length_ is 0 for a back/forward, we must be
961 // restoring from a previous session. We'll update our state in OnNavigate.
962 if (!is_back_forward || history_list_length_ <= 0)
963 return false;
964
965 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
966
967 // Check for whether the forward history has been cropped due to a recent
968 // navigation the browser didn't know about.
969 if (params.pending_history_list_offset >= history_list_length_)
970 return true;
971
972 // Check for whether this entry has been replaced with a new one.
973 int expected_page_id =
974 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44975 if (expected_page_id > 0 && params.page_id != expected_page_id) {
976 if (params.page_id < expected_page_id)
977 return true;
978
979 // Otherwise we've removed an earlier entry and should have shifted all
980 // entries left. For now, it's ok to lazily update the list.
981 // TODO(creis): Notify all live renderers when we remove entries from
982 // the front of the list, so that we don't hit this case.
983 history_page_ids_[params.pending_history_list_offset] = params.page_id;
984 }
[email protected]d466b8a2011-07-15 21:48:03985
986 return false;
987}
988
initial.commit09911bf2008-07-26 23:55:29989// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28990void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44991 if (webview()) {
992 WebFrame* main_frame = webview()->mainFrame();
993 // Stop the alt error page fetcher. If we let it continue it may complete
994 // and cause RenderViewHostManager to swap to this RenderView, even though
995 // it may no longer be active.
996 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
997 StopAltErrorPageFetcher(main_frame->dataSource());
998 main_frame->stopLoading();
999 }
initial.commit09911bf2008-07-26 23:55:291000}
1001
[email protected]ecbf10d2010-02-18 13:03:291002// Reload current focused frame.
1003// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281004void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291005 if (webview() && webview()->focusedFrame()) {
1006 // We always obey the cache (ignore_cache=false) here.
1007 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1008 // a cache-ignoring reload of the frame.
1009 webview()->focusedFrame()->reload(false);
1010 }
[email protected]1dda4022010-01-28 18:24:561011}
1012
[email protected]310ebd6302011-10-10 19:06:281013void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271014 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291015}
1016
[email protected]310ebd6302011-10-10 19:06:281017void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251018 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271019 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251020 return;
1021
[email protected]26aa0482009-09-30 16:55:271022 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451023 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251024}
1025
[email protected]310ebd6302011-10-10 19:06:281026void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291027 // Check if there is a targeturl waiting to be sent.
1028 if (target_url_status_ == TARGET_PENDING) {
1029 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1030 pending_target_url_));
1031 }
1032
1033 target_url_status_ = TARGET_NONE;
1034}
1035
[email protected]310ebd6302011-10-10 19:06:281036void RenderViewImpl::OnUndo() {
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("Undo"));
initial.commit09911bf2008-07-26 23:55:291041}
1042
[email protected]310ebd6302011-10-10 19:06:281043void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291044 if (!webview())
1045 return;
1046
[email protected]26aa0482009-09-30 16:55:271047 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291048}
1049
[email protected]310ebd6302011-10-10 19:06:281050void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291051 if (!webview())
1052 return;
1053
[email protected]26aa0482009-09-30 16:55:271054 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291055}
1056
[email protected]310ebd6302011-10-10 19:06:281057void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291058 if (!webview())
1059 return;
1060
[email protected]f6b1856b2011-06-29 22:02:531061 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1062 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291063}
1064
[email protected]c0cc3092009-09-12 08:27:271065#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281066void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351067 if (!webview())
1068 return;
1069
1070 // Since the find pasteboard supports only plain text, this can be simpler
1071 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271072 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351073 if (frame->hasSelection()) {
1074 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271075 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171076 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351077 }
[email protected]a954bf72009-09-12 07:30:351078}
[email protected]c0cc3092009-09-12 08:27:271079#endif
[email protected]a954bf72009-09-12 07:30:351080
[email protected]310ebd6302011-10-10 19:06:281081void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291082 if (!webview())
1083 return;
1084
[email protected]26aa0482009-09-30 16:55:271085 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291086}
1087
[email protected]44bf7002011-10-16 02:46:151088void RenderViewImpl::OnPasteAndMatchStyle() {
1089 if (!webview())
1090 return;
1091
1092 webview()->focusedFrame()->executeCommand(
1093 WebString::fromUTF8("PasteAndMatchStyle"));
1094}
1095
[email protected]310ebd6302011-10-10 19:06:281096void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291097 if (!webview())
1098 return;
1099
[email protected]1ff7a032010-02-03 02:46:031100 WebFrame* frame = webview()->focusedFrame();
1101 if (!frame->hasSelection())
1102 frame->selectWordAroundCaret();
1103 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291104}
1105
[email protected]310ebd6302011-10-10 19:06:281106void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291107 if (!webview())
1108 return;
1109
[email protected]26aa0482009-09-30 16:55:271110 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291111}
1112
[email protected]310ebd6302011-10-10 19:06:281113void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291114 if (!webview())
1115 return;
1116
[email protected]26aa0482009-09-30 16:55:271117 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221118 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291119}
1120
[email protected]310ebd6302011-10-10 19:06:281121void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1122 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081123 if (!webview())
1124 return;
1125
1126 handling_select_range_ = true;
1127 webview()->focusedFrame()->selectRange(start, end);
1128 handling_select_range_ = false;
1129}
1130
[email protected]310ebd6302011-10-10 19:06:281131void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1132 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191133 DCHECK(history_length >= 0);
1134 DCHECK(history_list_offset_ == history_list_length_ - 1);
1135 DCHECK(minimum_page_id >= -1);
1136
1137 // Generate the new list.
1138 std::vector<int32> new_history_page_ids(history_length, -1);
1139 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1140 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1141 continue;
1142 new_history_page_ids.push_back(history_page_ids_[i]);
1143 }
1144 new_history_page_ids.swap(history_page_ids_);
1145
1146 // Update indexes.
1147 history_list_length_ = history_page_ids_.size();
1148 history_list_offset_ = history_list_length_ - 1;
1149}
1150
1151
[email protected]310ebd6302011-10-10 19:06:281152void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291153 if (!webview())
1154 return;
[email protected]26aa0482009-09-30 16:55:271155 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291156}
1157
[email protected]54ca3ca892011-06-07 21:14:541158#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281159void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331160 if (!webview())
1161 return;
1162 if (in_live_resize)
1163 webview()->willStartLiveResize();
1164 else
1165 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541166}
1167#endif
1168
[email protected]310ebd6302011-10-10 19:06:281169void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1170 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091171 WebKit::WebNode node = GetFocusedNode();
1172 if (!node.isNull()) {
1173 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191174 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511175 }
1176}
1177
initial.commit09911bf2008-07-26 23:55:291178///////////////////////////////////////////////////////////////////////////////
1179
1180// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281181void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451182 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291183 DCHECK(ds);
1184
[email protected]726985e22009-06-18 21:09:281185 const WebURLRequest& request = ds->request();
1186 const WebURLRequest& original_request = ds->originalRequest();
1187 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291188
[email protected]007733c2011-11-17 00:34:071189 DocumentState* document_state = DocumentState::FromDataSource(ds);
1190 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291191
1192 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281193 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291194 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051195 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291196 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071197 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191198 params.socket_address.set_host(response.remoteIPAddress().utf8());
1199 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031200 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091201 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071202 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291203 // SSL state specified in the request takes precedence over the one in the
1204 // response.
1205 // So far this is only intended for error pages that are not expected to be
1206 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281207 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071208 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291209 } else {
[email protected]726985e22009-06-18 21:09:281210 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291211 }
1212
1213 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311214 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291215
[email protected]5f9b8712011-11-23 08:55:571216 if (frame->document().baseURL() != params.url)
1217 params.base_url = frame->document().baseURL();
1218
[email protected]726985e22009-06-18 21:09:281219 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241220 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041221 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291222
[email protected]007733c2011-11-17 00:34:071223 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351224 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071225 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291226
1227 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071228 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291229 if (password_form_data)
1230 params.password_form = *password_form_data;
1231
1232 params.gesture = navigation_gesture_;
1233 navigation_gesture_ = NavigationGestureUnknown;
1234
[email protected]0f38dc4552011-02-25 11:24:001235 // Make navigation state a part of the FrameNavigate message so that commited
1236 // entry had it at all times.
1237 const WebHistoryItem& item = frame->currentHistoryItem();
1238 if (!item.isNull()) {
1239 params.content_state = webkit_glue::HistoryItemToString(item);
1240 } else {
1241 params.content_state =
1242 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1243 }
1244
[email protected]dd7daa82009-08-10 05:46:451245 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291246 // Top-level navigation.
1247
[email protected]b75b8292010-10-01 07:28:251248 // Set zoom level, but don't do it for full-page plugin since they don't use
1249 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011250 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541251 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251252 if (webview()->mainFrame()->document().isPluginDocument()) {
1253 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251254 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251255 } else {
1256 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251257 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251258 }
1259
[email protected]f85f0702010-01-30 09:31:011260 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511261 // This zoom level was merely recorded transiently for this load. We can
1262 // erase it now. If at some point we reload this page, the browser will
1263 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011264 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511265 }
1266
[email protected]b75b8292010-10-01 07:28:251267 // Reset the zoom limits in case a plugin had changed them previously. This
1268 // will also call us back which will cause us to send a message to
[email protected]770005b2012-04-16 15:58:131269 // update WebContentsImpl.
[email protected]b75b8292010-10-01 07:28:251270 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011271 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1272 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251273
initial.commit09911bf2008-07-26 23:55:291274 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551275 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291276
[email protected]daa8c58e2009-06-15 17:21:101277 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581278 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291279 // If the main frame does a load, it should not be reported as a subframe
1280 // navigation. This can occur in the following case:
1281 // 1. You're on a site with frames.
1282 // 2. You do a subframe navigation. This is stored with transition type
1283 // MANUAL_SUBFRAME.
1284 // 3. You navigate to some non-frame site, say, google.com.
1285 // 4. You navigate back to the page from step 2. Since it was initially
1286 // MANUAL_SUBFRAME, it will be that same transition type here.
1287 // We don't want that, because any navigation that changes the toplevel
1288 // frame should be tracked as a toplevel navigation (this allows us to
1289 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581290 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291291 }
1292
initial.commit09911bf2008-07-26 23:55:291293 // If we have a valid consumed client redirect source,
1294 // the page contained a client redirect (meta refresh, document.loc...),
1295 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151296 if (completed_client_redirect_src_.url.is_valid()) {
1297 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291298 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581299 params.transition = static_cast<content::PageTransition>(
1300 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291301 } else {
1302 // Bug 654101: the referrer will be empty on https->http transitions. It
1303 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151304 params.referrer = Referrer(GURL(
1305 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:401306 GetReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291307 }
1308
[email protected]726985e22009-06-18 21:09:281309 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051310 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291311 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051312 params.post_id = ExtractPostId(item);
1313 }
initial.commit09911bf2008-07-26 23:55:291314
[email protected]c2a797d2009-09-21 16:46:321315 // Save some histogram data so we can compute the average memory used per
1316 // page load of the glyphs.
1317 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1318 webkit_glue::GetGlyphPageCount());
1319
[email protected]15cf526b2010-02-12 06:33:491320 // This message needs to be sent before any of allowScripts(),
1321 // allowImages(), allowPlugins() is called for the new page, so that when
1322 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1323 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291324 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1325 } else {
1326 // Subframe navigation: the type depends on whether this navigation
1327 // generated a new session history entry. When they do generate a session
1328 // history entry, it means the user initiated the navigation and we should
1329 // mark it as such. This test checks if this is the first time UpdateURL
1330 // has been called since WillNavigateToURL was called to initiate the load.
1331 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581332 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291333 else
[email protected]2905f742011-10-13 03:51:581334 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291335
initial.commit09911bf2008-07-26 23:55:291336 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1337 }
1338
1339 last_page_id_sent_to_browser_ =
1340 std::max(last_page_id_sent_to_browser_, page_id_);
1341
1342 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101343 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581344 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291345}
1346
1347// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281348void RenderViewImpl::UpdateTitle(WebFrame* frame,
1349 const string16& title,
1350 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461351 // Ignore all but top level navigations.
1352 if (frame->parent())
1353 return;
1354
1355 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1356 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1357 title_direction));
initial.commit09911bf2008-07-26 23:55:291358}
1359
[email protected]310ebd6302011-10-10 19:06:281360void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1361 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291362 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271363 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291364 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301365 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291366 last_encoding_name_ = encoding_name;
1367
[email protected]e38f40152008-09-12 23:08:301368 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291369 }
1370}
1371
[email protected]e15f680732010-11-23 22:30:201372// Sends the last committed session history state to the browser so it will be
1373// saved before we navigate to a new page. This must be called *before* the
1374// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281375void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291376 // If we have a valid page ID at this point, then it corresponds to the page
1377 // we are navigating away from. Otherwise, this is the first navigation, so
1378 // there is no past session history to record.
1379 if (page_id_ == -1)
1380 return;
1381
[email protected]ca948a22009-06-25 19:36:171382 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271383 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051384 SendUpdateState(item);
1385}
1386
1387void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171388 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291389 return;
[email protected]ca948a22009-06-25 19:36:171390
[email protected]285f4bb82012-04-17 15:57:281391 // Don't send state updates for content::kSwappedOutURL.
1392 if (item.urlString() == WebString::fromUTF8(content::kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051393 return;
1394
[email protected]ca948a22009-06-25 19:36:171395 Send(new ViewHostMsg_UpdateState(
1396 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291397}
1398
[email protected]310ebd6302011-10-10 19:06:281399void RenderViewImpl::OpenURL(WebFrame* frame,
1400 const GURL& url,
[email protected]445e1042011-12-03 21:03:151401 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281402 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171403 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581404 routing_id_,
1405 url,
1406 referrer,
1407 NavigationPolicyToDisposition(policy),
1408 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171409}
1410
[email protected]79dbc662009-09-04 05:42:511411// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291412
[email protected]310ebd6302011-10-10 19:06:281413void RenderViewImpl::LoadNavigationErrorPage(
1414 WebFrame* frame,
1415 const WebURLRequest& failed_request,
1416 const WebURLError& error,
1417 const std::string& html,
1418 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581419 std::string alt_html;
1420 const std::string* error_html;
1421
1422 if (!html.empty()) {
1423 error_html = &html;
1424 } else {
1425 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1426 failed_request, error, &alt_html, NULL);
1427 error_html = &alt_html;
1428 }
1429
1430 frame->loadHTMLString(*error_html,
[email protected]285f4bb82012-04-17 15:57:281431 GURL(content::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251432 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551433 replace);
initial.commit09911bf2008-07-26 23:55:291434}
1435
[email protected]269f86d2011-12-07 02:43:471436bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281437 const string16& message,
1438 const string16& default_value,
1439 const GURL& frame_url,
1440 string16* result) {
initial.commit09911bf2008-07-26 23:55:291441 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411442 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291443 if (!result)
1444 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291445
[email protected]12636df2009-09-28 22:32:211446 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1447 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291448 return success;
1449}
1450
[email protected]310ebd6302011-10-10 19:06:281451bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571452 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1453 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1454 // it is particularly important that we do not call willEnterModalLoop as
1455 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441456 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1457 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571458
1459 message->EnableMessagePumping(); // Runs a nested message loop.
1460 return Send(message);
1461}
1462
[email protected]48c9cf2d2009-09-16 16:47:521463// WebKit::WebViewClient ------------------------------------------------------
1464
[email protected]916dfb62012-03-05 03:39:371465WebView* RenderViewImpl::createView(
1466 WebFrame* creator,
1467 const WebURLRequest& request,
1468 const WebWindowFeatures& features,
1469 const WebString& frame_name,
1470 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521471 // Check to make sure we aren't overloading on popups.
1472 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1473 return NULL;
1474
[email protected]8ab04652010-06-12 02:47:261475 ViewHostMsg_CreateWindow_Params params;
1476 params.opener_id = routing_id_;
1477 params.user_gesture = creator->isProcessingUserGesture();
1478 params.window_container_type = WindowFeaturesToContainerType(features);
1479 params.session_storage_namespace_id = session_storage_namespace_id_;
1480 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111481 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411482 params.opener_url = creator->document().url();
1483 params.opener_security_origin =
1484 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591485 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1486 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111487 if (!request.isNull())
1488 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261489
[email protected]48c9cf2d2009-09-16 16:47:521490 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561491 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341492 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521493
[email protected]380244092011-10-07 17:26:271494 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261495 new ViewHostMsg_CreateWindow(params,
1496 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561497 &surface_id,
[email protected]8ab04652010-06-12 02:47:261498 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211499 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521500 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521501
[email protected]8cca3da2012-03-20 08:26:341502 // TODO(fsamuel): The host renderer needs to be able to control whether
1503 // the guest renderer is allowed to do this or not. This current
1504 // behavior is not well defined.
[email protected]310ebd6302011-10-10 19:06:281505 RenderViewImpl* view = RenderViewImpl::Create(
1506 0,
1507 routing_id_,
1508 renderer_preferences_,
1509 webkit_preferences_,
1510 shared_popup_counter_,
1511 routing_id,
[email protected]9f4f3322012-01-18 22:29:561512 surface_id,
[email protected]310ebd6302011-10-10 19:06:281513 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461514 frame_name,
[email protected]6fd35b72012-03-01 19:46:411515 1,
[email protected]8cca3da2012-03-20 08:26:341516 screen_info_,
[email protected]3e3c4522012-04-13 21:16:291517 guest_,
1518 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261519 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521520
[email protected]007a848b2009-10-26 15:55:461521 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591522 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461523
[email protected]48c9cf2d2009-09-16 16:47:521524 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411525 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521526 if (!creator_url.is_valid() || !creator_url.IsStandard())
1527 creator_url = GURL();
1528 view->creator_url_ = creator_url;
1529
1530 // Copy over the alternate error page URL so we can have alt error pages in
1531 // the new render view (we don't need the browser to send the URL back down).
1532 view->alternate_error_page_url_ = alternate_error_page_url_;
1533
1534 return view->webview();
1535}
1536
[email protected]310ebd6302011-10-10 19:06:281537WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411538 RenderWidget* widget =
1539 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521540 return widget->webwidget();
1541}
1542
[email protected]310ebd6302011-10-10 19:06:281543WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441544 // TODO(jcivelli): Remove this deprecated method when its been removed from
1545 // the WebViewClient interface. It's been replaced by
1546 // createExternalPopupMenu.
1547 NOTREACHED();
1548 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521549}
1550
[email protected]310ebd6302011-10-10 19:06:281551WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081552 const WebPopupMenuInfo& popup_menu_info,
1553 WebExternalPopupMenuClient* popup_menu_client) {
1554 DCHECK(!external_popup_menu_.get());
1555 external_popup_menu_.reset(
1556 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1557 return external_popup_menu_.get();
1558}
1559
[email protected]310ebd6302011-10-10 19:06:281560RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521561 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531562 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421563 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411564 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531565 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271566 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391567 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561568 return widget;
[email protected]79c7bed2010-09-14 22:28:391569}
1570
[email protected]310ebd6302011-10-10 19:06:281571WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1572 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:161573 CHECK(session_storage_namespace_id_ !=
1574 dom_storage::kInvalidSessionStorageNamespaceId);
1575 return new RendererWebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341576}
1577
[email protected]7e8b4d12012-01-20 23:39:511578WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]40ec0c12012-03-08 12:34:401579 const WebGraphicsContext3D::Attributes& attributes) {
[email protected]7e8b4d12012-01-20 23:39:511580 if (!webview())
1581 return NULL;
1582 // The WebGraphicsContext3DInProcessImpl code path is used for
1583 // layout tests (though not through this code) as well as for
1584 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511585 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571586 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
[email protected]29dea0e2012-03-16 01:46:581587 attributes, true);
[email protected]7e8b4d12012-01-20 23:39:511588 } else {
[email protected]b3e83de2012-02-07 03:33:281589 GURL url;
1590 if (webview()->mainFrame())
1591 url = GURL(webview()->mainFrame()->document().url());
1592
[email protected]b3e83de2012-02-07 03:33:281593 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1594 new WebGraphicsContext3DCommandBufferImpl(
[email protected]8c9e0a02012-04-02 05:13:191595 surface_id(),
1596 url,
1597 RenderThreadImpl::current(),
1598 AsWeakPtr()));
[email protected]b3e83de2012-02-07 03:33:281599
[email protected]8c9e0a02012-04-02 05:13:191600 if (!context->Initialize(
1601 attributes,
1602 false /* bind generates resources */,
1603 content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
[email protected]56200f012012-02-03 23:13:571604 return NULL;
[email protected]d0fb8a72012-03-10 18:54:521605 context_is_web_graphics_context_3d_command_buffer_impl_ = true;
[email protected]56200f012012-02-03 23:13:571606 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511607 }
[email protected]7e8b4d12012-01-20 23:39:511608}
1609
[email protected]310ebd6302011-10-10 19:06:281610void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521611 const WebConsoleMessage& message, const WebString& source_name,
1612 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081613 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511614 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081615 case WebConsoleMessage::LevelTip:
1616 log_severity = logging::LOG_VERBOSE;
1617 break;
1618 case WebConsoleMessage::LevelLog:
1619 log_severity = logging::LOG_INFO;
1620 break;
1621 case WebConsoleMessage::LevelWarning:
1622 log_severity = logging::LOG_WARNING;
1623 break;
1624 case WebConsoleMessage::LevelError:
1625 log_severity = logging::LOG_ERROR;
1626 break;
1627 default:
1628 NOTREACHED();
1629 }
1630
[email protected]48c9cf2d2009-09-16 16:47:521631 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081632 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311633 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521634 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311635 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521636}
1637
[email protected]310ebd6302011-10-10 19:06:281638void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421639 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521640}
1641
[email protected]310ebd6302011-10-10 19:06:281642WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511643 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021644}
1645
[email protected]310ebd6302011-10-10 19:06:281646bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121647 const WebString& path,
1648 WebFileChooserCompletion* chooser_completion) {
1649 int id = enumeration_completion_id_++;
1650 enumeration_completions_[id] = chooser_completion;
1651 return Send(new ViewHostMsg_EnumerateDirectory(
1652 routing_id_,
1653 id,
1654 webkit_glue::WebStringToFilePath(path)));
1655}
1656
[email protected]310ebd6302011-10-10 19:06:281657void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521658 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141659 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521660 return;
1661 }
1662
1663 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521664
1665 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311666
1667 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521668}
1669
[email protected]310ebd6302011-10-10 19:06:281670void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521671 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141672 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521673 return;
1674 }
1675
1676 is_loading_ = false;
1677
1678 // NOTE: For now we're doing the safest thing, and sending out notification
1679 // when done loading. This currently isn't an issue as the favicon is only
1680 // displayed when done loading. Ideally we would send notification when
1681 // finished parsing the head, but webkit doesn't support that yet.
1682 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521683 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1684
[email protected]90109412010-12-15 17:14:241685 if (load_progress_tracker_ != NULL)
1686 load_progress_tracker_->DidStopLoading();
1687
[email protected]93b9d692011-04-13 00:44:311688 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521689}
1690
[email protected]310ebd6302011-10-10 19:06:281691void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1692 double load_progress) {
[email protected]90109412010-12-15 17:14:241693 if (load_progress_tracker_ != NULL)
1694 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1695}
1696
[email protected]310ebd6302011-10-10 19:06:281697bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061698#if defined(OS_MACOSX)
1699 return true;
1700#else
1701 return false;
1702#endif
1703}
1704
[email protected]310ebd6302011-10-10 19:06:281705bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031706#if defined(OS_WIN)
1707 return true;
1708#else
1709 return false;
1710#endif
1711}
1712
[email protected]310ebd6302011-10-10 19:06:281713void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081714 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031715 return;
[email protected]4fb60142011-08-09 02:22:081716 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011717
[email protected]fca52022012-04-03 17:00:501718 if (is_empty_selection)
1719 selection_text_.clear();
1720
[email protected]b781ff282011-08-20 06:19:361721 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031722}
1723
[email protected]310ebd6302011-10-10 19:06:281724void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121725 const std::string& name = UTF16ToUTF8(command_name);
1726 if (StartsWithASCII(name, "Move", true) ||
1727 StartsWithASCII(name, "Insert", true) ||
1728 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031729 return;
[email protected]f1a29a02011-10-06 23:08:441730 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031731}
1732
[email protected]310ebd6302011-10-10 19:06:281733bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101734 if (edit_commands_.empty())
1735 return false;
1736
[email protected]26aa0482009-09-30 16:55:271737 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101738 if (!frame)
1739 return false;
1740
1741 EditCommands::iterator it = edit_commands_.begin();
1742 EditCommands::iterator end = edit_commands_.end();
1743
[email protected]507b33ea2009-09-29 03:56:511744 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101745 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331746 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1747 // key (but it's the exception). Once one edit command is not executed, it
1748 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101749 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1750 WebString::fromUTF8(it->value)))
1751 break;
[email protected]507b33ea2009-09-29 03:56:511752 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101753 }
1754
[email protected]507b33ea2009-09-29 03:56:511755 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101756}
1757
[email protected]da8543762012-03-20 08:52:201758WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
1759 WebKit::WebColorChooserClient* client,
1760 const WebKit::WebColor& initial_color) {
1761 RendererWebColorChooserImpl* color_chooser =
1762 new RendererWebColorChooserImpl(this, client);
1763 color_chooser->Open(static_cast<SkColor>(initial_color));
1764 return color_chooser;
1765}
1766
[email protected]310ebd6302011-10-10 19:06:281767bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351768 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471769 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351770 // Do not open the file dialog in a hidden RenderView.
1771 if (is_hidden())
1772 return false;
[email protected]8caadeb2011-11-22 02:45:231773 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261774 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231775 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261776 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231777 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501778 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231779 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261780 else
[email protected]8caadeb2011-11-22 02:45:231781 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471782 ipc_params.title = params.title;
1783 ipc_params.default_file_name =
1784 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461785 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1786 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1787 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471788
1789 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461790}
1791
[email protected]269f86d2011-12-07 02:43:471792void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1793 const WebString& message) {
1794 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411795 message,
1796 string16(),
[email protected]b6cb3a842011-06-24 18:28:411797 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521798 NULL);
1799}
1800
[email protected]269f86d2011-12-07 02:43:471801bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1802 const WebString& message) {
1803 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411804 message,
1805 string16(),
[email protected]b6cb3a842011-06-24 18:28:411806 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521807 NULL);
1808}
1809
[email protected]269f86d2011-12-07 02:43:471810bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1811 const WebString& message,
1812 const WebString& default_value,
1813 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411814 string16 result;
[email protected]269f86d2011-12-07 02:43:471815 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411816 message,
1817 default_value,
[email protected]b6cb3a842011-06-24 18:28:411818 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521819 &result);
1820 if (ok)
[email protected]4f5ce842011-05-27 19:34:411821 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521822 return ok;
1823}
1824
[email protected]310ebd6302011-10-10 19:06:281825bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521826 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151827 // If we are swapping out, we have already run the beforeunload handler.
1828 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1829 // at all, to avoid running it twice.
1830 if (is_swapped_out_)
1831 return true;
1832
[email protected]3b3301f62012-02-29 04:32:321833 bool is_reload = false;
1834 WebDataSource* ds = frame->provisionalDataSource();
1835 if (ds)
1836 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
1837
[email protected]48c9cf2d2009-09-16 16:47:521838 bool success = false;
1839 // This is an ignored return value, but is included so we can accept the same
1840 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411841 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211842 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:321843 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:411844 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521845 return success;
1846}
1847
[email protected]310ebd6302011-10-10 19:06:281848void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441849 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:511850 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:371851
1852 // frame is NULL if invoked by BlockedPlugin.
1853 if (frame)
1854 params.frame_id = frame->identifier();
1855
[email protected]db803aae2011-03-05 02:00:421856 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271857 // it. We replace it with an empty GURL so the appropriate items are disabled
1858 // in the context menu.
1859 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1860 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421861 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271862 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101863 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291864 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441865}
1866
[email protected]310ebd6302011-10-10 19:06:281867void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521868}
1869
[email protected]310ebd6302011-10-10 19:06:281870void RenderViewImpl::UpdateTargetURL(const GURL& url,
1871 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581872 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521873 if (latest_url == target_url_)
1874 return;
[email protected]163f8242009-10-30 20:19:551875
[email protected]48c9cf2d2009-09-16 16:47:521876 // Tell the browser to display a destination link.
1877 if (target_url_status_ == TARGET_INFLIGHT ||
1878 target_url_status_ == TARGET_PENDING) {
1879 // If we have a request in-flight, save the URL to be sent when we
1880 // receive an ACK to the in-flight request. We can happily overwrite
1881 // any existing pending sends.
1882 pending_target_url_ = latest_url;
1883 target_url_status_ = TARGET_PENDING;
1884 } else {
[email protected]c85f0212011-11-04 16:54:411885 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1886 // see |ParamTraits<GURL>|.
1887 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1888 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521889 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1890 target_url_ = latest_url;
1891 target_url_status_ = TARGET_INFLIGHT;
1892 }
1893}
1894
[email protected]310ebd6302011-10-10 19:06:281895void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311896 int delay;
1897 if (send_content_state_immediately_)
1898 delay = 0;
1899 else if (is_hidden())
1900 delay = kDelaySecondsForContentStateSyncHidden;
1901 else
1902 delay = kDelaySecondsForContentStateSync;
1903
1904 if (nav_state_sync_timer_.IsRunning()) {
1905 // The timer is already running. If the delay of the timer maches the amount
1906 // we want to delay by, then return. Otherwise stop the timer so that it
1907 // gets started with the right delay.
1908 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1909 return;
1910 nav_state_sync_timer_.Stop();
1911 }
1912
[email protected]d323a172011-09-02 18:23:021913 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281914 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311915}
1916
[email protected]310ebd6302011-10-10 19:06:281917void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551918 mouse_over_url_ = GURL(url);
1919 UpdateTargetURL(mouse_over_url_, focus_url_);
1920}
1921
[email protected]310ebd6302011-10-10 19:06:281922void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551923 focus_url_ = GURL(url);
1924 UpdateTargetURL(focus_url_, mouse_over_url_);
1925}
1926
[email protected]310ebd6302011-10-10 19:06:281927void RenderViewImpl::startDragging(const WebDragData& data,
1928 WebDragOperationsMask mask,
1929 const WebImage& image,
1930 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411931#if WEBKIT_USING_SKIA
1932 SkBitmap bitmap(image.getSkBitmap());
1933#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331934 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411935#endif
1936
[email protected]59f4f2fa2011-03-23 01:00:551937 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521938 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411939 mask,
1940 bitmap,
1941 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521942}
1943
[email protected]310ebd6302011-10-10 19:06:281944bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451945 return renderer_preferences_.can_accept_load_drops;
1946}
1947
[email protected]310ebd6302011-10-10 19:06:281948void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521949 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1950}
1951
[email protected]310ebd6302011-10-10 19:06:281952void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521953 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1954}
1955
[email protected]310ebd6302011-10-10 19:06:281956void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511957 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071958
[email protected]38b592902011-04-16 02:08:421959 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491960}
1961
[email protected]169d4282011-11-30 19:33:591962void RenderViewImpl::didUpdateLayout() {
1963 // We don't always want to set up a timer, only if we've been put in that
1964 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1965 // message.
1966 if (!send_preferred_size_changes_ || !webview())
1967 return;
1968
1969 if (check_preferred_size_timer_.IsRunning())
1970 return;
1971 check_preferred_size_timer_.Start(FROM_HERE,
1972 TimeDelta::FromMilliseconds(0), this,
1973 &RenderViewImpl::CheckPreferredSize);
1974}
1975
[email protected]310ebd6302011-10-10 19:06:281976void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521977 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1978}
1979
[email protected]310ebd6302011-10-10 19:06:281980int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001981 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521982}
1983
[email protected]310ebd6302011-10-10 19:06:281984int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001985 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521986}
1987
[email protected]310ebd6302011-10-10 19:06:281988void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321989 const WebAccessibilityObject& obj,
1990 WebAccessibilityNotification notification) {
1991 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1992}
1993
[email protected]310ebd6302011-10-10 19:06:281994void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141995 const WebString& value) {
1996 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1997 key.utf8(),
1998 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261999}
2000
[email protected]79dbc662009-09-04 05:42:512001// WebKit::WebWidgetClient ----------------------------------------------------
2002
[email protected]310ebd6302011-10-10 19:06:282003void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122004 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2005 // we won't have to test for user gesture anymore and we can
2006 // move that code back to render_widget.cc
2007 if (webview() && webview()->mainFrame() &&
2008 webview()->mainFrame()->isProcessingUserGesture()) {
2009 Send(new ViewHostMsg_Focus(routing_id_));
2010 }
2011}
2012
[email protected]310ebd6302011-10-10 19:06:282013void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122014 // TODO(jcivelli): see TODO above in didFocus().
2015 if (webview() && webview()->mainFrame() &&
2016 webview()->mainFrame()->isProcessingUserGesture()) {
2017 Send(new ViewHostMsg_Blur(routing_id_));
2018 }
2019}
2020
initial.commit09911bf2008-07-26 23:55:292021// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282022// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292023// point to dispatch the ShowView message.
2024//
2025// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282026// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292027//
[email protected]310ebd6302011-10-10 19:06:282028void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292029 DCHECK(!did_show_) << "received extraneous Show call";
2030 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2031
2032 if (did_show_)
2033 return;
2034 did_show_ = true;
2035
[email protected]6779aa12011-03-29 17:32:242036 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042037 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042038
[email protected]28295ec2009-10-16 05:34:332039 // Force new windows to a popup if they were not opened with a user gesture.
2040 if (!opened_by_user_gesture_) {
2041 // We exempt background tabs for compat with older versions of Chrome.
2042 // TODO(darin): This seems bogus. These should have a user gesture, so
2043 // we probably don't need this check.
2044 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2045 policy = WebKit::WebNavigationPolicyNewPopup;
2046 }
2047
initial.commit09911bf2008-07-26 23:55:292048 // NOTE: initial_pos_ may still have its default values at this point, but
2049 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2050 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282051 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2052 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292053 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242054 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292055}
2056
[email protected]310ebd6302011-10-10 19:06:282057void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292058 DCHECK(did_show_) << "should already have shown the view";
2059
[email protected]c1f50aa2010-02-18 03:46:572060 // We must keep WebKit's shared timer running in this case in order to allow
2061 // showModalDialog to function properly.
2062 //
2063 // TODO(darin): WebKit should really be smarter about suppressing events and
2064 // timers so that we do not need to manage the shared timer in such a heavy
2065 // handed manner.
2066 //
[email protected]f1a29a02011-10-06 23:08:442067 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2068 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572069
[email protected]12636df2009-09-28 22:32:212070 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292071}
2072
[email protected]2b624c562011-10-27 22:58:262073bool RenderViewImpl::enterFullScreen() {
2074 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2075 return true;
2076}
2077
2078void RenderViewImpl::exitFullScreen() {
2079 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2080}
2081
[email protected]217690d2012-01-27 07:33:112082bool RenderViewImpl::requestPointerLock() {
2083 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2084}
2085
2086void RenderViewImpl::requestPointerUnlock() {
2087 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2088}
2089
2090bool RenderViewImpl::isPointerLocked() {
2091 return mouse_lock_dispatcher_->IsMouseLockedTo(
2092 webwidget_mouse_lock_target_.get());
2093}
2094
[email protected]7a1ec28a2012-03-28 21:10:242095void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2096 CompositorThread* compositor_thread =
2097 RenderThreadImpl::current()->compositor_thread();
2098 if (compositor_thread)
2099 compositor_thread->AddInputHandler(
2100 routing_id_, input_handler_identifier, AsWeakPtr());
2101
2102 RenderWidget::didActivateCompositor(input_handler_identifier);
2103}
2104
[email protected]3d9689372009-09-10 04:29:172105// WebKit::WebFrameClient -----------------------------------------------------
2106
[email protected]310ebd6302011-10-10 19:06:282107WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2108 const WebPluginParams& params) {
[email protected]0361b942012-03-14 06:42:532109 // The browser plugin is a special kind of pepper plugin
2110 // that loads asynchronously. We first create a placeholder here.
2111 // When a guest is ready to be displayed, we swap out the placeholder
2112 // with the guest.
2113 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2114 if (command_line.HasSwitch(switches::kEnableBrowserPlugin) &&
2115 UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType)
2116 return BrowserPluginPlaceholder::Create(this, frame, params);
2117
[email protected]eaacd1f2011-09-23 02:32:552118 WebPlugin* plugin = NULL;
2119 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2120 this, frame, params, &plugin)) {
2121 return plugin;
2122 }
2123
[email protected]a813c8e2011-10-08 01:34:112124 webkit::WebPluginInfo info;
2125 std::string mime_type;
2126 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2127 params.mimeType.utf8(), &info, &mime_type);
2128 if (!found)
2129 return NULL;
2130
2131 WebPluginParams params_to_use = params;
2132 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312133 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172134}
2135
[email protected]310ebd6302011-10-10 19:06:282136WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422137 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372138 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422139
[email protected]30447b62009-11-13 01:13:372140 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512141 bool exists = false;
[email protected]30447b62009-11-13 01:13:372142 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512143 ViewHostMsg_CreateWorker_Params params;
2144 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512145 params.name = name;
2146 params.document_id = document_id;
2147 params.render_view_route_id = routing_id_;
2148 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232149 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372150 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512151 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372152 if (url_mismatch) {
2153 return NULL;
2154 } else {
[email protected]f1a29a02011-10-06 23:08:442155 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492156 document_id,
[email protected]6de0bcf2010-02-17 22:00:512157 exists,
[email protected]30447b62009-11-13 01:13:372158 route_id,
2159 routing_id_);
2160 }
[email protected]9c00f002009-11-05 22:37:422161}
2162
[email protected]310ebd6302011-10-10 19:06:282163WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172164 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442165 FOR_EACH_OBSERVER(
2166 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172167
[email protected]bb6fd402011-12-09 02:45:442168 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502169 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442170 media::FilterCollection* collection = new media::FilterCollection();
2171 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372172
[email protected]9e2269d2012-01-07 00:06:212173 RenderAudioSourceProvider* audio_source_provider = NULL;
2174
[email protected]3d9689372009-09-10 04:29:172175 // Add in any custom filter factories first.
2176 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2177 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212178 // audio_source_provider is a "provider" to WebKit, and a sink
2179 // from the perspective of the audio renderer.
2180 audio_source_provider = new RenderAudioSourceProvider();
2181
2182 // Add the chrome specific audio renderer, using audio_source_provider
2183 // as the sink.
[email protected]37136d162012-04-09 23:39:192184 media::AudioRendererImpl* audio_renderer =
2185 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212186 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172187 }
2188
[email protected]e1d69d762011-12-13 05:12:182189 // Currently only cros/arm has any HW video decode support in
2190 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2191 // platforms. This is a startup-time optimization. When new VDA
2192 // implementations are added, relax the #if above.
[email protected]d0fb8a72012-03-10 18:54:522193#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
2194 // Note we don't actually use the result of this blind down-cast unless it's
2195 // valid (not NULL and of the right type).
[email protected]43567302012-02-16 23:21:392196 WebGraphicsContext3DCommandBufferImpl* context3d =
2197 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2198 webview()->graphicsContext3D());
[email protected]d0fb8a72012-03-10 18:54:522199 if (context_is_web_graphics_context_3d_command_buffer_impl_ && context3d) {
[email protected]84a83e192012-03-09 18:43:402200 MessageLoop* factories_loop =
2201 RenderThreadImpl::current()->compositor_thread() ?
2202 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
2203 ->message_loop() :
2204 MessageLoop::current();
[email protected]e1d69d762011-12-13 05:12:182205 GpuChannelHost* gpu_channel_host =
2206 RenderThreadImpl::current()->EstablishGpuChannelSync(
2207 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2208 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312209 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
[email protected]84a83e192012-03-09 18:43:402210 factories_loop,
[email protected]8d4359282012-01-14 00:53:312211 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402212 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182213 }
2214#endif
2215
[email protected]da952fd2012-01-13 03:49:252216 webkit_media::WebMediaPlayerImpl* media_player =
2217 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2218 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1bc65a42012-04-23 09:31:252219 message_loop_factory, media_stream_impl_, render_media_log);
[email protected]c4dabe452012-02-08 23:58:122220#if defined(OS_ANDROID)
2221 // TODO(qinmin): Implement for android.
2222 // http://crbug.com/113218
2223#else
[email protected]da952fd2012-01-13 03:49:252224 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562225 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252226 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1bc65a42012-04-23 09:31:252227 message_loop_factory, media_stream_impl_, render_media_log);
[email protected]bb6fd402011-12-09 02:45:442228 }
[email protected]c4dabe452012-02-08 23:58:122229#endif
[email protected]cec4eb82012-01-12 17:51:562230 return media_player;
[email protected]3d9689372009-09-10 04:29:172231}
2232
[email protected]310ebd6302011-10-10 19:06:282233WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212234 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232235 if (!frame || !frame->view())
2236 return NULL;
[email protected]035545f2010-04-09 13:10:212237 return new RendererWebApplicationCacheHostImpl(
2238 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442239 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212240}
2241
[email protected]310ebd6302011-10-10 19:06:282242WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382243 return &cookie_jar_;
2244}
2245
[email protected]310ebd6302011-10-10 19:06:282246void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512247 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452248}
2249
[email protected]310ebd6302011-10-10 19:06:282250void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512251 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172252}
2253
[email protected]310ebd6302011-10-10 19:06:282254void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172255 WebFrame* frame, const WebURLRequest& request,
2256 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342257 loadURLExternally(frame, request, policy, WebString());
2258}
2259
[email protected]310ebd6302011-10-10 19:06:282260void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342261 WebFrame* frame, const WebURLRequest& request,
2262 WebNavigationPolicy policy,
2263 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592264 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2265 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342266 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2267 suggested_name));
[email protected]efce17b2009-09-11 18:04:592268 } else {
[email protected]445e1042011-12-03 21:03:152269 OpenURL(frame, request.url(),
[email protected]b9fd01ba2012-02-28 01:50:402270 Referrer(referrer, GetReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592271 }
[email protected]3d9689372009-09-10 04:29:172272}
2273
[email protected]310ebd6302011-10-10 19:06:282274WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172275 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222276 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332277 Referrer referrer(
2278 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2279 GetReferrerPolicyFromRequest(request));
2280
[email protected]992db4c2011-05-12 15:37:152281 if (is_swapped_out_) {
[email protected]285f4bb82012-04-17 15:57:282282 if (request.url() != GURL(content::kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332283 // Targeted links may try to navigate a swapped out frame. Allow the
2284 // browser process to navigate the tab instead. Note that it is also
2285 // possible for non-targeted navigations (from this view) to arrive
2286 // here just after we are swapped out. It's ok to send them to the
2287 // browser, as long as they're for the top level frame.
2288 // TODO(creis): Ensure this supports targeted form submissions when
2289 // fixing http://crbug.com/101395.
2290 if (frame->parent() == NULL) {
2291 OpenURL(frame, request.url(), referrer, default_policy);
2292 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2293 }
2294
2295 // We should otherwise ignore in-process iframe navigations, if they
2296 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552297 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332298 }
[email protected]73eb2602012-02-09 19:50:552299
[email protected]285f4bb82012-04-17 15:57:282300 // Allow content::kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152301 return default_policy;
2302 }
2303
[email protected]3d9689372009-09-10 04:29:172304 // Webkit is asking whether to navigate to a new URL.
2305 // This is fine normally, except if we're showing UI from one security
2306 // context and they're trying to navigate to a different context.
2307 const GURL& url = request.url();
2308
[email protected]d19ea342011-04-20 20:31:132309 // A content initiated navigation may have originated from a link-click,
2310 // script, drag-n-drop operation, etc.
2311 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072312 DocumentState::FromDataSource(frame->provisionalDataSource())->
2313 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132314
[email protected]a8c269a2011-10-25 20:17:222315 // Experimental:
2316 // If --enable-strict-site-isolation is enabled, send all top-level
2317 // navigations to the browser to let it swap processes when crossing site
2318 // boundaries. This is currently expected to break some script calls and
2319 // navigations, such as form submissions.
2320 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102321 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2322 !frame->parent() && (is_content_initiated || is_redirect)) {
2323 WebString origin_str = frame->document().securityOrigin().toString();
2324 GURL frame_url(origin_str.utf8().data());
2325 // TODO(cevans): revisit whether this origin check is still necessary once
2326 // crbug.com/101395 is fixed.
2327 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]313b80bd2011-11-23 03:49:102328 OpenURL(frame, url, referrer, default_policy);
2329 return WebKit::WebNavigationPolicyIgnore;
2330 }
[email protected]a8c269a2011-10-25 20:17:222331 }
2332
[email protected]3d9689372009-09-10 04:29:172333 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302334 // navigations.
[email protected]5f000f272012-01-19 05:25:082335 if (is_content_initiated) {
2336 bool browser_handles_top_level_requests =
2337 renderer_preferences_.browser_handles_top_level_requests &&
2338 IsNonLocalTopLevelNavigation(url, frame, type);
2339 if (browser_handles_top_level_requests ||
2340 renderer_preferences_.browser_handles_all_requests) {
[email protected]5f000f272012-01-19 05:25:082341 // Reset these counters as the RenderView could be reused for the next
2342 // navigation.
2343 page_id_ = -1;
2344 last_page_id_sent_to_browser_ = -1;
2345 OpenURL(frame, url, referrer, default_policy);
2346 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2347 }
[email protected]3d9689372009-09-10 04:29:172348 }
2349
[email protected]6101c342010-12-16 22:44:372350 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552351 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042352 // top-level navigations (not iframes). But we sometimes navigate to
2353 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372354 //
[email protected]744c2a22012-03-15 18:42:042355 // Note: this is known to break POST submissions when crossing process
2356 // boundaries until http://crbug.com/101395 is fixed. This is better for
2357 // security than loading a WebUI, extension or app page in the wrong process.
2358 // POST requests don't work because this mechanism does not preserve form
2359 // POST data. We will need to send the request's httpBody data up to the
2360 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572361 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2362 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222363 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042364 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372365 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042366
2367 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2368 // must be handled by the browser process so that the correct bindings and
2369 // data sources can be registered.
2370 // Similarly, navigations to view-source URLs or within ViewSource mode
2371 // must be handled by the browser process.
2372 int cumulative_bindings =
2373 RenderProcess::current()->GetEnabledBindings();
[email protected]6101c342010-12-16 22:44:372374 bool should_fork =
[email protected]744c2a22012-03-15 18:42:042375 content::GetContentClient()->HasWebUIScheme(url) ||
2376 (cumulative_bindings & content::BINDINGS_POLICY_WEB_UI) ||
2377 url.SchemeIs(chrome::kViewSourceScheme) ||
2378 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112379
[email protected]e48869a2011-04-01 19:56:032380 if (!should_fork) {
2381 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042382 // For now, we skip this for POST submissions. This is because
2383 // http://crbug.com/101395 is more likely to cause compatibility issues
2384 // with hosted apps and extensions than WebUI pages. We will remove this
2385 // check when cross-process POST submissions are supported.
2386 if (request.httpMethod() == "GET") {
2387 bool is_initial_navigation = page_id_ == -1;
2388 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2389 frame, url, is_initial_navigation, &send_referrer);
2390 }
[email protected]6101c342010-12-16 22:44:372391 }
2392
2393 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152394 OpenURL(
2395 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112396 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2397 }
[email protected]3d9689372009-09-10 04:29:172398 }
2399
[email protected]43763f982011-08-26 18:33:402400 // Use the frame's original request's URL rather than the document's URL for
2401 // this check. For a popup, the document's URL may become the opener window's
2402 // URL if the opener has called document.write. See http://crbug.com/93517.
2403 GURL old_url(frame->dataSource()->request().url());
2404
[email protected]3d9689372009-09-10 04:29:172405 // Detect when a page is "forking" a new tab that can be safely rendered in
2406 // its own process. This is done by sites like Gmail that try to open links
2407 // in new windows without script connections back to the original page. We
2408 // treat such cases as browser navigations (in which we will create a new
2409 // renderer for a cross-site navigation), rather than WebKit navigations.
2410 //
2411 // We use the following heuristic to decide whether to fork a new page in its
2412 // own process:
2413 // The parent page must open a new tab to about:blank, set the new tab's
2414 // window.opener to null, and then redirect the tab to a cross-site URL using
2415 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462416 //
2417 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2418 // (see below).
[email protected]3d9689372009-09-10 04:29:172419 bool is_fork =
2420 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582421 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172422 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522423 historyBackListCount() < 1 &&
2424 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172425 // The parent page must have set the child's window.opener to null before
2426 // redirecting to the desired URL.
2427 frame->opener() == NULL &&
2428 // Must be a top-level frame.
2429 frame->parent() == NULL &&
2430 // Must not have issued the request from this page.
2431 is_content_initiated &&
2432 // Must be targeted at the current tab.
2433 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2434 // Must be a JavaScript navigation, which appears as "other".
2435 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462436
[email protected]f92ce2b2012-03-06 18:02:592437 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172438 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152439 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172440 return WebKit::WebNavigationPolicyIgnore;
2441 }
2442
2443 return default_policy;
2444}
2445
[email protected]310ebd6302011-10-10 19:06:282446bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492447 WebFrame* frame, const WebURLRequest& request) {
2448 // We allow WebKit to think that everything can be handled even though
2449 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342450 return true;
2451}
2452
[email protected]310ebd6302011-10-10 19:06:282453WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492454 WebFrame* frame, const WebURLRequest& request) {
2455 NOTREACHED(); // Since we said we can handle all requests.
2456 return WebURLError();
2457}
2458
[email protected]310ebd6302011-10-10 19:06:282459WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492460 WebFrame* frame, const WebURLRequest& request) {
2461 WebURLError error;
2462 error.domain = WebString::fromUTF8(net::kErrorDomain);
2463 error.reason = net::ERR_ABORTED;
2464 error.unreachableURL = request.url();
2465 return error;
[email protected]7b7a7dc2009-10-19 02:23:342466}
2467
[email protected]310ebd6302011-10-10 19:06:282468void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492469 WebFrame*, const WebURLError&) {
2470 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342471}
2472
[email protected]310ebd6302011-10-10 19:06:282473void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432474 const WebKit::WebFormElement& form) {
2475 // Some login forms have onSubmit handlers that put a hash of the password
2476 // into a hidden field and then clear the password. (Issue 28910.)
2477 // This method gets called before any of those handlers run, so save away
2478 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072479 DocumentState* document_state =
2480 DocumentState::FromDataSource(frame->dataSource());
2481 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432482 PasswordFormDomManager::CreatePasswordForm(form));
2483}
2484
[email protected]310ebd6302011-10-10 19:06:282485void RenderViewImpl::willSubmitForm(WebFrame* frame,
2486 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072487 DocumentState* document_state =
2488 DocumentState::FromDataSource(frame->provisionalDataSource());
2489 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172490
[email protected]2905f742011-10-13 03:51:582491 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2492 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172493
2494 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352495 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072496 document_state->set_searchable_form_url(web_searchable_form_data.url());
2497 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212498 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432499 PasswordForm* password_form_data =
2500 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072501 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432502
[email protected]098c95cb2011-04-28 16:49:012503 // In order to save the password that the user actually typed and not one
2504 // that may have gotten transformed by the site prior to submit, recover it
2505 // from the form contents already stored by |willSendSubmitEvent| into the
2506 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2507 // which is what we're storing into now.)
2508 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072509 DocumentState* old_document_state =
2510 DocumentState::FromDataSource(frame->dataSource());
2511 if (old_document_state) {
2512 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432513 if (old_form_data && old_form_data->action == password_form_data->action)
2514 password_form_data->password_value = old_form_data->password_value;
2515 }
2516 }
[email protected]3d9689372009-09-10 04:29:172517
[email protected]2a5b1732011-04-01 23:55:552518 FOR_EACH_OBSERVER(
2519 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172520}
2521
[email protected]310ebd6302011-10-10 19:06:282522void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172523 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2524 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382525 FOR_EACH_OBSERVER(
2526 RenderViewObserver, observers_,
2527 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172528}
2529
[email protected]310ebd6302011-10-10 19:06:282530void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382531 FOR_EACH_OBSERVER(
2532 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172533}
2534
[email protected]310ebd6302011-10-10 19:06:282535void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172536 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152537 if (!frame->parent()) {
2538 WebDataSource* ds = frame->provisionalDataSource();
2539 // If there's no provisional data source, it's a reference fragment
2540 // navigation.
2541 completed_client_redirect_src_ = Referrer(
[email protected]b9fd01ba2012-02-28 01:50:402542 from, ds ? GetReferrerPolicyFromRequest(ds->request()) :
[email protected]445e1042011-12-03 21:03:152543 frame->referrerPolicy());
2544 }
[email protected]eb0bff942011-04-07 22:08:382545 FOR_EACH_OBSERVER(
2546 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172547}
2548
[email protected]310ebd6302011-10-10 19:06:282549void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572550 bool content_initiated = !pending_navigation_params_.get();
2551
[email protected]007733c2011-11-17 00:34:072552 DocumentState* document_state = DocumentState::FromDataSource(ds);
2553 if (!document_state) {
2554 document_state = new DocumentState;
2555 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572556 if (!content_initiated)
2557 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072558 }
2559
[email protected]3d9689372009-09-10 04:29:172560 // The rest of RenderView assumes that a WebDataSource will always have a
2561 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072562 if (content_initiated)
2563 document_state->set_navigation_state(
2564 NavigationState::CreateContentInitiated());
[email protected]45d83a12012-04-06 22:57:572565 else {
2566 document_state->set_navigation_state(CreateNavigationStateFromPending());
2567 pending_navigation_params_.reset();
2568 }
[email protected]8a3125a712010-08-09 18:58:512569
[email protected]007733c2011-11-17 00:34:072570 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512571 // navigating from a page that used prefetching using a link on that
2572 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072573 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512574 // this value appropriately.
2575 // TODO(gavinp): catch the important case of navigation in a new
2576 // renderer process.
2577 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302578 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522579 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512580 const GURL referrer(
2581 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2582 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072583 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512584 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:412585 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:512586 WebDataSource* old_frame_ds = old_frame->dataSource();
2587 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072588 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512589 break;
2590 }
2591 }
2592 }
2593 }
2594 }
2595
[email protected]4c1b6f0b2010-02-07 16:38:182596 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522597 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512598 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182599 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072600 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182601 break;
2602 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072603 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182604 break;
2605 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072606 document_state->set_load_type(
2607 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182608 break;
2609 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072610 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182611 break;
2612 }
2613 }
[email protected]fa7b6b542009-11-03 05:02:302614
[email protected]946a0032011-03-31 18:42:282615 FOR_EACH_OBSERVER(
2616 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172617}
2618
[email protected]45d83a12012-04-06 22:57:572619void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:072620 DocumentState* document_state) {
2621 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:572622 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:072623
[email protected]45d83a12012-04-06 22:57:572624 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
2625 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2626 // We're doing a load of a page that was restored from the last session. By
2627 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
2628 // can result in stale data for pages that are set to expire. We explicitly
2629 // override that by setting the policy here so that as necessary we load
2630 // from the network.
2631 document_state->set_cache_policy_override(
2632 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:072633 }
2634
2635 if (IsReload(params))
2636 document_state->set_load_type(DocumentState::RELOAD);
2637 else if (!params.state.empty())
2638 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2639 else
2640 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]45d83a12012-04-06 22:57:572641}
[email protected]007733c2011-11-17 00:34:072642
[email protected]45d83a12012-04-06 22:57:572643NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
2644 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2645 NavigationState* navigation_state = NULL;
2646
2647 // A navigation resulting from loading a javascript URL should not be treated
2648 // as a browser initiated event. Instead, we want it to look as if the page
2649 // initiated any load resulting from JS execution.
2650 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2651 navigation_state = NavigationState::CreateBrowserInitiated(
2652 params.page_id,
2653 params.pending_history_list_offset,
2654 params.transition);
2655 navigation_state->set_transferred_request_child_id(
2656 params.transferred_request_child_id);
2657 navigation_state->set_transferred_request_request_id(
2658 params.transferred_request_request_id);
2659 } else {
2660 navigation_state = NavigationState::CreateContentInitiated();
2661 }
2662 return navigation_state;
[email protected]007733c2011-11-17 00:34:072663}
2664
[email protected]5b52cd2f712012-03-28 02:12:482665void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
2666 bool enable_viewport =
2667 command_line.HasSwitch(switches::kEnableViewport);
2668 bool enable_fixed_layout =
2669 command_line.HasSwitch(switches::kEnableFixedLayout);
2670
2671 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
2672 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
2673
2674 if (enable_viewport) {
2675 webview()->settings()->setViewportEnabled(true);
2676 } else if (enable_fixed_layout) {
2677 std::string str =
2678 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
2679 std::vector<std::string> tokens;
2680 base::SplitString(str, ',', &tokens);
2681 if (tokens.size() == 2) {
2682 int width, height;
2683 if (base::StringToInt(tokens[0], &width) &&
2684 base::StringToInt(tokens[1], &height))
2685 webview()->setFixedLayoutSize(WebSize(width,height));
2686 }
2687 }
2688}
2689
[email protected]310ebd6302011-10-10 19:06:282690void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172691 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072692 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172693
[email protected]3d9689372009-09-10 04:29:172694 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072695 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172696 double event_time = ds->triggeringEventTime();
2697 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072698 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172699 }
2700
[email protected]05c8e502010-08-15 15:13:522701 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072702 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522703
[email protected]3d9689372009-09-10 04:29:172704 bool is_top_most = !frame->parent();
2705 if (is_top_most) {
2706 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132707 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172708
2709 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152710 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172711 } else if (frame->parent()->isLoading()) {
2712 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002713 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072714 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582715 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172716 }
2717
[email protected]28685da92011-02-07 21:49:172718 FOR_EACH_OBSERVER(
2719 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2720
[email protected]3d9689372009-09-10 04:29:172721 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592722 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262723 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172724}
2725
[email protected]310ebd6302011-10-10 19:06:282726void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2727 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172728 if (frame->parent())
2729 return;
2730 // Received a redirect on the main frame.
2731 WebDataSource* data_source = frame->provisionalDataSource();
2732 if (!data_source) {
2733 // Should only be invoked when we have a data source.
2734 NOTREACHED();
2735 return;
2736 }
2737 std::vector<GURL> redirects;
2738 GetRedirectChain(data_source, &redirects);
2739 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512740 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592741 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172742 }
2743}
2744
[email protected]310ebd6302011-10-10 19:06:282745void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2746 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172747 // Notify the browser that we failed a provisional load with an error.
2748 //
2749 // Note: It is important this notification occur before DidStopLoading so the
2750 // SSL manager can react to the provisional load failure before being
2751 // notified the load stopped.
2752 //
2753 WebDataSource* ds = frame->provisionalDataSource();
2754 DCHECK(ds);
2755
2756 const WebURLRequest& failed_request = ds->request();
2757
[email protected]28685da92011-02-07 21:49:172758 FOR_EACH_OBSERVER(
2759 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2760
[email protected]3d9689372009-09-10 04:29:172761 bool show_repost_interstitial =
2762 (error.reason == net::ERR_CACHE_MISS &&
2763 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582764
2765 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2766 params.frame_id = frame->identifier();
2767 params.is_main_frame = !frame->parent();
2768 params.error_code = error.reason;
2769 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2770 failed_request,
2771 error,
2772 NULL,
2773 &params.error_description);
2774 params.url = error.unreachableURL;
2775 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172776 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582777 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172778
2779 // Don't display an error page if this is simply a cancelled load. Aside
2780 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2781 if (error.reason == net::ERR_ABORTED)
2782 return;
[email protected]b553edd52012-01-10 12:15:232783 // Don't display an error message if the request was handled by an
2784 // external protocol handler.
2785 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2786 return;
[email protected]3d9689372009-09-10 04:29:172787
2788 // Make sure we never show errors in view source mode.
2789 frame->enableViewSourceMode(false);
2790
[email protected]007733c2011-11-17 00:34:072791 DocumentState* document_state = DocumentState::FromDataSource(ds);
2792 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172793
2794 // If this is a failed back/forward/reload navigation, then we need to do a
2795 // 'replace' load. This is necessary to avoid messing up session history.
2796 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2797 // as session history is concerned.
2798 //
2799 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2800 // the page id.
2801 //
2802 bool replace =
2803 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582804 navigation_state->transition_type() ==
2805 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172806
2807 // If we failed on a browser initiated request, then make sure that our error
2808 // page load is regarded as the same browser initiated request.
2809 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072810 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2811 pending_navigation_params_->page_id =
2812 navigation_state->pending_page_id();
2813 pending_navigation_params_->pending_history_list_offset =
2814 navigation_state->pending_history_list_offset();
2815 pending_navigation_params_->transition =
2816 navigation_state->transition_type();
2817 pending_navigation_params_->request_time =
2818 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172819 }
2820
2821 // Provide the user with a more helpful error page?
2822 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2823 return;
2824
2825 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082826 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172827}
2828
[email protected]310ebd6302011-10-10 19:06:282829void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172830 WebFrame* frame, const char* data, size_t data_len,
2831 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072832 DocumentState* document_state =
2833 DocumentState::FromDataSource(frame->dataSource());
2834 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172835}
2836
[email protected]310ebd6302011-10-10 19:06:282837void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2838 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072839 DocumentState* document_state =
2840 DocumentState::FromDataSource(frame->dataSource());
2841 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172842
[email protected]007733c2011-11-17 00:34:072843 if (document_state->commit_load_time().is_null())
2844 document_state->set_commit_load_time(Time::Now());
2845
[email protected]3d9689372009-09-10 04:29:172846 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202847 // When we perform a new navigation, we need to update the last committed
2848 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172849 UpdateSessionHistory(frame);
2850
2851 // We bump our Page ID to correspond with the new session history entry.
2852 page_id_ = next_page_id_++;
2853
[email protected]285f4bb82012-04-17 15:57:282854 // Don't update history_page_ids_ (etc) for content::kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:262855 // we don't want to forget the entry that was there, and since we will
[email protected]285f4bb82012-04-17 15:57:282856 // never come back to content::kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:312857 // UpdateSessionHistory and update page_id_ even in this case, so that
2858 // the current entry gets a state update and so that we don't send a
2859 // state update to the wrong entry when we swap back in.
[email protected]285f4bb82012-04-17 15:57:282860 if (GetLoadingUrl(frame) != GURL(content::kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:312861 // Advance our offset in session history, applying the length limit.
2862 // There is now no forward history.
2863 history_list_offset_++;
2864 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2865 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
2866 history_list_length_ = history_list_offset_ + 1;
2867 history_page_ids_.resize(history_list_length_, -1);
2868 history_page_ids_[history_list_offset_] = page_id_;
2869 }
[email protected]3d9689372009-09-10 04:29:172870 } else {
2871 // Inspect the navigation_state on this frame to see if the navigation
2872 // corresponds to a session history navigation... Note: |frame| may or
2873 // may not be the toplevel frame, but for the case of capturing session
2874 // history, the first committed frame suffices. We keep track of whether
2875 // we've seen this commit before so that only capture session history once
2876 // per navigation.
2877 //
2878 // Note that we need to check if the page ID changed. In the case of a
2879 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2880 // previous URL and the current page ID, which would be wrong.
2881 if (navigation_state->pending_page_id() != -1 &&
2882 navigation_state->pending_page_id() != page_id_ &&
2883 !navigation_state->request_committed()) {
2884 // This is a successful session history navigation!
2885 UpdateSessionHistory(frame);
2886 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002887
2888 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032889
2890 // If the history list is valid, our list of page IDs should be correct.
2891 DCHECK(history_list_length_ <= 0 ||
2892 history_list_offset_ < 0 ||
2893 history_list_offset_ >= history_list_length_ ||
2894 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172895 }
2896 }
2897
[email protected]28685da92011-02-07 21:49:172898 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2899 DidCommitProvisionalLoad(frame, is_new_navigation));
2900
[email protected]3d9689372009-09-10 04:29:172901 // Remember that we've already processed this request, so we don't update
2902 // the session history again. We do this regardless of whether this is
2903 // a session history navigation, because if we attempted a session history
2904 // navigation without valid HistoryItem state, WebCore will think it is a
2905 // new navigation.
2906 navigation_state->set_request_committed(true);
2907
2908 UpdateURL(frame);
2909
2910 // If this committed load was initiated by a client redirect, we're
2911 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152912 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172913
2914 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272915 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172916}
2917
[email protected]310ebd6302011-10-10 19:06:282918void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102919 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2920 DidClearWindowObject(frame));
2921
[email protected]b6cb3a842011-06-24 18:28:412922 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212923 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252924 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2925 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272926 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172927 }
[email protected]766a7082012-02-03 23:39:152928
2929 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
2930 if (!dom_automation_controller_.get())
2931 dom_automation_controller_.reset(new DomAutomationController());
2932 dom_automation_controller_->set_message_sender(
2933 static_cast<content::RenderView*>(this));
2934 dom_automation_controller_->set_routing_id(routing_id());
2935 dom_automation_controller_->BindToJavascript(frame,
2936 "domAutomationController");
2937 }
[email protected]3d9689372009-09-10 04:29:172938}
2939
[email protected]310ebd6302011-10-10 19:06:282940void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172941 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412942 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252943 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:432944 if (frame == webview()->mainFrame())
2945 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:172946 }
[email protected]e48869a2011-04-01 19:56:032947
2948 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2949 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172950}
2951
[email protected]310ebd6302011-10-10 19:06:282952void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2953 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462954 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172955
2956 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272957 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172958}
2959
[email protected]310ebd6302011-10-10 19:06:282960void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132961 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2962 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582963}
2964
[email protected]310ebd6302011-10-10 19:06:282965void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172966 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072967 DocumentState* document_state = DocumentState::FromDataSource(ds);
2968 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172969
[email protected]622474d2010-11-04 09:21:082970 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172971
[email protected]28685da92011-02-07 21:49:172972 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2973 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172974
2975 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272976 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172977}
2978
[email protected]310ebd6302011-10-10 19:06:282979void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082980 if (webview()->mainFrame() == frame) {
2981 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2982 page_id_));
2983 }
[email protected]3d9689372009-09-10 04:29:172984}
2985
[email protected]310ebd6302011-10-10 19:06:282986void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312987 WebDataSource* ds = frame->dataSource();
2988 DCHECK(ds);
2989
2990
[email protected]28685da92011-02-07 21:49:172991 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312992
2993 const WebURLRequest& failed_request = ds->request();
2994 string16 error_description;
2995 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2996 failed_request,
2997 error,
2998 NULL,
2999 &error_description);
3000 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3001 frame->identifier(),
3002 failed_request.url(),
3003 !frame->parent(),
3004 error.reason,
3005 error_description));
[email protected]3d9689372009-09-10 04:29:173006}
3007
[email protected]310ebd6302011-10-10 19:06:283008void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173009 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073010 DocumentState* document_state = DocumentState::FromDataSource(ds);
3011 if (document_state->finish_load_time().is_null())
3012 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413013
[email protected]676126f72011-01-15 00:03:513014 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173015
[email protected]1a55c5be2011-11-29 11:36:313016 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3017 frame->identifier(),
3018 ds->request().url(),
3019 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173020}
3021
[email protected]310ebd6302011-10-10 19:06:283022void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173023 WebFrame* frame, bool is_new_navigation) {
3024 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073025 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173026 // update the ExtraData on the datasource so that others who read the
3027 // ExtraData will get the new NavigationState. Similarly, if we did not
3028 // initiate this navigation, then we need to take care to reset any pre-
3029 // existing navigation state to a content-initiated navigation state.
3030 // DidCreateDataSource conveniently takes care of this for us.
3031 didCreateDataSource(frame, frame->dataSource());
3032
[email protected]007733c2011-11-17 00:34:073033 DocumentState* document_state =
3034 DocumentState::FromDataSource(frame->dataSource());
3035 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093036 new_state->set_was_within_same_page(true);
3037
[email protected]3d9689372009-09-10 04:29:173038 didCommitProvisionalLoad(frame, is_new_navigation);
3039
[email protected]750fcf872011-08-03 23:10:473040 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3041 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173042}
3043
[email protected]310ebd6302011-10-10 19:06:283044void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313045 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593046}
3047
[email protected]310ebd6302011-10-10 19:06:283048void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173049 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3050 // Ignore
3051}
3052
[email protected]310ebd6302011-10-10 19:06:283053void RenderViewImpl::willSendRequest(WebFrame* frame,
3054 unsigned identifier,
3055 WebURLRequest& request,
3056 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303057 WebFrame* top_frame = frame->top();
3058 if (!top_frame)
3059 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513060 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3061 WebDataSource* top_data_source = top_frame->dataSource();
3062 WebDataSource* data_source =
3063 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223064
[email protected]78d5cfe2011-02-04 08:43:223065 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:033066 GURL new_url;
3067 if (content::GetContentClient()->renderer()->WillSendRequest(
3068 frame, request_url, &new_url)) {
3069 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:223070 }
3071
[email protected]2905f742011-10-13 03:51:583072 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073073 DocumentState* document_state = DocumentState::FromDataSource(data_source);
3074 NavigationState* navigation_state = document_state->navigation_state();
3075 if (document_state) {
3076 if (document_state->is_cache_policy_override_set())
3077 request.setCachePolicy(document_state->cache_policy_override());
3078 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:303079 }
[email protected]8a3125a712010-08-09 18:58:513080
[email protected]91043a8232011-11-04 16:41:193081 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:063082 new RequestExtraData(frame->referrerPolicy(),
3083 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193084 frame->identifier(),
3085 frame->parent() == top_frame,
3086 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:483087 transition_type,
3088 navigation_state->transferred_request_child_id(),
3089 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573090
[email protected]007733c2011-11-17 00:34:073091 DocumentState* top_document_state =
3092 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573093 // TODO(gavinp): separate out prefetching and prerender field trials
3094 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073095 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:573096 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
3097 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:073098 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513099
[email protected]3d9689372009-09-10 04:29:173100 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133101 request.setHasUserGesture(frame->isProcessingUserGesture());
3102
[email protected]0a8db0d2011-04-13 15:15:403103 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133104 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173105}
3106
[email protected]310ebd6302011-10-10 19:06:283107void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173108 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493109
[email protected]3d9689372009-09-10 04:29:173110 // Only do this for responses that correspond to a provisional data source
3111 // of the top-most frame. If we have a provisional data source, then we
3112 // can't have any sub-resources yet, so we know that this response must
3113 // correspond to a frame load.
3114 if (!frame->provisionalDataSource() || frame->parent())
3115 return;
3116
3117 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083118 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173119 if (frame->isViewSourceModeEnabled())
3120 return;
3121
[email protected]007733c2011-11-17 00:34:073122 DocumentState* document_state =
3123 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083124 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533125
[email protected]972ebdff2010-06-10 22:59:073126 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073127 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3128 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403129 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3130 if (extra_data) {
3131 document_state->set_npn_negotiated_protocol(
3132 extra_data->npn_negotiated_protocol());
3133 }
[email protected]007733c2011-11-17 00:34:073134 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573135 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073136 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3137 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093138 // Whether or not the http status code actually corresponds to an error is
3139 // only checked when the page is done loading, if |use_error_page| is
3140 // still true.
[email protected]007733c2011-11-17 00:34:073141 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173142}
3143
[email protected]310ebd6302011-10-10 19:06:283144void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173145 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073146 DocumentState* document_state =
3147 DocumentState::FromDataSource(frame->dataSource());
3148 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173149 return;
3150
[email protected]7bfc153f2011-09-23 22:00:203151 // Do not show error page when DevTools is attached.
3152 if (devtools_agent_->IsAttached())
3153 return;
3154
[email protected]06333afe2011-02-24 14:55:093155 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073156 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083157 if (http_status_code == 404) {
3158 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413159 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173160
[email protected]b6cb3a842011-06-24 18:28:413161 const GURL& error_page_url =
3162 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093163 if (error_page_url.is_valid()) {
3164 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473165 original_error.domain = "http";
3166 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413167 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173168
[email protected]007733c2011-11-17 00:34:073169 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093170 new AltErrorPageResourceFetcher(
3171 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083172 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3173 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093174 return;
3175 }
3176 }
[email protected]3d9689372009-09-10 04:29:173177
[email protected]e6a2ce52011-10-08 01:40:133178 std::string error_domain;
3179 if (content::GetContentClient()->renderer()->HasErrorPage(
3180 http_status_code, &error_domain)) {
3181 WebURLError error;
3182 error.unreachableURL = frame->document().url();
3183 error.domain = WebString::fromUTF8(error_domain);
3184 error.reason = http_status_code;
3185
3186 LoadNavigationErrorPage(
3187 frame, frame->dataSource()->request(), error, std::string(), true);
3188 }
[email protected]3d9689372009-09-10 04:29:173189}
3190
[email protected]310ebd6302011-10-10 19:06:283191void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173192 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3193 // Ignore
3194}
3195
[email protected]310ebd6302011-10-10 19:06:283196void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173197 WebFrame* frame, const WebURLRequest& request,
3198 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003199 // The recipients of this message have no use for data: URLs: they don't
3200 // affect the page's insecure content list and are not in the disk cache. To
3201 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3202 // filter them out here.
3203 GURL url(request.url());
3204 if (url.SchemeIs("data"))
3205 return;
3206
[email protected]3d9689372009-09-10 04:29:173207 // Let the browser know we loaded a resource from the memory cache. This
3208 // message is needed to display the correct SSL indicators.
3209 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3210 routing_id_,
[email protected]84703292011-10-28 20:44:003211 url,
[email protected]70435962011-08-02 20:13:283212 response.securityInfo(),
3213 request.httpMethod().utf8(),
3214 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173215}
3216
[email protected]310ebd6302011-10-10 19:06:283217void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293218 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3219}
3220
[email protected]310ebd6302011-10-10 19:06:283221void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023222 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293223 Send(new ViewHostMsg_DidRunInsecureContent(
3224 routing_id_,
[email protected]92771112011-01-20 00:13:023225 origin.toString().utf8(),
3226 target));
[email protected]e3d60e5d2009-09-25 21:08:293227}
3228
[email protected]310ebd6302011-10-10 19:06:283229void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033230 webkit_glue::WebURLLoaderImpl* loader_impl =
3231 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3232 loader_impl->UpdateRoutingId(routing_id_);
3233}
3234
[email protected]310ebd6302011-10-10 19:06:283235void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173236 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3237}
3238
[email protected]310ebd6302011-10-10 19:06:283239void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3240 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583241 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283242 int world_id) {
[email protected]5bc10932011-09-21 21:03:303243 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583244 frame, context, extension_group, world_id);
3245}
3246
3247void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3248 v8::Handle<v8::Context> context,
3249 int world_id) {
3250 content::GetContentClient()->renderer()->DidCreateScriptContext(
3251 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283252}
3253
[email protected]310ebd6302011-10-10 19:06:283254void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3255 v8::Handle<v8::Context> context,
3256 int world_id) {
[email protected]5bc10932011-09-21 21:03:303257 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3258 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283259}
3260
[email protected]310ebd6302011-10-10 19:06:283261void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073262 // We don't always want to send the change messages over IPC, only if we've
3263 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3264 // message.
3265 if (!send_preferred_size_changes_ || !webview())
3266 return;
3267
[email protected]705243f2010-05-05 19:58:073268 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3269 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533270
3271 // In the presence of zoom, these sizes are still reported as if unzoomed,
3272 // so we need to adjust.
3273 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3274 size.set_width(static_cast<int>(size.width() * zoom_factor));
3275 size.set_height(static_cast<int>(size.height() * zoom_factor));
3276
[email protected]705243f2010-05-05 19:58:073277 if (size == preferred_size_)
3278 return;
[email protected]c27324b2009-11-19 22:44:293279
[email protected]705243f2010-05-05 19:58:073280 preferred_size_ = size;
3281 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3282 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173283}
3284
[email protected]273558fb2012-01-12 15:03:513285void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]50da23d02012-04-13 17:47:483286 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
3287 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
3288 return;
3289
[email protected]273558fb2012-01-12 15:03:513290#if defined(ENABLE_P2P_APIS)
3291 if (!p2p_socket_dispatcher_)
3292 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3293#endif
3294
[email protected]5b87e782012-02-09 18:19:323295#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513296 if (!media_stream_dispatcher_)
3297 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3298
[email protected]1bc65a42012-04-23 09:31:253299 if (!media_stream_impl_) {
[email protected]273558fb2012-01-12 15:03:513300 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3301 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253302 this,
[email protected]273558fb2012-01-12 15:03:513303 media_stream_dispatcher_,
3304 p2p_socket_dispatcher_,
3305 RenderThreadImpl::current()->video_capture_impl_manager(),
3306 factory);
3307 }
[email protected]5b87e782012-02-09 18:19:323308#endif
[email protected]273558fb2012-01-12 15:03:513309}
3310
[email protected]310ebd6302011-10-10 19:06:283311void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3312 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313313 if (webview()->mainFrame() != frame)
3314 return;
3315 WebView* frameView = frame->view();
3316 if (!frameView)
3317 return;
3318
3319 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3320 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3321
3322 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3323 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3324 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3325 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3326
3327 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3328 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3329 }
3330}
3331
[email protected]310ebd6302011-10-10 19:06:283332void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313333 WebSize offset = frame->scrollOffset();
3334 WebSize minimum_offset = frame->minimumScrollOffset();
3335 WebSize maximum_offset = frame->maximumScrollOffset();
3336
3337 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3338 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3339
3340 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3341 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3342 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3343 routing_id_, is_pinned_to_left, is_pinned_to_right));
3344
3345 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3346 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3347 }
3348}
3349
[email protected]310ebd6302011-10-10 19:06:283350void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493351 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313352
3353 if (webview()->mainFrame() == frame)
3354 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:263355
3356 FOR_EACH_OBSERVER(
3357 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:313358}
3359
[email protected]310ebd6302011-10-10 19:06:283360void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313361 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493362}
3363
[email protected]ea931252012-02-15 22:01:033364void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3365 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3366}
3367
[email protected]310ebd6302011-10-10 19:06:283368void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3369 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113370 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3371 if (!count)
3372 active_match_ordinal = 0;
3373
3374 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3375 routing_id_,
3376 request_id,
3377 count,
3378 gfx::Rect(),
3379 active_match_ordinal,
3380 final_update);
3381
[email protected]8922e1f2009-10-03 05:01:263382 // If we have a message that has been queued up, then we should just replace
3383 // it. The ACK from the browser will make sure it gets sent when the browser
3384 // wants it.
3385 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263386 queued_find_reply_message_.reset(msg);
3387 } else {
3388 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113389 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263390 }
3391}
3392
[email protected]310ebd6302011-10-10 19:06:283393void RenderViewImpl::reportFindInPageSelection(int request_id,
3394 int active_match_ordinal,
3395 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263396 // Send the search result over to the browser process.
3397 Send(new ViewHostMsg_Find_Reply(routing_id_,
3398 request_id,
3399 -1,
3400 selection_rect,
3401 active_match_ordinal,
3402 false));
3403}
3404
[email protected]310ebd6302011-10-10 19:06:283405void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223406 WebFrame* frame,
3407 WebFileSystem::Type type,
3408 long long size,
[email protected]d275d7a2010-11-03 01:34:493409 bool create,
[email protected]2b06a992010-08-21 05:48:223410 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083411 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223412
[email protected]b6cb3a842011-06-24 18:28:413413 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563414 if (origin.isUnique()) {
3415 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083416 callbacks->didFail(WebKit::WebFileErrorAbort);
3417 return;
3418 }
[email protected]2b06a992010-08-21 05:48:223419
[email protected]c5a272d2010-09-27 18:37:083420 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3421 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493422 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223423}
3424
[email protected]310ebd6302011-10-10 19:06:283425void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403426 WebFrame* frame,
3427 WebStorageQuotaType type,
3428 WebStorageQuotaCallbacks* callbacks) {
3429 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413430 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563431 if (origin.isUnique()) {
3432 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403433 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3434 return;
3435 }
3436 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533437 GURL(origin.toString()),
3438 static_cast<quota::StorageType>(type),
3439 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403440}
3441
[email protected]310ebd6302011-10-10 19:06:283442void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403443 WebFrame* frame,
3444 WebStorageQuotaType type,
3445 unsigned long long requested_size,
3446 WebStorageQuotaCallbacks* callbacks) {
3447 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413448 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563449 if (origin.isUnique()) {
3450 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403451 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3452 return;
3453 }
3454 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533455 routing_id(), GURL(origin.toString()),
3456 static_cast<quota::StorageType>(type), requested_size,
3457 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403458}
3459
[email protected]8b5af492011-11-28 21:50:583460void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153461 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063462 string16 title = service.title();
3463 if (title.empty())
3464 title = webview()->mainFrame()->document().title();
3465
[email protected]8b5af492011-11-28 21:50:583466 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3467 service.action(),
3468 service.type(),
3469 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063470 title,
[email protected]8b5af492011-11-28 21:50:583471 service.disposition()));
3472}
3473
[email protected]ffc8bed2012-01-21 01:23:153474void RenderViewImpl::dispatchIntent(
3475 WebFrame* frame, const WebIntentRequest& intentRequest) {
3476 webkit_glue::WebIntentData intent_data(intentRequest.intent());
3477 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583478 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153479 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583480}
3481
[email protected]5fa3a062012-03-21 15:39:343482void RenderViewImpl::willOpenSocketStream(
3483 WebSocketStreamHandle* handle) {
3484 SocketStreamHandleData::AddToHandle(handle, routing_id_);
3485}
3486
[email protected]18d5be92011-07-25 18:00:193487// WebKit::WebPageSerializerClient implementation ------------------------------
3488
[email protected]310ebd6302011-10-10 19:06:283489void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193490 const WebURL& frame_url,
3491 const WebCString& data,
3492 WebPageSerializerClient::PageSerializationStatus status) {
3493 Send(new ViewHostMsg_SendSerializedHtmlData(
3494 routing_id(),
3495 frame_url,
3496 data.data(),
3497 static_cast<int32>(status)));
3498}
3499
[email protected]a2ef54c2011-10-10 16:20:313500// content::RenderView implementation ------------------------------------------
3501
[email protected]310ebd6302011-10-10 19:06:283502bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313503 return RenderWidget::Send(message);
3504}
3505
[email protected]82114f52012-03-20 22:53:413506int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:313507 return routing_id_;
3508}
3509
[email protected]82114f52012-03-20 22:53:413510int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:313511 return page_id_;
3512}
3513
[email protected]82114f52012-03-20 22:53:413514gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:313515 return size();
3516}
3517
[email protected]82114f52012-03-20 22:53:413518gfx::NativeViewId RenderViewImpl::GetHostWindow() const {
[email protected]a2ef54c2011-10-10 16:20:313519 return host_window();
3520}
3521
[email protected]82114f52012-03-20 22:53:413522WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313523 return webkit_preferences_;
3524}
3525
[email protected]82114f52012-03-20 22:53:413526WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313527 return webview();
3528}
3529
[email protected]82114f52012-03-20 22:53:413530WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313531 if (!webview())
3532 return WebNode();
3533 WebFrame* focused_frame = webview()->focusedFrame();
3534 if (focused_frame) {
3535 WebDocument doc = focused_frame->document();
3536 if (!doc.isNull())
3537 return doc.focusedNode();
3538 }
3539
3540 return WebNode();
3541}
3542
[email protected]82114f52012-03-20 22:53:413543WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313544 return context_menu_node_;
3545}
3546
[email protected]82114f52012-03-20 22:53:413547bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) const {
[email protected]a2ef54c2011-10-10 16:20:313548 bool is_editable_node = false;
3549 if (!node.isNull()) {
3550 if (node.isContentEditable()) {
3551 is_editable_node = true;
3552 } else if (node.isElementNode()) {
3553 is_editable_node =
3554 node.toConst<WebElement>().isTextFormControlElement();
3555 }
3556 }
3557 return is_editable_node;
3558}
3559
[email protected]310ebd6302011-10-10 19:06:283560WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313561 WebKit::WebFrame* frame,
3562 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:413563 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:313564 bool pepper_plugin_was_registered = false;
3565 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3566 pepper_delegate_.CreatePepperPluginModule(info,
3567 &pepper_plugin_was_registered));
3568 if (pepper_plugin_was_registered) {
3569 if (!pepper_module)
3570 return NULL;
3571 return new webkit::ppapi::WebPluginImpl(
3572 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3573 }
3574
[email protected]34b27e442012-01-20 20:07:413575#if defined(USE_AURA)
3576 return NULL;
3577#else
[email protected]a2ef54c2011-10-10 16:20:313578 return new webkit::npapi::WebPluginImpl(
3579 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413580#endif
[email protected]a2ef54c2011-10-10 16:20:313581}
3582
[email protected]310ebd6302011-10-10 19:06:283583void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3584 const string16& jscript,
3585 int id,
3586 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313587 v8::Handle<v8::Value> result;
3588 WebFrame* web_frame = GetChildFrame(frame_xpath);
3589 if (web_frame)
3590 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3591 if (notify_result) {
3592 ListValue list;
3593 if (!result.IsEmpty() && web_frame) {
3594 v8::HandleScope handle_scope;
3595 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3596 v8::Context::Scope context_scope(context);
3597 V8ValueConverterImpl converter;
3598 converter.set_allow_date(true);
3599 converter.set_allow_regexp(true);
3600 list.Set(0, converter.FromV8Value(result, context));
3601 } else {
3602 list.Set(0, Value::CreateNullValue());
3603 }
3604 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3605 }
3606}
3607
[email protected]310ebd6302011-10-10 19:06:283608bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313609 return (!send_preferred_size_changes_ ||
3610 (disable_scrollbars_size_limit_.width() <= width ||
3611 disable_scrollbars_size_limit_.height() <= height));
3612}
3613
[email protected]82114f52012-03-20 22:53:413614int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:313615 return enabled_bindings_;
3616}
3617
[email protected]82114f52012-03-20 22:53:413618bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:313619 return send_content_state_immediately_;
3620}
3621
[email protected]82114f52012-03-20 22:53:413622float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:313623 return filtered_time_per_frame();
3624}
3625
[email protected]310ebd6302011-10-10 19:06:283626void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
[email protected]82114f52012-03-20 22:53:413627 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313628 showContextMenu(frame, data);
3629}
3630
[email protected]82114f52012-03-20 22:53:413631WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313632 return visibilityState();
3633}
3634
[email protected]310ebd6302011-10-10 19:06:283635void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3636 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313637 return runModalAlertDialog(frame, message);
3638}
3639
[email protected]310ebd6302011-10-10 19:06:283640void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313641 WebKit::WebFrame* frame,
3642 const WebKit::WebURLRequest& request,
3643 WebKit::WebNavigationPolicy policy) {
3644 loadURLExternally(frame, request, policy);
3645}
3646
3647// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513648
[email protected]310ebd6302011-10-10 19:06:283649webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533650 const FilePath& file_path,
3651 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203652 if (!PluginChannelHost::IsListening()) {
3653 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593654 return NULL;
[email protected]94752ee2012-02-10 10:38:203655 }
[email protected]f103ab72009-09-02 17:10:593656
[email protected]00c39612010-03-06 02:53:283657 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463658 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323659#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223660 return webkit::npapi::WebPluginDelegateImpl::Create(
3661 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093662#else
[email protected]7398dcc2011-09-06 21:40:323663 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223664 NOTIMPLEMENTED();
3665 return NULL;
[email protected]7b6616f2010-01-14 18:07:553666#endif
[email protected]f103ab72009-09-02 17:10:593667 }
3668
[email protected]4e0616e2010-05-28 14:55:533669 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593670}
3671
[email protected]310ebd6302011-10-10 19:06:283672void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033673#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273674 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593675#endif
3676}
3677
[email protected]310ebd6302011-10-10 19:06:283678void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033679#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273680 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593681#endif
3682 CleanupWindowInPluginMoves(window);
3683}
3684
[email protected]310ebd6302011-10-10 19:06:283685void RenderViewImpl::DidMovePlugin(
3686 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593687 SchedulePluginMove(move);
3688}
3689
[email protected]310ebd6302011-10-10 19:06:283690void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593691 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523692 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593693}
3694
[email protected]310ebd6302011-10-10 19:06:283695void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593696 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523697 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593698}
3699
[email protected]310ebd6302011-10-10 19:06:283700WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513701 return &cookie_jar_;
3702}
3703
[email protected]a9288f52011-11-17 05:18:163704void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073705 Send(new ViewHostMsg_MediaNotification(routing_id_,
3706 reinterpret_cast<int64>(player),
3707 player->hasVideo(),
3708 player->hasAudio(),
3709 true));
3710}
3711
[email protected]a9288f52011-11-17 05:18:163712void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073713 Send(new ViewHostMsg_MediaNotification(routing_id_,
3714 reinterpret_cast<int64>(player),
3715 player->hasVideo(),
3716 player->hasAudio(),
3717 false));
3718}
3719
[email protected]a9288f52011-11-17 05:18:163720void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073721 DidPause(player);
3722}
3723
[email protected]310ebd6302011-10-10 19:06:283724void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293725 if (!webview())
3726 return;
3727
[email protected]26aa0482009-09-30 16:55:273728 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:053729 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:293730}
3731
[email protected]310ebd6302011-10-10 19:06:283732void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363733 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003734 if (!frame)
3735 return;
[email protected]b781ff282011-08-20 06:19:363736
[email protected]e99ef6f2011-10-16 01:13:003737 string16 text;
3738 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:523739 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:003740
[email protected]3c8c74c2012-03-15 07:34:523741 if (pepper_delegate_.IsPluginFocused()) {
3742 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:413743 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:523744 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:003745 } else {
[email protected]3c8c74c2012-03-15 07:34:523746 size_t location, length;
3747 if (!webview()->caretOrSelectionRange(&location, &length))
3748 return;
3749
3750 range = ui::Range(location, location + length);
3751
3752 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3753 // If current focused element is editable, we will send 100 more chars
3754 // before and after selection. It is for input method surrounding text
3755 // feature.
3756 if (location > kExtraCharsBeforeAndAfterSelection)
3757 offset = location - kExtraCharsBeforeAndAfterSelection;
3758 else
3759 offset = 0;
3760 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3761 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3762 if (!webrange.isNull())
3763 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3764 } else {
3765 offset = location;
3766 text = frame->selectionAsText();
3767 // http://crbug.com/101435
3768 // In some case, frame->selectionAsText() returned text's length is not
3769 // equal to the length returned from webview()->caretOrSelectionRange().
3770 // So we have to set the range according to text.length().
3771 range.set_end(range.start() + text.length());
3772 }
[email protected]b781ff282011-08-20 06:19:363773 }
3774
[email protected]b781ff282011-08-20 06:19:363775 // Sometimes we get repeated didChangeSelection calls from webkit when
3776 // the selection hasn't actually changed. We don't want to report these
3777 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003778 if (selection_text_offset_ != offset ||
3779 selection_range_ != range ||
3780 selection_text_ != text) {
3781 selection_text_ = text;
3782 selection_text_offset_ = offset;
3783 selection_range_ = range;
3784 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3785 }
[email protected]b781ff282011-08-20 06:19:363786}
3787
[email protected]310ebd6302011-10-10 19:06:283788GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3789 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553790 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293791 // If the URL that failed was secure, then the embedding web page was not
3792 // expecting a network attacker to be able to manipulate its contents. As
3793 // we fetch alternate error pages over HTTP, we would be allowing a network
3794 // attacker to manipulate the contents of the response if we tried to use
3795 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153796 return GURL();
initial.commit09911bf2008-07-26 23:55:293797 }
3798
3799 // Grab the base URL from the browser process.
3800 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153801 return GURL();
initial.commit09911bf2008-07-26 23:55:293802
3803 // Strip query params from the failed URL.
3804 GURL::Replacements remove_params;
3805 remove_params.ClearUsername();
3806 remove_params.ClearPassword();
3807 remove_params.ClearQuery();
3808 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553809 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503810 std::string spec_to_send = url_to_send.spec();
3811 // Notify link doctor of the url truncation by sending of "?" at the end.
3812 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:413813 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293814
3815 // Construct the query params to send to link doctor.
3816 std::string params(alternate_error_page_url_.query());
3817 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023818 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293819 params.append("&sourceid=chrome");
3820 params.append("&error=");
3821 switch (error_type) {
3822 case DNS_ERROR:
3823 params.append("dnserror");
3824 break;
3825
3826 case HTTP_404:
3827 params.append("http404");
3828 break;
3829
[email protected]5df266ac2008-10-15 19:50:133830 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333831 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133832 break;
3833
initial.commit09911bf2008-07-26 23:55:293834 default:
3835 NOTREACHED() << "unknown ErrorPageType";
3836 }
3837
3838 // OK, build the final url to return.
3839 GURL::Replacements link_doctor_params;
3840 link_doctor_params.SetQueryStr(params);
3841 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3842 return url;
3843}
3844
[email protected]310ebd6302011-10-10 19:06:283845GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593846 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3847 return GURL();
3848 else
3849 return creator_url_;
3850}
3851
[email protected]69ddf852012-02-21 23:21:313852GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
3853 WebDataSource* ds = frame->dataSource();
3854 if (ds->hasUnreachableURL())
3855 return ds->unreachableURL();
3856
3857 const WebURLRequest& request = ds->request();
3858 return request.url();
3859}
3860
[email protected]310ebd6302011-10-10 19:06:283861WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273862 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313863 web_ui_bindings_.reset(new WebUIBindings(
3864 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463865 }
[email protected]c50008512011-02-03 01:17:273866 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463867}
3868
[email protected]310ebd6302011-10-10 19:06:283869WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013870 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493871}
3872
[email protected]310ebd6302011-10-10 19:06:283873void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3874 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273875 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493876
[email protected]872542532011-06-23 00:43:163877 // Check if the plugin still exists in the document.
3878 if (main_frame->document().isPluginDocument() &&
3879 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493880 if (options.findNext) {
3881 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013882 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493883 } else {
[email protected]afdbd142010-07-10 08:01:233884 if (GetWebPluginFromPluginDocument()->startFind(
3885 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493886 } else {
[email protected]e7c58a32010-08-13 19:47:113887 // Send "no results".
3888 Send(new ViewHostMsg_Find_Reply(routing_id_,
3889 request_id,
3890 0,
3891 gfx::Rect(),
3892 0,
3893 true));
[email protected]24a7f3c2010-03-25 08:26:493894 }
3895 }
3896 return;
3897 }
3898
[email protected]b4bb2502009-10-01 22:35:273899 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273900 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293901 WebFrame* search_frame = focused_frame; // start searching focused frame.
3902
3903 bool multi_frame = (frame_after_main != main_frame);
3904
3905 // If we have multiple frames, we don't want to wrap the search within the
3906 // frame, so we check here if we only have main_frame in the chain.
3907 bool wrap_within_frame = !multi_frame;
3908
[email protected]b3f2b912009-04-09 16:18:523909 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293910 bool result = false;
3911
[email protected]7830da3e2009-11-06 16:27:263912 // If something is selected when we start searching it means we cannot just
3913 // increment the current match ordinal; we need to re-generate it.
3914 WebRange current_selection = focused_frame->selectionRange();
3915
initial.commit09911bf2008-07-26 23:55:293916 do {
[email protected]dd7daa82009-08-10 05:46:453917 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593918 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293919
3920 if (!result) {
3921 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223922 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293923
3924 // Find the next frame, but skip the invisible ones.
3925 do {
3926 // What is the next frame to search? (we might be going backwards). Note
3927 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593928 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273929 search_frame->traverseNext(true) :
3930 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453931 } while (!search_frame->hasVisibleContent() &&
3932 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293933
[email protected]884db412008-11-24 23:46:503934 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223935 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293936
3937 // If we have multiple frames and we have wrapped back around to the
3938 // focused frame, we need to search it once more allowing wrap within
3939 // the frame, otherwise it will report 'no match' if the focused frame has
3940 // reported matches, but no frames after the focused_frame contain a
3941 // match for the search word(s).
3942 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453943 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593944 request_id, search_text, options, true, // Force wrapping.
3945 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293946 }
3947 }
3948
[email protected]26aa0482009-09-30 16:55:273949 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293950 } while (!result && search_frame != focused_frame);
3951
[email protected]7830da3e2009-11-06 16:27:263952 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293953 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453954 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293955 } else {
3956 // If nothing is found, set result to "0 of 0", otherwise, set it to
3957 // "-1 of 1" to indicate that we found at least one item, but we don't know
3958 // yet what is active.
3959 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3960 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293961
[email protected]4f3dc372009-02-24 00:10:293962 // If we find no matches then this will be our last status update.
3963 // Otherwise the scoping effort will send more results.
3964 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293965
[email protected]4f3dc372009-02-24 00:10:293966 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403967 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593968 request_id,
[email protected]4f3dc372009-02-24 00:10:293969 match_count,
3970 selection_rect,
3971 ordinal,
3972 final_status_update));
initial.commit09911bf2008-07-26 23:55:293973
initial.commit09911bf2008-07-26 23:55:293974 // Scoping effort begins, starting with the mainframe.
3975 search_frame = main_frame;
3976
[email protected]dd7daa82009-08-10 05:46:453977 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293978
3979 do {
3980 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453981 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293982
3983 // We don't start another scoping effort unless at least one match has
3984 // been found.
3985 if (result) {
3986 // Start new scoping request. If the scoping function determines that it
3987 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453988 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593989 search_text,
3990 options,
initial.commit09911bf2008-07-26 23:55:293991 true); // reset the tickmarks
3992 }
3993
3994 // Iterate to the next frame. The frame will not necessarily scope, for
3995 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273996 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293997 } while (search_frame != main_frame);
3998 }
3999}
4000
[email protected]815dd9872011-11-23 18:40:304001void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494002 WebView* view = webview();
4003 if (!view)
4004 return;
4005
4006 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164007 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014008 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494009 return;
4010 }
4011
[email protected]815dd9872011-11-23 18:40:304012 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494013 if (clear_selection)
4014 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4015
4016 WebFrame* frame = view->mainFrame();
4017 while (frame) {
4018 frame->stopFinding(clear_selection);
4019 frame = frame->traverseNext(false);
4020 }
4021
[email protected]815dd9872011-11-23 18:40:304022 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494023 WebFrame* focused_frame = view->focusedFrame();
4024 if (focused_frame) {
4025 WebDocument doc = focused_frame->document();
4026 if (!doc.isNull()) {
4027 WebNode node = doc.focusedNode();
4028 if (!node.isNull())
4029 node.simulateClick();
4030 }
4031 }
4032 }
4033}
4034
[email protected]310ebd6302011-10-10 19:06:284035void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:494036 // Check if there is any queued up request waiting to be sent.
4037 if (queued_find_reply_message_.get()) {
4038 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424039 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494040 }
4041}
4042
[email protected]54087fe2011-10-28 22:02:484043void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514044 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4045 return;
4046
[email protected]258d31122010-05-09 10:59:414047 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104048
[email protected]b75b8292010-10-01 07:28:254049 double old_zoom_level = webview()->zoomLevel();
4050 double zoom_level;
[email protected]54087fe2011-10-28 22:02:484051 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254052 zoom_level = 0;
4053 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4054 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484055 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254056 } else {
4057 // Either the user hit the zoom factor limit and thus the zoom level is now
4058 // not a whole number, or a plugin changed it to a custom value. We want
4059 // to go to the next whole number so that the user can always get back to
4060 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484061 if ((old_zoom_level > 1 && zoom > 0) ||
4062 (old_zoom_level < 1 && zoom < 0)) {
4063 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254064 } else {
4065 // We're going towards 100%, so first go to the next whole number.
4066 zoom_level = static_cast<int>(old_zoom_level);
4067 }
4068 }
[email protected]b75b8292010-10-01 07:28:254069 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414070 zoomLevelChanged();
4071}
4072
4073void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
4074 int zoom_center_x, int zoom_center_y) {
4075 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4076 kScalingIncrementForGesture);
4077}
4078
4079void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
4080 int zoom_center_x,
4081 int zoom_center_y,
4082 float scaling_increment) {
4083 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4084 return;
4085
[email protected]c514d6372011-08-16 22:54:444086 double old_page_scale_factor = webview()->pageScaleFactor();
4087 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:484088 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444089 page_scale_factor = 1.0;
4090 } else {
4091 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414092 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444093 }
[email protected]47578fa02011-11-02 19:34:414094 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094095 webview()->setPageScaleFactor(page_scale_factor,
4096 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414097 }
[email protected]40bd6582009-12-04 23:49:514098}
4099
[email protected]310ebd6302011-10-10 19:06:284100void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174101 webview()->hidePopups();
4102 webview()->setZoomLevel(false, zoom_level);
4103 zoomLevelChanged();
4104}
4105
[email protected]310ebd6302011-10-10 19:06:284106void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4107 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544108 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294109}
4110
[email protected]310ebd6302011-10-10 19:06:284111void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274112 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294113}
4114
[email protected]310ebd6302011-10-10 19:06:284115void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274116 WebString no_encoding;
4117 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184118}
4119
[email protected]310ebd6302011-10-10 19:06:284120WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454121 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274122 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454123
4124 // xpath string can represent a frame deep down the tree (across multiple
4125 // frame DOMs).
4126 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4127 // should break into 2 xpaths
4128 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414129 std::vector<string16> xpaths;
4130 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454131
[email protected]26aa0482009-09-30 16:55:274132 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414133 for (std::vector<string16>::const_iterator i = xpaths.begin();
4134 frame && i != xpaths.end(); ++i) {
4135 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294136 }
4137
[email protected]dd7daa82009-08-10 05:46:454138 return frame;
initial.commit09911bf2008-07-26 23:55:294139}
4140
[email protected]310ebd6302011-10-10 19:06:284141void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4142 const string16& jscript,
4143 int id,
4144 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:534145 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294146}
4147
[email protected]310ebd6302011-10-10 19:06:284148void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4149 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414150 WebFrame* frame = GetChildFrame(frame_xpath);
4151 if (!frame)
[email protected]216813952011-05-19 22:21:264152 return;
[email protected]ae461542009-06-19 19:03:414153
[email protected]01cf589c2011-07-28 18:04:034154 frame->document().insertUserStyleSheet(
4155 WebString::fromUTF8(css),
4156 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484157}
4158
[email protected]310ebd6302011-10-10 19:06:284159void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094160 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:044161
4162 // Keep track of the total bindings accumulated in this process.
4163 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:294164}
4165
[email protected]310ebd6302011-10-10 19:06:284166void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4167 const std::string& value) {
[email protected]808bda52012-03-09 22:43:324168 if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI)
4169 GetWebUIBindings()->SetProperty(name, value);
4170 else
4171 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:294172}
4173
[email protected]310ebd6302011-10-10 19:06:284174void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4175 const gfx::Point& client_point,
4176 const gfx::Point& screen_point,
4177 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554178 WebDragOperation operation = webview()->dragTargetDragEnter(
4179 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554180 client_point,
4181 screen_point,
4182 ops);
4183
4184 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4185}
4186
[email protected]310ebd6302011-10-10 19:06:284187void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4188 const gfx::Point& screen_point,
4189 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554190 WebDragOperation operation = webview()->dragTargetDragOver(
4191 client_point,
4192 screen_point,
4193 ops);
4194
4195 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4196}
4197
[email protected]310ebd6302011-10-10 19:06:284198void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554199 webview()->dragTargetDragLeave();
4200}
4201
[email protected]310ebd6302011-10-10 19:06:284202void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
4203 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:554204 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:574205
4206 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554207}
4208
[email protected]310ebd6302011-10-10 19:06:284209void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4210 const gfx::Point& screen_point,
4211 bool ended,
4212 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034213 if (ended) {
[email protected]26aa0482009-09-30 16:55:274214 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204215 } else {
4216 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034217 }
initial.commit09911bf2008-07-26 23:55:294218}
4219
[email protected]310ebd6302011-10-10 19:06:284220void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274221 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294222}
4223
[email protected]310ebd6302011-10-10 19:06:284224void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594225 webkit_preferences_ = prefs;
4226 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294227}
4228
[email protected]310ebd6302011-10-10 19:06:284229void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294230 alternate_error_page_url_ = url;
4231}
4232
[email protected]310ebd6302011-10-10 19:06:284233void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514234 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084235 unsigned action) {
4236 if (custom_context.is_pepper_menu)
4237 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4238 else
4239 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584240 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4241 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334242}
4243
[email protected]310ebd6302011-10-10 19:06:284244void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514245 int id,
4246 const std::vector<FilePath>& paths) {
4247 if (!enumeration_completions_[id])
4248 return;
4249
4250 WebVector<WebString> ws_file_names(paths.size());
4251 for (size_t i = 0; i < paths.size(); ++i)
4252 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4253
4254 enumeration_completions_[id]->didChooseFile(ws_file_names);
4255 enumeration_completions_.erase(id);
4256}
4257
[email protected]fb11b6a42012-03-14 07:25:124258void RenderViewImpl::OnFileChooserResponse(
4259 const std::vector<content::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:364260 // This could happen if we navigated to a different page before the user
4261 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474262 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364263 return;
4264
[email protected]b5188522012-03-15 00:18:044265 // Convert Chrome's SelectedFileInfo list to WebKit's.
4266 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
4267 files.size());
4268 for (size_t i = 0; i < files.size(); ++i) {
4269 WebFileChooserCompletion::SelectedFileInfo selected_file;
4270 selected_file.path = webkit_glue::FilePathToWebString(files[i].path);
4271 selected_file.displayName = webkit_glue::FilePathStringToWebString(
4272 files[i].display_name);
4273 selected_files[i] = selected_file;
4274 }
[email protected]a1128322009-10-06 18:38:464275
[email protected]cdaf8d02010-03-30 19:52:474276 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:044277 file_chooser_completions_.front()->completion->didChooseFile(
4278 selected_files);
[email protected]cdaf8d02010-03-30 19:52:474279 file_chooser_completions_.pop_front();
4280
4281 // If there are more pending file chooser requests, schedule one now.
4282 if (!file_chooser_completions_.empty()) {
4283 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4284 file_chooser_completions_.front()->params));
4285 }
initial.commit09911bf2008-07-26 23:55:294286}
4287
[email protected]244ac1892011-12-02 17:04:474288void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4289 const gfx::Size& max_size) {
4290 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4291 if (!webview())
4292 return;
[email protected]61e2b3cc2012-03-02 16:13:344293 webview()->enableAutoResizeMode(min_size, max_size);
4294}
4295
4296void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
4297 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4298 if (!webview())
4299 return;
4300 webview()->disableAutoResizeMode();
4301
4302 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:474303}
4304
[email protected]2bf834f2011-11-17 20:02:214305void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244306 if (send_preferred_size_changes_)
4307 return;
[email protected]9fb325e2010-05-06 18:23:244308 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394309
[email protected]d812fd12011-05-27 23:05:074310 // Start off with an initial preferred size notification (in case
4311 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594312 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084313}
4314
[email protected]310ebd6302011-10-10 19:06:284315void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104316 const gfx::Size& disable_scrollbar_size_limit) {
4317 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4318}
4319
[email protected]310ebd6302011-10-10 19:06:284320void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314321 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504322 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514323 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374324 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:224325#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414326 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4327 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464328 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:514329 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344330 renderer_prefs.thumb_inactive_color,
4331 renderer_prefs.thumb_active_color,
4332 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554333#endif
[email protected]93623c5d2009-12-10 21:40:324334
[email protected]a13283cc2012-04-05 00:21:224335#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:104336 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:224337#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:324338 webview()->setScrollbarColors(
4339 renderer_prefs.thumb_inactive_color,
4340 renderer_prefs.thumb_active_color,
4341 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554342#endif
[email protected]644d77e2010-01-27 01:03:104343 webview()->setSelectionColors(
4344 renderer_prefs.active_selection_bg_color,
4345 renderer_prefs.active_selection_fg_color,
4346 renderer_prefs.inactive_selection_bg_color,
4347 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464348 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104349 }
[email protected]7a74e102009-09-03 00:16:564350#endif
[email protected]d299d972012-03-23 02:26:554351
[email protected]d051d9a2011-12-10 02:02:504352 // If the zoom level for this page matches the old zoom default, and this
4353 // is not a plugin, update the zoom level to match the new default.
4354 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4355 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4356 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4357 zoomLevelChanged();
4358 }
[email protected]80d96fa2009-06-10 22:34:514359}
4360
[email protected]310ebd6302011-10-10 19:06:284361void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4362 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284363 if (webview())
4364 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564365}
4366
[email protected]81375e872012-01-11 21:40:364367void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4368 const WebPluginAction& action) {
4369 if (webview())
4370 webview()->performPluginAction(action, location);
4371}
4372
[email protected]310ebd6302011-10-10 19:06:284373void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194374 const GURL& page_url) {
4375 // Prepare list to storage all savable resource links.
4376 std::vector<GURL> resources_list;
4377 std::vector<GURL> referrers_list;
4378 std::vector<GURL> frames_list;
4379 webkit_glue::SavableResourcesResult result(&resources_list,
4380 &referrers_list,
4381 &frames_list);
4382
[email protected]445e1042011-12-03 21:03:154383 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4384 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194385 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4386 webview(),
4387 page_url,
4388 &result,
[email protected]0a35efc2012-03-13 17:28:134389 content::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194390 // If something is wrong when collecting all savable resource links,
4391 // send empty list to embedder(browser) to tell it failed.
4392 referrers_list.clear();
4393 resources_list.clear();
4394 frames_list.clear();
4395 }
4396
4397 // Send result of all savable resource links to embedder.
4398 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4399 resources_list,
4400 referrers_list,
4401 frames_list));
4402}
4403
[email protected]310ebd6302011-10-10 19:06:284404void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194405 const std::vector<GURL>& links,
4406 const std::vector<FilePath>& local_paths,
4407 const FilePath& local_directory_name) {
4408
4409 // Convert std::vector of GURLs to WebVector<WebURL>
4410 WebVector<WebURL> weburl_links(links);
4411
4412 // Convert std::vector of std::strings to WebVector<WebString>
4413 WebVector<WebString> webstring_paths(local_paths.size());
4414 for (size_t i = 0; i < local_paths.size(); i++)
4415 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4416
4417 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4418 webstring_paths,
4419 webkit_glue::FilePathToWebString(
4420 local_directory_name));
4421}
4422
[email protected]310ebd6302011-10-10 19:06:284423void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:124424 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:274425 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:124426 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
4427 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
4428 before_unload_start_time,
4429 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:294430}
4431
[email protected]310ebd6302011-10-10 19:06:284432void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:314433 // Ensure that no other in-progress navigation continues.
4434 OnStop();
4435
[email protected]73eb2602012-02-09 19:50:554436 // Only run unload if we're not swapped out yet, but send the ack either way.
4437 if (!is_swapped_out_) {
4438 // Swap this RenderView out so the tab can navigate to a page rendered by a
4439 // different process. This involves running the unload handler and clearing
4440 // the page. Once WasSwappedOut is called, we also allow this process to
4441 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154442
[email protected]73eb2602012-02-09 19:50:554443 // Send an UpdateState message before we get swapped out.
4444 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154445
[email protected]73eb2602012-02-09 19:50:554446 // Synchronously run the unload handler before sending the ACK.
4447 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154448
[email protected]73eb2602012-02-09 19:50:554449 // Swap out and stop sending any IPC messages that are not ACKs.
4450 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154451
[email protected]285f4bb82012-04-17 15:57:284452 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:554453 // run a second time, thanks to a check in FrameLoader::stopLoading.
[email protected]69ddf852012-02-21 23:21:314454 // We use loadRequest instead of loadHTMLString because the former commits
4455 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]285f4bb82012-04-17 15:57:284456 // to content::kSwappedOutURL. If that happens to be to the page we had been
[email protected]69ddf852012-02-21 23:21:314457 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]73eb2602012-02-09 19:50:554458 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:284459 // beforeunload handler. For now, we just run it a second time silently.
4460 GURL swappedOutURL(content::kSwappedOutURL);
[email protected]58436a12012-03-21 17:10:264461 WebURLRequest request(swappedOutURL);
[email protected]69ddf852012-02-21 23:21:314462 webview()->mainFrame()->loadRequest(request);
[email protected]73eb2602012-02-09 19:50:554463 }
[email protected]992db4c2011-05-12 15:37:154464
4465 // Just echo back the params in the ACK.
4466 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4467}
4468
[email protected]310ebd6302011-10-10 19:06:284469void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374470 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294471 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4472 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4473 // in the onunload handler from appearing. For now, we're bypassing that and
4474 // calling the FrameLoader's CloseURL method directly. This should be
4475 // revisited to avoid having two ways to close a page. Having a single way
4476 // to close that can run onunload is also useful for fixing
4477 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274478 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294479
[email protected]992db4c2011-05-12 15:37:154480 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294481}
4482
[email protected]310ebd6302011-10-10 19:06:284483void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024484#if defined(USE_AURA)
4485 // Aura doesn't care if we switch themes.
4486#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164487 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464488 if (webview())
4489 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574490#else // defined(OS_WIN)
4491 // TODO(port): we don't support theming on non-Windows platforms yet
4492 NOTIMPLEMENTED();
4493#endif
initial.commit09911bf2008-07-26 23:55:294494}
4495
[email protected]310ebd6302011-10-10 19:06:284496void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084497 if (decrement_shared_popup_at_destruction_)
4498 shared_popup_counter_->data--;
4499 shared_popup_counter_ = new SharedRenderViewCounter(0);
4500 decrement_shared_popup_at_destruction_ = false;
4501}
4502
[email protected]310ebd6302011-10-10 19:06:284503bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4504 const WebURLError& error,
4505 bool replace) {
[email protected]15d79e12009-08-02 19:23:454506 // We only show alternate error pages in the main frame. They are
4507 // intended to assist the user when navigating, so there is not much
4508 // value in showing them for failed subframes. Ideally, we would be
4509 // able to use the TYPED transition type for this, but that flag is
4510 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454511 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454512 return false;
4513
4514 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374515 // connection failure.
[email protected]15d79e12009-08-02 19:23:454516 int ec = error.reason;
4517 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4518 ec != net::ERR_CONNECTION_FAILED &&
4519 ec != net::ERR_CONNECTION_REFUSED &&
4520 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:414521 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:454522 return false;
[email protected]82114f52012-03-20 22:53:414523 }
[email protected]15d79e12009-08-02 19:23:454524
4525 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554526 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454527 if (!error_page_url.is_valid())
4528 return false;
4529
4530 // Load an empty page first so there is an immediate response to the error,
4531 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454532 frame->loadHTMLString(std::string(),
[email protected]285f4bb82012-04-17 15:57:284533 GURL(content::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454534 error.unreachableURL,
4535 replace);
4536
4537 // Now, create a fetcher for the error page and associate it with the data
4538 // source we just created via the LoadHTMLString call. That way if another
4539 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074540 DocumentState* document_state =
4541 DocumentState::FromDataSource(frame->provisionalDataSource());
4542 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454543 new AltErrorPageResourceFetcher(
4544 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084545 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4546 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454547 return true;
4548}
4549
[email protected]310ebd6302011-10-10 19:06:284550void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4551 const WebURLError& original_error,
4552 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454553 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094554 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554555 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094556 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454557}
4558
[email protected]310ebd6302011-10-10 19:06:284559void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004560 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474561 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004562}
4563
[email protected]310ebd6302011-10-10 19:06:284564void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094565 const gfx::Rect& resizer_rect,
4566 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104567 if (webview()) {
[email protected]7ddea9802012-02-22 23:08:054568 // This setting has no effect if fixed layout is not enabled.
[email protected]43d9d782012-03-01 15:40:094569 if (webkit_preferences_.default_device_scale_factor)
[email protected]7ddea9802012-02-22 23:08:054570 webview()->settings()->setLayoutFallbackWidth(
[email protected]43d9d782012-03-01 15:40:094571 new_size.width() / webkit_preferences_.default_device_scale_factor);
[email protected]a72a1fa2010-05-03 22:18:474572 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104573 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204574 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314575 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104576 }
[email protected]dd6afca2011-08-13 03:44:314577 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104578 }
4579
[email protected]ee41e7d22011-10-14 19:34:094580 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004581}
[email protected]0aa477bd2009-03-23 22:21:434582
[email protected]29ed96a2012-02-04 18:12:164583void RenderViewImpl::WillInitiatePaint() {
4584 // Notify the pepper plugins that we're about to paint.
4585 pepper_delegate_.ViewWillInitiatePaint();
4586}
4587
[email protected]310ebd6302011-10-10 19:06:284588void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164589 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014590 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284591}
4592
[email protected]310ebd6302011-10-10 19:06:284593void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284594 // Notify any pepper plugins that we painted. This will call into the plugin,
4595 // and we it may ask to close itself as a result. This will, in turn, modify
4596 // our set, possibly invalidating the iterator. So we iterate on a copy that
4597 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014598 pepper_delegate_.ViewFlushedPaint();
4599
[email protected]5b1dec8c2012-02-07 04:35:384600 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4601 // See crbug.com/112921.
4602 if (!webview())
4603 return;
4604
[email protected]00c39612010-03-06 02:53:284605 WebFrame* main_frame = webview()->mainFrame();
4606
4607 // If we have a provisional frame we are between the start and commit stages
4608 // of loading and we don't want to save stats.
4609 if (!main_frame->provisionalDataSource()) {
4610 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074611 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284612
[email protected]05c8e502010-08-15 15:13:524613 // TODO(jar): The following code should all be inside a method, probably in
4614 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284615 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074616 if (document_state->first_paint_time().is_null()) {
4617 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284618 }
[email protected]007733c2011-11-17 00:34:074619 if (document_state->first_paint_after_load_time().is_null() &&
4620 !document_state->finish_load_time().is_null()) {
4621 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284622 }
4623 }
4624}
4625
[email protected]310ebd6302011-10-10 19:06:284626void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084627 RenderWidget::OnSwapBuffersPosted();
4628}
4629
[email protected]310ebd6302011-10-10 19:06:284630void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244631 RenderWidget::OnSwapBuffersComplete();
4632}
4633
[email protected]310ebd6302011-10-10 19:06:284634void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244635 RenderWidget::OnSwapBuffersAborted();
4636}
4637
[email protected]310ebd6302011-10-10 19:06:284638webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154639 const gfx::Rect& paint_bounds,
4640 TransportDIB** dib,
4641 gfx::Rect* location,
4642 gfx::Rect* clip) {
4643 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4644 paint_bounds, dib, location, clip);
4645}
4646
[email protected]310ebd6302011-10-10 19:06:284647gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074648 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434649 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524650}
4651
[email protected]310ebd6302011-10-10 19:06:284652void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164653 if (webview())
[email protected]26aa0482009-09-30 16:55:274654 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164655}
4656
[email protected]310ebd6302011-10-10 19:06:284657void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144658 if (webview())
[email protected]b4bb2502009-10-01 22:35:274659 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144660
4661 SetBackground(background);
4662}
4663
[email protected]310ebd6302011-10-10 19:06:284664void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344665 if (webview())
[email protected]b4bb2502009-10-01 22:35:274666 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264667
4668#if defined(OS_MACOSX)
4669 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4670 for (plugin_it = plugin_delegates_.begin();
4671 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4672 (*plugin_it)->SetWindowFocus(active);
4673 }
4674#endif
[email protected]8c66c5a2009-07-22 17:26:344675}
4676
[email protected]7a17bac02012-03-07 21:58:124677void RenderViewImpl::OnSetNavigationStartTime(
4678 const base::TimeTicks& browser_navigation_start) {
4679 if (!webview())
4680 return;
4681
4682 // Only the initial navigation can be a cross-renderer navigation. If we've
4683 // already navigated away from that page, we can ignore this message.
4684 if (page_id_ != -1)
4685 return;
4686
4687 // browser_navigation_start is likely before this process existed, so we can't
4688 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
4689 // ensure we don't report a bogus value in the future.
4690 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
4691 browser_navigation_start);
4692 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
4693 (navigation_start - base::TimeTicks()).InSecondsF());
4694}
4695
[email protected]6ce7abc52010-02-02 18:40:144696#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284697void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144698 // Inform plugins that their container has changed visibility.
4699 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4700 for (plugin_it = plugin_delegates_.begin();
4701 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4702 (*plugin_it)->SetContainerVisibility(visible);
4703 }
4704}
[email protected]1e6e3c992010-02-08 15:52:134705
[email protected]310ebd6302011-10-10 19:06:284706void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4707 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134708 // Inform plugins that their window's frame has changed.
4709 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4710 for (plugin_it = plugin_delegates_.begin();
4711 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4712 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4713 }
4714}
[email protected]935d63d2010-10-15 23:31:554715
[email protected]310ebd6302011-10-10 19:06:284716void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4717 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134718 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554719 // applies to it or not, so inform all the delegates.
4720 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4721 for (plugin_it = plugin_delegates_.begin();
4722 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134723 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554724 }
4725}
[email protected]6ce7abc52010-02-02 18:40:144726#endif // OS_MACOSX
4727
[email protected]310ebd6302011-10-10 19:06:284728void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484729 const EditCommands& edit_commands) {
4730 edit_commands_ = edit_commands;
4731}
4732
[email protected]310ebd6302011-10-10 19:06:284733void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594734 // We need to grab a pointer to the doomed WebView before we destroy it.
4735 WebView* doomed = webview();
4736 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494737 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594738}
4739
[email protected]310ebd6302011-10-10 19:06:284740void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484741 edit_commands_.clear();
4742}
4743
[email protected]310ebd6302011-10-10 19:06:284744bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:114745 pepper_delegate_.WillHandleMouseEvent();
4746
4747 // If the mouse is locked, only the current owner of the mouse lock can
4748 // process mouse events.
4749 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374750}
4751
[email protected]2b942c332012-04-25 16:26:264752void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514753 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064754}
4755
[email protected]310ebd6302011-10-10 19:06:284756void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244757 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4758}
4759
[email protected]310ebd6302011-10-10 19:06:284760void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434761 RenderWidget::OnWasHidden();
4762
[email protected]a6939ca42011-02-18 17:58:074763 if (webview()) {
4764 webview()->settings()->setMinimumTimerInterval(
4765 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444766 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074767 }
4768
[email protected]204f1df2012-01-04 20:21:134769 // Inform PPAPI plugins that their page is no longer visible.
4770 pepper_delegate_.PageVisibilityChanged(false);
4771
[email protected]a6939ca42011-02-18 17:58:074772#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134773 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434774 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4775 for (plugin_it = plugin_delegates_.begin();
4776 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4777 (*plugin_it)->SetContainerVisibility(false);
4778 }
[email protected]a6939ca42011-02-18 17:58:074779#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434780}
4781
[email protected]310ebd6302011-10-10 19:06:284782void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434783 RenderWidget::OnWasRestored(needs_repainting);
4784
[email protected]a6939ca42011-02-18 17:58:074785 if (webview()) {
4786 webview()->settings()->setMinimumTimerInterval(
4787 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444788 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074789 }
4790
[email protected]204f1df2012-01-04 20:21:134791 // Inform PPAPI plugins that their page is visible.
4792 pepper_delegate_.PageVisibilityChanged(true);
4793
[email protected]a6939ca42011-02-18 17:58:074794#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134795 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434796 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4797 for (plugin_it = plugin_delegates_.begin();
4798 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4799 (*plugin_it)->SetContainerVisibility(true);
4800 }
[email protected]784ea1ab2010-09-18 00:02:344801#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074802}
[email protected]1e6e3c992010-02-08 15:52:134803
[email protected]310ebd6302011-10-10 19:06:284804bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384805 if (WebWidgetHandlesCompositorScheduling())
4806 return false;
4807
[email protected]05a980d7a2012-02-07 22:16:424808 if (queried_for_swapbuffers_complete_callback_)
4809 return context_has_swapbuffers_complete_callback_;
4810
4811 queried_for_swapbuffers_complete_callback_ = true;
4812
[email protected]65225772011-05-12 21:10:244813 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:424814 if (context && context->makeContextCurrent()) {
4815 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4816 context_has_swapbuffers_complete_callback_ =
4817 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
4818 != std::string::npos;
4819 }
4820
4821 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:244822}
4823
[email protected]310ebd6302011-10-10 19:06:284824void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134825 RenderWidget::OnSetFocus(enable);
4826
[email protected]7d3c02c2010-05-05 23:10:314827 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074828 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134829 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4830 for (plugin_it = plugin_delegates_.begin();
4831 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344832#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314833 // RenderWidget's call to setFocus can cause the underlying webview's
4834 // activation state to change just like a call to setIsActive.
4835 if (enable)
4836 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344837#endif
[email protected]7d3c02c2010-05-05 23:10:314838 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134839 }
[email protected]589621b2010-09-23 22:01:074840
4841 // Notify all Pepper plugins.
4842 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134843 }
4844}
[email protected]941e4552010-02-01 21:23:434845
[email protected]310ebd6302011-10-10 19:06:284846void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004847 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504848 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574849}
4850
[email protected]73bf95812011-10-12 11:38:324851void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004852 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324853}
4854
[email protected]3f783362011-10-21 22:40:504855void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4856 UpdateSelectionBounds();
4857}
4858
[email protected]b25b3ee2012-01-13 05:19:544859bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4860 if (!pepper_delegate_.IsPluginFocused())
4861 return false;
4862 *rect = pepper_delegate_.GetCaretBounds();
4863 return true;
4864}
4865
[email protected]73bf95812011-10-12 11:38:324866void RenderViewImpl::PpapiPluginCancelComposition() {
4867 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4868 ui::Range range(ui::Range::InvalidRange());
4869 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4870}
4871
[email protected]3c8c74c2012-03-15 07:34:524872void RenderViewImpl::PpapiPluginSelectionChanged() {
4873 SyncSelectionIfRequired();
4874}
4875
[email protected]310ebd6302011-10-10 19:06:284876void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574877 const string16& text,
4878 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4879 int selection_start,
4880 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324881 if (pepper_delegate_.IsPluginFocused()) {
4882 // When a PPAPI plugin has focus, we bypass WebKit.
4883 pepper_delegate_.OnImeSetComposition(text,
4884 underlines,
4885 selection_start,
4886 selection_end);
4887 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234888#if defined(OS_WIN)
4889 // When a plug-in has focus, we create platform-specific IME data used by
4890 // our IME emulator and send it directly to the focused plug-in, i.e. we
4891 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4892 // instance ID is the same one as the specified ID.)
4893 if (focused_plugin_id_ >= 0) {
4894 std::vector<int> clauses;
4895 std::vector<int> target;
4896 for (size_t i = 0; i < underlines.size(); ++i) {
4897 clauses.push_back(underlines[i].startOffset);
4898 clauses.push_back(underlines[i].endOffset);
4899 if (underlines[i].thick) {
4900 target.clear();
4901 target.push_back(underlines[i].startOffset);
4902 target.push_back(underlines[i].endOffset);
4903 }
4904 }
4905 std::set<WebPluginDelegateProxy*>::iterator it;
4906 for (it = plugin_delegates_.begin();
4907 it != plugin_delegates_.end(); ++it) {
4908 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4909 focused_plugin_id_);
4910 }
4911 return;
4912 }
4913#endif
[email protected]56ea1a62011-05-30 07:05:574914 RenderWidget::OnImeSetComposition(text,
4915 underlines,
4916 selection_start,
4917 selection_end);
4918 }
4919}
4920
[email protected]4de6d1692011-10-12 08:45:444921void RenderViewImpl::OnImeConfirmComposition(
4922 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574923 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324924 // When a PPAPI plugin has focus, we bypass WebKit.
4925 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574926 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234927#if defined(OS_WIN)
4928 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4929 // plug-ins. When we send IME text directly to plug-ins, we should not send
4930 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444931 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234932 if (focused_plugin_id_ >= 0) {
4933 std::set<WebPluginDelegateProxy*>::iterator it;
4934 for (it = plugin_delegates_.begin();
4935 it != plugin_delegates_.end(); ++it) {
4936 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4937 }
4938 return;
4939 }
4940#endif
[email protected]ebd28ac2011-10-13 18:49:054941 if (replacement_range.IsValid() && webview()) {
4942 // Select the text in |replacement_range|, it will then be replaced by
4943 // text added by the call to RenderWidget::OnImeConfirmComposition().
4944 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164945 WebRange webrange = WebRange::fromDocumentRange(
4946 frame, replacement_range.start(), replacement_range.length());
4947 if (!webrange.isNull())
4948 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054949 }
4950 }
[email protected]4de6d1692011-10-12 08:45:444951 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574952 }
4953}
4954
[email protected]310ebd6302011-10-10 19:06:284955ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324956 return pepper_delegate_.IsPluginFocused() ?
4957 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4958}
4959
[email protected]3f783362011-10-21 22:40:504960void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4961 if (pepper_delegate_.IsPluginFocused()) {
4962 // TODO(kinaba) http://crbug.com/101101
4963 // Current Pepper IME API does not handle selection bounds. So we simply
4964 // use the caret position as an empty range for now. It will be updated
4965 // after Pepper API equips features related to surrounding text retrieval.
4966 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4967 *start = caret;
4968 *end = caret;
4969 return;
4970 }
4971 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454972}
4973
[email protected]310ebd6302011-10-10 19:06:284974bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324975 return pepper_delegate_.IsPluginFocused() ?
4976 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574977}
4978
[email protected]e6ae0f6c2011-10-04 10:39:234979#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284980void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234981 if (focused)
4982 focused_plugin_id_ = plugin_id;
4983 else
4984 focused_plugin_id_ = -1;
4985}
4986#endif
4987
[email protected]43f28f832010-02-03 02:28:484988#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284989void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:414990 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:134991}
4992
[email protected]310ebd6302011-10-10 19:06:284993void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134994 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554995 // This message can be sent during event-handling, and needs to be delivered
4996 // within that context.
4997 msg->set_unblock(true);
4998 Send(msg);
4999}
5000
[email protected]310ebd6302011-10-10 19:06:285001gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235002 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:515003 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:485004 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235005 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115006 if (window) {
5007 fake_plugin_window_handles_.insert(window);
5008 }
[email protected]43f28f832010-02-03 02:28:485009 return window;
5010}
5011
[email protected]310ebd6302011-10-10 19:06:285012void RenderViewImpl::DestroyFakePluginWindowHandle(
5013 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115014 if (window && fake_plugin_window_handles_.find(window) !=
5015 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485016 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115017 fake_plugin_window_handles_.erase(window);
5018 }
[email protected]43f28f832010-02-03 02:28:485019}
5020
[email protected]310ebd6302011-10-10 19:06:285021void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
5022 gfx::PluginWindowHandle window,
5023 int32 width,
5024 int32 height,
5025 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:335026 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485027 routing_id(), window, width, height, io_surface_identifier));
5028}
5029
[email protected]310ebd6302011-10-10 19:06:285030void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335031 gfx::PluginWindowHandle window,
5032 int32 width,
5033 int32 height,
5034 TransportDIB::Handle transport_dib) {
5035 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075036 routing_id(), window, width, height, transport_dib));
5037}
5038
[email protected]310ebd6302011-10-10 19:06:285039TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335040 size_t size) {
[email protected]1aef98132010-02-23 18:00:075041 TransportDIB::Handle dib_handle;
5042 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385043 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075044 return dib_handle;
5045 // Return an invalid handle if Send() fails.
5046 return TransportDIB::DefaultHandleValue();
5047}
5048
[email protected]310ebd6302011-10-10 19:06:285049void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
5050 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075051 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5052}
5053
[email protected]310ebd6302011-10-10 19:06:285054void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325055 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:145056 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325057 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:485058}
[email protected]82114f52012-03-20 22:53:415059#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:285060
[email protected]310ebd6302011-10-10 19:06:285061bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:235062 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:475063 WebFileChooserCompletion* completion) {
5064 static const size_t kMaximumPendingFileChooseRequests = 4;
5065 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5066 // This sanity check prevents too many file choose requests from getting
5067 // queued which could DoS the user. Getting these is most likely a
5068 // programming error (there are many ways to DoS the user so it's not
5069 // considered a "real" security check), either in JS requesting many file
5070 // choosers to pop up, or in a plugin.
5071 //
5072 // TODO(brettw) we might possibly want to require a user gesture to open
5073 // a file picker, which will address this issue in a better way.
5074 return false;
5075 }
5076
5077 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5078 new PendingFileChooser(params, completion)));
5079 if (file_chooser_completions_.size() == 1) {
5080 // Actually show the browse dialog when this is the first request.
5081 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5082 }
5083 return true;
5084}
5085
[email protected]310ebd6302011-10-10 19:06:285086WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515087 if (!geolocation_dispatcher_)
5088 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5089 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255090}
[email protected]61c9f032010-03-31 23:04:195091
[email protected]310ebd6302011-10-10 19:06:285092WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:115093 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:225094#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:025095 if (!input_tag_speech_dispatcher_)
5096 input_tag_speech_dispatcher_ =
5097 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:225098#endif
[email protected]c52b2892012-03-07 11:01:025099 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:115100}
5101
[email protected]310ebd6302011-10-10 19:06:285102WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515103 if (!device_orientation_dispatcher_)
5104 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5105 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535106}
5107
[email protected]310ebd6302011-10-10 19:06:285108void RenderViewImpl::zoomLimitsChanged(double minimum_level,
5109 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:255110 // For now, don't remember plugin zoom values. We don't want to mix them with
5111 // normal web content (i.e. a fixed layout plugin would usually want them
5112 // different).
5113 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5114
[email protected]b75b8292010-10-01 07:28:255115 int minimum_percent = static_cast<int>(
5116 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5117 int maximum_percent = static_cast<int>(
5118 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255119
5120 Send(new ViewHostMsg_UpdateZoomLimits(
5121 routing_id_, minimum_percent, maximum_percent, remember));
5122}
5123
[email protected]310ebd6302011-10-10 19:06:285124void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:255125 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:085126 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:265127
5128 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
5129
[email protected]b75b8292010-10-01 07:28:255130 // Tell the browser which url got zoomed so it can update the menu and the
5131 // saved values if necessary
5132 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:085133 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:415134 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:255135}
5136
[email protected]310ebd6302011-10-10 19:06:285137void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
5138 const WebString& base_url,
5139 const WebString& url,
5140 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:485141 GURL base(base_url);
5142 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
5143 if (base.GetOrigin() != absolute_url.GetOrigin()) {
5144 return;
5145 }
[email protected]f1a29a02011-10-06 23:08:445146 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
5147 UTF16ToUTF8(scheme),
5148 absolute_url,
5149 title));
[email protected]a6d36cc2011-02-23 00:39:485150}
5151
[email protected]310ebd6302011-10-10 19:06:285152WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:445153 WebKit::WebPageVisibilityState current_state = is_hidden() ?
5154 WebKit::WebPageVisibilityStateHidden :
5155 WebKit::WebPageVisibilityStateVisible;
5156 WebKit::WebPageVisibilityState override_state = current_state;
5157 if (content::GetContentClient()->renderer()->
5158 ShouldOverridePageVisibilityState(this,
5159 &override_state))
5160 return override_state;
5161 return current_state;
[email protected]94dec932011-05-26 20:04:215162}
5163
[email protected]273558fb2012-01-12 15:03:515164WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:515165 EnsureMediaStreamImpl();
5166 return media_stream_impl_;
5167}
5168
[email protected]310ebd6302011-10-10 19:06:285169bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195170 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455171 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195172 if (frame->parent() != NULL)
5173 return false;
5174
[email protected]f0a3d0b2010-08-06 22:51:535175 // Navigations initiated within Webkit are not sent out to the external host
5176 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275177 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:135178 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535179 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:135180 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:335181 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:535182 return false;
5183
[email protected]2fc22d12010-12-02 23:08:165184 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325185 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015186 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165187 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015188 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325189 // The opener relationship between the new window and the parent allows the
5190 // new window to script the parent and vice versa. This is not allowed if
5191 // the origins of the two domains are different. This can be treated as a
5192 // top level navigation and routed back to the host.
5193 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275194 if (!opener) {
[email protected]86965362011-04-21 18:42:515195 return true;
[email protected]d19ea342011-04-20 20:31:135196 } else {
[email protected]b6cb3a842011-06-24 18:28:415197 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:325198 return true;
5199 }
5200 }
[email protected]61c9f032010-03-31 23:04:195201 return false;
5202}
[email protected]2b06a992010-08-21 05:48:225203
[email protected]310ebd6302011-10-10 19:06:285204void RenderViewImpl::OnAsyncFileOpened(
5205 base::PlatformFileError error_code,
5206 IPC::PlatformFileForTransit file_for_transit,
5207 int message_id) {
[email protected]27a9ef32010-09-10 04:06:245208 pepper_delegate_.OnAsyncFileOpened(
5209 error_code,
5210 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5211 message_id);
5212}
[email protected]caf706f2010-10-26 17:54:085213
[email protected]310ebd6302011-10-10 19:06:285214void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:475215 int request_id,
5216 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:435217 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:475218 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
5219 broker_process_handle,
5220 handle);
[email protected]eb415bf0e2011-04-14 02:45:425221}
5222
[email protected]caf706f2010-10-26 17:54:085223#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285224void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155225 if (external_popup_menu_ == NULL) {
5226 // Crash reports from the field indicate that we can be notified with a
5227 // NULL external popup menu (we probably get notified twice).
5228 // If you hit this please file a bug against jcivelli and include the page
5229 // and steps to repro.
5230 NOTREACHED();
5231 return;
5232 }
[email protected]caf706f2010-10-26 17:54:085233 external_popup_menu_->DidSelectItem(selected_index);
5234 external_popup_menu_.reset();
5235}
5236#endif
[email protected]bb461532010-11-26 21:50:235237
[email protected]310ebd6302011-10-10 19:06:285238void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515239 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085240 if (custom_context.is_pepper_menu)
5241 pepper_delegate_.OnContextMenuClosed(custom_context);
5242 else
5243 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105244}
[email protected]5a7b15a2011-08-22 22:48:185245
[email protected]310ebd6302011-10-10 19:06:285246void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185247 if (!webview())
5248 return;
5249 WebFrame* main_frame = webview()->mainFrame();
5250 if (!main_frame)
5251 return;
5252 main_frame->enableViewSourceMode(true);
5253}
[email protected]67bfb83f2011-09-22 03:36:375254
[email protected]310ebd6302011-10-10 19:06:285255bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085256 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405257}
[email protected]7f3c7af2011-10-20 22:52:515258
[email protected]64d0e192011-12-09 14:44:205259void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:515260 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:185261#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:205262 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:185263#endif
[email protected]7f3c7af2011-10-20 22:52:515264}