blob: 681d3e971f586cfb59c50a3afed301d788ea4387 [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]778574e2011-03-21 22:03:5041#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2142#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0443#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4844#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2945#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5146#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2347#include "content/public/common/file_chooser_params.h"
[email protected]fb11b6a42012-03-14 07:25:1248#include "content/public/common/selected_file_info.h"
[email protected]a1d29162011-10-14 17:14:0349#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3450#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0751#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3252#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4453#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3654#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1955#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0256#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1557#include "content/renderer/dom_automation_controller.h"
[email protected]55722152011-03-22 01:33:5358#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1959#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4060#include "content/renderer/gpu/compositor_thread.h"
[email protected]1784b2f2011-11-24 10:53:4861#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0262#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4263#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0264#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0865#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3766#include "content/renderer/media/audio_renderer_impl.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"
85#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]86a7d3c2011-09-12 16:45:3286#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1987#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:1388#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:0189#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3590#include "content/renderer/webplugin_delegate_proxy.h"
91#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4992#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4193#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:5094#include "media/base/message_loop_factory.h"
[email protected]e1d69d762011-12-13 05:12:1895#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2996#include "net/base/escape.h"
97#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0498#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5799#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:37100#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:37101#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:37102#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37103#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
104#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37105#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37110#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37111#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57112#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58113#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44114#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58115#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14116#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37117#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19118#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37119#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36120#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37121#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37124#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37125#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17128#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37129#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37130#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40131#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51132#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08133#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]273558fb2012-01-12 15:03:51139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08141#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]e6e90dc2011-12-03 00:01:37144#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26150#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47151#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38152#include "ui/gfx/native_widget_types.h"
153#include "ui/gfx/point.h"
154#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55155#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04156#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]9c4bf232011-12-15 02:25:08157#include "webkit/forms/form_data.h"
158#include "webkit/forms/form_field.h"
159#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43160#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19161#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24162#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29163#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07164#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29165#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03166#include "webkit/glue/weburlloader_impl.h"
[email protected]b9fd01ba2012-02-28 01:50:40167#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51168#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16169#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50170#include "webkit/plugins/npapi/plugin_list.h"
171#include "webkit/plugins/npapi/webplugin_delegate.h"
172#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
173#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52174#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29175
[email protected]6c8afae52009-01-22 02:24:57176#if defined(OS_WIN)
177// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57178// * theming
[email protected]08397d52011-02-05 01:53:38179#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03180#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37181#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51182#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33183#elif defined(OS_MACOSX)
184#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57185#endif
186
[email protected]9892b472010-09-16 00:23:42187using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08188using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21189using WebKit::WebApplicationCacheHost;
190using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26191using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41192using WebKit::WebColor;
193using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59194using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44195using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51196using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55197using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28198using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00199using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58200using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25201using WebKit::WebDragOperation;
202using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51203using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51204using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08205using WebKit::WebExternalPopupMenu;
206using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47207using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22208using WebKit::WebFileSystem;
209using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49210using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59211using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48212using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45213using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51214using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17215using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13216using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41217using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50218using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15219using WebKit::WebIntentRequest;
220using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17221using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28222using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17223using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28224using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28225using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51226using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19227using WebKit::WebPageSerializer;
228using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17229using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36230using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40231using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49232using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09233using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52234using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59235using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51236using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52237using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15238using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40239using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35240using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29241using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17242using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59243using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42244using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02245using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34246using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40247using WebKit::WebStorageQuotaCallbacks;
248using WebKit::WebStorageQuotaError;
249using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28250using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51251using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52252using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24253using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28254using WebKit::WebURL;
255using WebKit::WebURLError;
256using WebKit::WebURLRequest;
257using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28258using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03259using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28260using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26261using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26262using appcache::WebApplicationCacheHostImpl;
263using base::Time;
264using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07265using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32266using content::NavigationState;
[email protected]380244092011-10-07 17:26:27267using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44268using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36269using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15270using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19271using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08272using webkit::forms::FormField;
273using webkit::forms::PasswordForm;
274using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26275using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23276using webkit_glue::ResourceFetcher;
[email protected]b9fd01ba2012-02-28 01:50:40277using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33278
initial.commit09911bf2008-07-26 23:55:29279//-----------------------------------------------------------------------------
280
[email protected]310ebd6302011-10-10 19:06:28281typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49282static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02283
[email protected]882daa92009-11-05 16:31:31284// Time, in seconds, we delay before sending content state changes (such as form
285// state and scroll position) to the browser. We delay sending changes to avoid
286// spamming the browser.
287// To avoid having tab/session restore require sending a message to get the
288// current content state during tab closing we use a shorter timeout for the
289// foreground renderer. This means there is a small window of time from which
290// content state is modified and not sent to session restore, but this is
291// better than having to wake up all renderers during shutdown.
292static const int kDelaySecondsForContentStateSyncHidden = 5;
293static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29294
[email protected]e99ef6f2011-10-16 01:13:00295static const size_t kExtraCharsBeforeAndAfterSelection = 100;
296
[email protected]0aa55312008-10-17 21:53:08297// The maximum number of popups that can be spawned from one page.
298static const int kMaximumNumberOfUnacknowledgedPopups = 25;
299
[email protected]c514d6372011-08-16 22:54:44300static const float kScalingIncrement = 0.1f;
301
[email protected]47578fa02011-11-02 19:34:41302static const float kScalingIncrementForGesture = 0.01f;
303
[email protected]726985e22009-06-18 21:09:28304static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
305 WebVector<WebURL> urls;
306 ds->redirectChain(urls);
307 result->reserve(urls.size());
308 for (size_t i = 0; i < urls.size(); ++i)
309 result->push_back(urls[i]);
310}
311
[email protected]007733c2011-11-17 00:34:07312// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44313// the AltErrorPageResourceFetcher is reset.
314static void StopAltErrorPageFetcher(WebDataSource* data_source) {
315 if (data_source) {
[email protected]007733c2011-11-17 00:34:07316 DocumentState* document_state = DocumentState::FromDataSource(data_source);
317 if (document_state)
318 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44319 }
320}
321
[email protected]007733c2011-11-17 00:34:07322static bool IsReload(const ViewMsg_Navigate_Params& params) {
323 return
324 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
325 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
326}
327
[email protected]b9fd01ba2012-02-28 01:50:40328static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]445e1042011-12-03 21:03:15329 const WebURLRequest& request) {
330 return request.extraData() ?
331 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
332 WebKit::WebReferrerPolicyDefault;
333}
334
[email protected]b9fd01ba2012-02-28 01:50:40335static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
336 const WebURLResponse& response) {
337 return static_cast<WebURLResponseExtraDataImpl*>(
338 response.extraData());
339}
340
[email protected]2149cc622012-02-14 01:12:12341NOINLINE static void CrashIntentionally() {
342 // NOTE(shess): Crash directly rather than using NOTREACHED() so
343 // that the signature is easier to triage in crash reports.
344 volatile int* zero = NULL;
345 *zero = 0;
346}
347
[email protected]8bf1048012012-02-08 01:22:18348static void MaybeHandleDebugURL(const GURL& url) {
349 if (!url.SchemeIs(chrome::kChromeUIScheme))
350 return;
351 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12352 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18353 } else if (url == GURL(chrome::kChromeUIKillURL)) {
354 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
355 } else if (url == GURL(chrome::kChromeUIHangURL)) {
356 for (;;) {
357 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
358 }
359 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
360 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
361 }
362}
363
initial.commit09911bf2008-07-26 23:55:29364///////////////////////////////////////////////////////////////////////////////
365
[email protected]310ebd6302011-10-10 19:06:28366struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23367 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47368 WebFileChooserCompletion* c)
369 : params(p),
370 completion(c) {
371 }
[email protected]8caadeb2011-11-22 02:45:23372 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47373 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
374};
375
[email protected]217690d2012-01-27 07:33:11376namespace {
377
378class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
379 public:
380 WebWidgetLockTarget (WebKit::WebWidget* webwidget)
381 : webwidget_(webwidget) {}
382
383 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
384 if (succeeded)
385 webwidget_->didAcquirePointerLock();
386 else
387 webwidget_->didNotAcquirePointerLock();
388 }
389
390 virtual void OnMouseLockLost() OVERRIDE {
391 webwidget_->didLosePointerLock();
392 }
393
394 virtual bool HandleMouseLockedInputEvent(
395 const WebKit::WebMouseEvent &event) OVERRIDE {
396 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
397 return false;
398 }
399
400 private:
401 WebKit::WebWidget* webwidget_;
402};
403
[email protected]86cd9472012-02-03 19:51:05404int64 ExtractPostId(const WebHistoryItem& item) {
405 if (item.isNull())
406 return -1;
407
408 if (item.httpBody().isNull())
409 return -1;
410
411 return item.httpBody().identifier();
412}
413
[email protected]217690d2012-01-27 07:33:11414} // namespace
415
[email protected]daf82f82011-10-31 22:35:31416RenderViewImpl::RenderViewImpl(
417 gfx::NativeViewId parent_hwnd,
418 int32 opener_id,
419 const content::RendererPreferences& renderer_prefs,
420 const WebPreferences& webkit_prefs,
421 SharedRenderViewCounter* counter,
422 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56423 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31424 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46425 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41426 int32 next_page_id,
427 const WebKit::WebScreenInfo& screen_info)
428 : RenderWidget(WebKit::WebPopupTypeNone, screen_info),
[email protected]676126f72011-01-15 00:03:51429 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02430 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09431 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02432 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24433 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21434 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02435 opened_by_user_gesture_(true),
436 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24437 page_id_(-1),
438 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46439 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00440 history_list_offset_(-1),
441 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02442 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55443 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31444 cached_is_main_frame_pinned_to_left_(false),
445 cached_is_main_frame_pinned_to_right_(false),
446 cached_has_main_frame_horizontal_scrollbar_(false),
447 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]05a980d7a2012-02-07 22:16:42448 context_has_swapbuffers_complete_callback_(false),
449 queried_for_swapbuffers_complete_callback_(false),
[email protected]d0fb8a72012-03-10 18:54:52450 context_is_web_graphics_context_3d_command_buffer_impl_(false),
[email protected]3354d3e2010-06-10 19:53:02451 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51452 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02453 input_tag_speech_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51454 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51455 media_stream_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18456 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41457 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32458 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11459 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08460 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18461 handling_select_range_(false),
462#if defined(OS_WIN)
463 focused_plugin_id_(-1),
464#endif
465 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51466 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56467 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51468 if (opener_id != MSG_ROUTING_NONE)
469 opener_id_ = opener_id;
470
[email protected]74ce1ad2011-12-16 21:51:46471 // Ensure we start with a valid next_page_id_ from the browser.
472 DCHECK_GE(next_page_id_, 0);
473
[email protected]21b3a6ae2011-11-30 00:45:29474#if defined(ENABLE_NOTIFICATIONS)
475 notification_provider_ = new NotificationProvider(this);
476#else
477 notification_provider_ = NULL;
478#endif
479
[email protected]11fee2332011-03-29 20:36:35480 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11481 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35482
[email protected]676126f72011-01-15 00:03:51483 if (counter) {
484 shared_popup_counter_ = counter;
485 shared_popup_counter_->data++;
486 decrement_shared_popup_at_destruction_ = true;
487 } else {
488 shared_popup_counter_ = new SharedRenderViewCounter(0);
489 decrement_shared_popup_at_destruction_ = false;
490 }
491
[email protected]380244092011-10-07 17:26:27492 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51493 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47494 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51495 AddRef();
496
497 // If this is a popup, we must wait for the CreatingNew_ACK message before
498 // completing initialization. Otherwise, we can finish it now.
499 if (opener_id == MSG_ROUTING_NONE) {
500 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55501 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51502 }
503
[email protected]34c61bd52011-05-02 19:38:33504 g_view_map.Get().insert(std::make_pair(webview(), this));
505 webkit_preferences_.Apply(webview());
506 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35507 if (!frame_name.empty())
508 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33509 webview()->settings()->setMinimumTimerInterval(
510 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
511 webkit_glue::kForegroundTabTimerInterval);
512
513 OnSetRendererPrefs(renderer_prefs);
514
[email protected]676126f72011-01-15 00:03:51515 host_window_ = parent_hwnd;
516
[email protected]a026daa2011-04-20 15:49:51517#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51518 if (!p2p_socket_dispatcher_)
519 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51520#endif
[email protected]cae8c8492011-03-03 11:12:18521
[email protected]5b87e782012-02-09 18:19:32522#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02523 if (!media_stream_dispatcher_)
524 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32525#endif
[email protected]735873d2012-01-25 23:31:02526
[email protected]8f6a3b852011-07-19 16:48:56527 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32528#if defined(OS_MACOSX)
529 new TextInputClientObserver(this);
530#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56531
[email protected]217690d2012-01-27 07:33:11532 // The next group of objects all implement RenderViewObserver, so are deleted
533 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41534 devtools_agent_ = new DevToolsAgent(this);
[email protected]063afcb2011-09-29 07:54:32535 renderer_accessibility_ = new RendererAccessibility(this);
[email protected]217690d2012-01-27 07:33:11536 mouse_lock_dispatcher_ = new MouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40537 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32538
[email protected]1784b2f2011-11-24 10:53:48539 new IdleUserDetector(this);
540
[email protected]766a7082012-02-03 23:39:15541 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
542 if (command_line.HasSwitch(switches::kDomAutomationController))
543 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
544
[email protected]7ddea9802012-02-22 23:08:05545 bool enable_fixed_layout =
546 command_line.HasSwitch(switches::kEnableFixedLayout);
547 webview()->enableFixedLayoutMode(enable_fixed_layout);
548 if (enable_fixed_layout)
549 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
[email protected]7ddea9802012-02-22 23:08:05550
[email protected]e48869a2011-04-01 19:56:03551 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29552}
553
[email protected]310ebd6302011-10-10 19:06:28554RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03555 history_page_ids_.clear();
556
[email protected]0aa55312008-10-17 21:53:08557 if (decrement_shared_popup_at_destruction_)
558 shared_popup_counter_->data--;
559
[email protected]a1128322009-10-06 18:38:46560 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47561 while (!file_chooser_completions_.empty()) {
562 if (file_chooser_completions_.front()->completion) {
563 file_chooser_completions_.front()->completion->didChooseFile(
564 WebVector<WebString>());
565 }
566 file_chooser_completions_.pop_front();
567 }
[email protected]a1128322009-10-06 18:38:46568
[email protected]83dde542009-09-11 20:59:55569#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11570 // Destroy all fake plugin window handles on the browser side.
571 while (!fake_plugin_window_handles_.empty()) {
572 // Make sure no NULL plugin window handles were inserted into this list.
573 DCHECK(*fake_plugin_window_handles_.begin());
574 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
575 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
576 }
[email protected]83dde542009-09-11 20:59:55577#endif
[email protected]98324892009-09-09 21:16:05578
[email protected]60c42a8c72009-10-09 04:08:59579#ifndef NDEBUG
580 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49581 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59582 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
583 DCHECK_NE(this, it->second) << "Failed to call Close?";
584#endif
[email protected]676126f72011-01-15 00:03:51585
[email protected]273558fb2012-01-12 15:03:51586 // MediaStreamImpl holds weak references to RenderViewObserver objects,
587 // ensure it's deleted before the observers.
588 media_stream_impl_ = NULL;
589
[email protected]310ebd6302011-10-10 19:06:28590 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51591 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59592}
593
594/*static*/
[email protected]310ebd6302011-10-10 19:06:28595RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31596 ViewMap* views = g_view_map.Pointer();
597 ViewMap::iterator it = views->find(webview);
598 return it == views->end() ? NULL : it->second;
599}
600
601/*static*/
602content::RenderView*
603 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28604 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31605}
606
607/*static*/
608void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49609 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59610 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
611 if (!visitor->Visit(it->second))
612 return;
613 }
614}
615
616/*static*/
[email protected]310ebd6302011-10-10 19:06:28617RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15618 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08619 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31620 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08621 const WebPreferences& webkit_prefs,
622 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34623 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56624 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26625 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46626 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41627 int32 next_page_id,
628 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29629 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28630 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51631 parent_hwnd,
632 opener_id,
633 renderer_prefs,
634 webkit_prefs,
635 counter,
636 routing_id,
[email protected]9f4f3322012-01-18 22:29:56637 surface_id,
[email protected]676126f72011-01-15 00:03:51638 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46639 frame_name,
[email protected]6fd35b72012-03-01 19:46:41640 next_page_id,
641 screen_info);
initial.commit09911bf2008-07-26 23:55:29642}
643
[email protected]273558fb2012-01-12 15:03:51644WebKit::WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
645 WebKit::WebPeerConnectionHandlerClient* client) {
646 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
647 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
648 return NULL;
649 EnsureMediaStreamImpl();
[email protected]5b87e782012-02-09 18:19:32650 if (!media_stream_impl_.get())
651 return NULL;
[email protected]273558fb2012-01-12 15:03:51652 return media_stream_impl_->CreatePeerConnectionHandler(client);
653}
654
[email protected]310ebd6302011-10-10 19:06:28655void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51656 observers_.AddObserver(observer);
657}
658
[email protected]310ebd6302011-10-10 19:06:28659void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
660 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51661 observers_.RemoveObserver(observer);
662}
663
[email protected]310ebd6302011-10-10 19:06:28664WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26665 return static_cast<WebKit::WebView*>(webwidget());
666}
667
[email protected]310ebd6302011-10-10 19:06:28668void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40669 if (!enabled) {
670 load_progress_tracker_.reset(NULL);
671 return;
672 }
673 if (load_progress_tracker_ == NULL)
674 load_progress_tracker_.reset(new LoadProgressTracker(this));
675}
676
[email protected]310ebd6302011-10-10 19:06:28677void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51678 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29679}
680
[email protected]310ebd6302011-10-10 19:06:28681void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26682 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30683 // If the renderer is visible, set initial visibility and focus state.
684 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34685#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30686 delegate->SetContainerVisibility(true);
687 if (webview() && webview()->isActive())
688 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34689#endif
[email protected]49232292010-09-03 19:07:30690 }
[email protected]784ea1ab2010-09-18 00:02:34691 // Plugins start assuming the content has focus (so that they work in
692 // environments where RenderView isn't hosting them), so we always have to
693 // set the initial state. See webplugin_delegate_impl.h for details.
694 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26695}
696
[email protected]310ebd6302011-10-10 19:06:28697void RenderViewImpl::UnregisterPluginDelegate(
698 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26699 plugin_delegates_.erase(delegate);
700}
[email protected]d8fd6fa2010-02-01 15:54:26701
[email protected]310ebd6302011-10-10 19:06:28702bool RenderViewImpl::GetPluginInfo(const GURL& url,
703 const GURL& page_url,
704 const std::string& mime_type,
705 webkit::WebPluginInfo* plugin_info,
706 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08707 bool found = false;
708 Send(new ViewHostMsg_GetPluginInfo(
709 routing_id_, url, page_url, mime_type, &found, plugin_info,
710 actual_mime_type));
711 return found;
712}
713
[email protected]310ebd6302011-10-10 19:06:28714bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27715 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27716 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41717 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26718
[email protected]676126f72011-01-15 00:03:51719 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
720 RenderViewObserver* observer;
721 while ((observer = it.GetNext()) != NULL)
722 if (observer->OnMessageReceived(message))
723 return true;
[email protected]b2abac72009-02-26 12:39:28724
[email protected]a95986a82010-12-24 06:19:28725 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40726 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28727 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29728 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
729 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56730 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29731 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
732 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
733 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
734 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27735#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35736 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27737#endif
initial.commit09911bf2008-07-26 23:55:29738 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15739 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29740 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
741 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
742 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08743 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29744 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15745 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29746 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49747 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
748 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17749 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17750 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41751 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54752 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
753 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29754 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18755 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
756 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29757 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48758 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55759 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
760 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
761 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
762 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
763 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
764 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
765 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45766 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40767 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29768 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19769 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
770 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29771 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
772 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
773 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51774 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
775 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29776 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04777 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15778 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29779 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
780 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08781 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
782 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00783 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16784 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14785 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25786 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
787 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47788 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34789 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10790 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
791 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51792 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56793 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36794 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34795 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:12796 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
797 OnSetNavigationStartTime)
[email protected]6ce7abc52010-02-02 18:40:14798#if defined(OS_MACOSX)
799 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13800 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13801 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
802 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14803#endif
[email protected]446705872009-09-10 07:22:48804 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33805 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33806 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
807 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24808 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42809 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
810 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19811 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
812 OnGetAllSavableResourceLinksForCurrentPage)
813 IPC_MESSAGE_HANDLER(
814 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
815 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08816#if defined(OS_MACOSX)
817 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
818#endif
[email protected]521b2482011-01-15 00:10:10819 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51820 // TODO(viettrungluu): Move to a separate message filter.
821#if defined(ENABLE_FLAPPER_HACKS)
822 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
823#endif
[email protected]54ca3ca892011-06-07 21:14:54824#if defined(OS_MACOSX)
825 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
826#endif
[email protected]9e1ad4b2011-08-14 16:49:19827 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
828 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18829 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51830 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19831
initial.commit09911bf2008-07-26 23:55:29832 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28833 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29834 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40835
836 if (!msg_is_ok) {
837 // The message had a handler, but its deserialization failed.
838 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28839 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40840 }
841
[email protected]a95986a82010-12-24 06:19:28842 return handled;
initial.commit09911bf2008-07-26 23:55:29843}
844
[email protected]310ebd6302011-10-10 19:06:28845void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]6dc7ff62012-03-15 06:16:13846#if defined(OS_CHROMEOS)
847 // crosbug.com/26646.
848 LOG(ERROR) << "OnNavigate: url=" << params.url
849 << ", webview=" << webview()
850 << ", reload=" << IsReload(params)
851 << ", paerams.state.empty=" << params.state.empty();
852#endif
[email protected]8bf1048012012-02-08 01:22:18853 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:29854 if (!webview())
855 return;
856
[email protected]440a0e52011-09-13 17:38:58857 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
858
[email protected]007733c2011-11-17 00:34:07859 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03860
861 // If this is a stale back/forward (due to a recent navigation the browser
862 // didn't know about), ignore it.
863 if (IsBackForwardToStaleEntry(params, is_reload))
864 return;
865
[email protected]992db4c2011-05-12 15:37:15866 // Swap this renderer back in if necessary.
867 if (is_swapped_out_)
868 SetSwappedOut(false);
869
[email protected]3cc72b12010-03-18 23:03:00870 history_list_offset_ = params.current_history_list_offset;
871 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03872 if (history_list_length_ >= 0)
873 history_page_ids_.resize(history_list_length_, -1);
874 if (params.pending_history_list_offset >= 0 &&
875 params.pending_history_list_offset < history_list_length_)
876 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00877
[email protected]38b592902011-04-16 02:08:42878 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29879
[email protected]26aa0482009-09-30 16:55:27880 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45881 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29882 // We cannot reload if we do not have any history state. This happens, for
883 // example, when recovering from a crash. Our workaround here is a bit of
884 // a hack since it means that reload after a crashed tab does not cause an
885 // end-to-end cache validation.
886 is_reload = false;
887 }
888
[email protected]007733c2011-11-17 00:34:07889 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
890 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50891
[email protected]04d3c6e2009-05-22 17:00:13892 // If we are reloading, then WebKit will use the history state of the current
893 // page, so we should just ignore any given history state. Otherwise, if we
894 // have history state, then we need to navigate to it, which corresponds to a
895 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55896 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29897 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02898 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29899 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55900 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13901 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58902 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45903 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17904 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13905 } else {
906 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28907 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29908
[email protected]e6f546c32009-07-01 17:12:55909 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23910 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13911
[email protected]dd7daa82009-08-10 05:46:45912 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55913 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13914
[email protected]445e1042011-12-03 21:03:15915 if (params.referrer.url.is_valid()) {
916 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
917 params.referrer.policy,
918 params.url,
919 WebString::fromUTF8(params.referrer.url.spec()));
920 if (!referrer.isEmpty())
921 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28922 }
[email protected]04d3c6e2009-05-22 17:00:13923
[email protected]52c68652010-12-07 17:47:04924 if (!params.extra_headers.empty()) {
925 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
926 params.extra_headers.end(), "\n");
927 i.GetNext(); ) {
928 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
929 WebString::fromUTF8(i.values()));
930 }
931 }
[email protected]6dc7ff62012-03-15 06:16:13932#if defined(OS_CHROMEOS)
933 // crosbug.com/26646.
934 LOG(ERROR) << " FrameLoader::loadRequest()";
935#endif
[email protected]dd7daa82009-08-10 05:46:45936 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50937 }
938
[email protected]77f17a82009-05-21 04:42:54939 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07940 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29941}
942
[email protected]310ebd6302011-10-10 19:06:28943bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03944 const ViewMsg_Navigate_Params& params,
945 bool is_reload) {
946 // Make sure this isn't a back/forward to an entry we have already cropped
947 // or replaced from our history, before the browser knew about it. If so,
948 // a new navigation has committed in the mean time, and we can ignore this.
949 bool is_back_forward = !is_reload && !params.state.empty();
950
951 // Note: if the history_list_length_ is 0 for a back/forward, we must be
952 // restoring from a previous session. We'll update our state in OnNavigate.
953 if (!is_back_forward || history_list_length_ <= 0)
954 return false;
955
956 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
957
958 // Check for whether the forward history has been cropped due to a recent
959 // navigation the browser didn't know about.
960 if (params.pending_history_list_offset >= history_list_length_)
961 return true;
962
963 // Check for whether this entry has been replaced with a new one.
964 int expected_page_id =
965 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44966 if (expected_page_id > 0 && params.page_id != expected_page_id) {
967 if (params.page_id < expected_page_id)
968 return true;
969
970 // Otherwise we've removed an earlier entry and should have shifted all
971 // entries left. For now, it's ok to lazily update the list.
972 // TODO(creis): Notify all live renderers when we remove entries from
973 // the front of the list, so that we don't hit this case.
974 history_page_ids_[params.pending_history_list_offset] = params.page_id;
975 }
[email protected]d466b8a2011-07-15 21:48:03976
977 return false;
978}
979
initial.commit09911bf2008-07-26 23:55:29980// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28981void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44982 if (webview()) {
983 WebFrame* main_frame = webview()->mainFrame();
984 // Stop the alt error page fetcher. If we let it continue it may complete
985 // and cause RenderViewHostManager to swap to this RenderView, even though
986 // it may no longer be active.
987 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
988 StopAltErrorPageFetcher(main_frame->dataSource());
989 main_frame->stopLoading();
990 }
initial.commit09911bf2008-07-26 23:55:29991}
992
[email protected]ecbf10d2010-02-18 13:03:29993// Reload current focused frame.
994// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28995void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29996 if (webview() && webview()->focusedFrame()) {
997 // We always obey the cache (ignore_cache=false) here.
998 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
999 // a cache-ignoring reload of the frame.
1000 webview()->focusedFrame()->reload(false);
1001 }
[email protected]1dda4022010-01-28 18:24:561002}
1003
[email protected]310ebd6302011-10-10 19:06:281004void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271005 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291006}
1007
[email protected]310ebd6302011-10-10 19:06:281008void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251009 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271010 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251011 return;
1012
[email protected]26aa0482009-09-30 16:55:271013 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451014 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251015}
1016
[email protected]310ebd6302011-10-10 19:06:281017void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291018 // Check if there is a targeturl waiting to be sent.
1019 if (target_url_status_ == TARGET_PENDING) {
1020 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1021 pending_target_url_));
1022 }
1023
1024 target_url_status_ = TARGET_NONE;
1025}
1026
[email protected]310ebd6302011-10-10 19:06:281027void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291028 if (!webview())
1029 return;
1030
[email protected]26aa0482009-09-30 16:55:271031 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291032}
1033
[email protected]310ebd6302011-10-10 19:06:281034void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291035 if (!webview())
1036 return;
1037
[email protected]26aa0482009-09-30 16:55:271038 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291039}
1040
[email protected]310ebd6302011-10-10 19:06:281041void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291042 if (!webview())
1043 return;
1044
[email protected]26aa0482009-09-30 16:55:271045 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291046}
1047
[email protected]310ebd6302011-10-10 19:06:281048void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291049 if (!webview())
1050 return;
1051
[email protected]f6b1856b2011-06-29 22:02:531052 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1053 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291054}
1055
[email protected]c0cc3092009-09-12 08:27:271056#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281057void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351058 if (!webview())
1059 return;
1060
1061 // Since the find pasteboard supports only plain text, this can be simpler
1062 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271063 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351064 if (frame->hasSelection()) {
1065 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271066 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171067 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351068 }
[email protected]a954bf72009-09-12 07:30:351069}
[email protected]c0cc3092009-09-12 08:27:271070#endif
[email protected]a954bf72009-09-12 07:30:351071
[email protected]310ebd6302011-10-10 19:06:281072void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291073 if (!webview())
1074 return;
1075
[email protected]26aa0482009-09-30 16:55:271076 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291077}
1078
[email protected]44bf7002011-10-16 02:46:151079void RenderViewImpl::OnPasteAndMatchStyle() {
1080 if (!webview())
1081 return;
1082
1083 webview()->focusedFrame()->executeCommand(
1084 WebString::fromUTF8("PasteAndMatchStyle"));
1085}
1086
[email protected]310ebd6302011-10-10 19:06:281087void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291088 if (!webview())
1089 return;
1090
[email protected]1ff7a032010-02-03 02:46:031091 WebFrame* frame = webview()->focusedFrame();
1092 if (!frame->hasSelection())
1093 frame->selectWordAroundCaret();
1094 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291095}
1096
[email protected]310ebd6302011-10-10 19:06:281097void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291098 if (!webview())
1099 return;
1100
[email protected]26aa0482009-09-30 16:55:271101 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291102}
1103
[email protected]310ebd6302011-10-10 19:06:281104void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291105 if (!webview())
1106 return;
1107
[email protected]26aa0482009-09-30 16:55:271108 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221109 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291110}
1111
[email protected]310ebd6302011-10-10 19:06:281112void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1113 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081114 if (!webview())
1115 return;
1116
1117 handling_select_range_ = true;
1118 webview()->focusedFrame()->selectRange(start, end);
1119 handling_select_range_ = false;
1120}
1121
[email protected]310ebd6302011-10-10 19:06:281122void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1123 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191124 DCHECK(history_length >= 0);
1125 DCHECK(history_list_offset_ == history_list_length_ - 1);
1126 DCHECK(minimum_page_id >= -1);
1127
1128 // Generate the new list.
1129 std::vector<int32> new_history_page_ids(history_length, -1);
1130 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1131 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1132 continue;
1133 new_history_page_ids.push_back(history_page_ids_[i]);
1134 }
1135 new_history_page_ids.swap(history_page_ids_);
1136
1137 // Update indexes.
1138 history_list_length_ = history_page_ids_.size();
1139 history_list_offset_ = history_list_length_ - 1;
1140}
1141
1142
[email protected]310ebd6302011-10-10 19:06:281143void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291144 if (!webview())
1145 return;
[email protected]26aa0482009-09-30 16:55:271146 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291147}
1148
[email protected]54ca3ca892011-06-07 21:14:541149#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281150void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331151 if (!webview())
1152 return;
1153 if (in_live_resize)
1154 webview()->willStartLiveResize();
1155 else
1156 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541157}
1158#endif
1159
[email protected]310ebd6302011-10-10 19:06:281160void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1161 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091162 WebKit::WebNode node = GetFocusedNode();
1163 if (!node.isNull()) {
1164 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191165 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511166 }
1167}
1168
initial.commit09911bf2008-07-26 23:55:291169///////////////////////////////////////////////////////////////////////////////
1170
1171// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281172void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451173 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291174 DCHECK(ds);
1175
[email protected]726985e22009-06-18 21:09:281176 const WebURLRequest& request = ds->request();
1177 const WebURLRequest& original_request = ds->originalRequest();
1178 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291179
[email protected]007733c2011-11-17 00:34:071180 DocumentState* document_state = DocumentState::FromDataSource(ds);
1181 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291182
1183 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281184 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291185 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051186 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291187 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071188 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191189 params.socket_address.set_host(response.remoteIPAddress().utf8());
1190 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031191 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091192 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071193 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291194 // SSL state specified in the request takes precedence over the one in the
1195 // response.
1196 // So far this is only intended for error pages that are not expected to be
1197 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281198 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071199 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291200 } else {
[email protected]726985e22009-06-18 21:09:281201 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291202 }
1203
1204 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311205 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291206
[email protected]5f9b8712011-11-23 08:55:571207 if (frame->document().baseURL() != params.url)
1208 params.base_url = frame->document().baseURL();
1209
[email protected]726985e22009-06-18 21:09:281210 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241211 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041212 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291213
[email protected]007733c2011-11-17 00:34:071214 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351215 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071216 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291217
1218 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071219 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291220 if (password_form_data)
1221 params.password_form = *password_form_data;
1222
1223 params.gesture = navigation_gesture_;
1224 navigation_gesture_ = NavigationGestureUnknown;
1225
[email protected]0f38dc4552011-02-25 11:24:001226 // Make navigation state a part of the FrameNavigate message so that commited
1227 // entry had it at all times.
1228 const WebHistoryItem& item = frame->currentHistoryItem();
1229 if (!item.isNull()) {
1230 params.content_state = webkit_glue::HistoryItemToString(item);
1231 } else {
1232 params.content_state =
1233 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1234 }
1235
[email protected]dd7daa82009-08-10 05:46:451236 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291237 // Top-level navigation.
1238
[email protected]b75b8292010-10-01 07:28:251239 // Set zoom level, but don't do it for full-page plugin since they don't use
1240 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011241 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541242 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251243 if (webview()->mainFrame()->document().isPluginDocument()) {
1244 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251245 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251246 } else {
1247 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251248 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251249 }
1250
[email protected]f85f0702010-01-30 09:31:011251 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511252 // This zoom level was merely recorded transiently for this load. We can
1253 // erase it now. If at some point we reload this page, the browser will
1254 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011255 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511256 }
1257
[email protected]b75b8292010-10-01 07:28:251258 // Reset the zoom limits in case a plugin had changed them previously. This
1259 // will also call us back which will cause us to send a message to
1260 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251261 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011262 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1263 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251264
initial.commit09911bf2008-07-26 23:55:291265 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551266 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291267
[email protected]daa8c58e2009-06-15 17:21:101268 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581269 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291270 // If the main frame does a load, it should not be reported as a subframe
1271 // navigation. This can occur in the following case:
1272 // 1. You're on a site with frames.
1273 // 2. You do a subframe navigation. This is stored with transition type
1274 // MANUAL_SUBFRAME.
1275 // 3. You navigate to some non-frame site, say, google.com.
1276 // 4. You navigate back to the page from step 2. Since it was initially
1277 // MANUAL_SUBFRAME, it will be that same transition type here.
1278 // We don't want that, because any navigation that changes the toplevel
1279 // frame should be tracked as a toplevel navigation (this allows us to
1280 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581281 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291282 }
1283
initial.commit09911bf2008-07-26 23:55:291284 // If we have a valid consumed client redirect source,
1285 // the page contained a client redirect (meta refresh, document.loc...),
1286 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151287 if (completed_client_redirect_src_.url.is_valid()) {
1288 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291289 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581290 params.transition = static_cast<content::PageTransition>(
1291 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291292 } else {
1293 // Bug 654101: the referrer will be empty on https->http transitions. It
1294 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151295 params.referrer = Referrer(GURL(
1296 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:401297 GetReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291298 }
1299
[email protected]726985e22009-06-18 21:09:281300 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051301 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291302 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051303 params.post_id = ExtractPostId(item);
1304 }
initial.commit09911bf2008-07-26 23:55:291305
[email protected]c2a797d2009-09-21 16:46:321306 // Save some histogram data so we can compute the average memory used per
1307 // page load of the glyphs.
1308 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1309 webkit_glue::GetGlyphPageCount());
1310
[email protected]15cf526b2010-02-12 06:33:491311 // This message needs to be sent before any of allowScripts(),
1312 // allowImages(), allowPlugins() is called for the new page, so that when
1313 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1314 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291315 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1316 } else {
1317 // Subframe navigation: the type depends on whether this navigation
1318 // generated a new session history entry. When they do generate a session
1319 // history entry, it means the user initiated the navigation and we should
1320 // mark it as such. This test checks if this is the first time UpdateURL
1321 // has been called since WillNavigateToURL was called to initiate the load.
1322 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581323 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291324 else
[email protected]2905f742011-10-13 03:51:581325 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291326
initial.commit09911bf2008-07-26 23:55:291327 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1328 }
1329
1330 last_page_id_sent_to_browser_ =
1331 std::max(last_page_id_sent_to_browser_, page_id_);
1332
1333 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101334 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581335 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291336}
1337
1338// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281339void RenderViewImpl::UpdateTitle(WebFrame* frame,
1340 const string16& title,
1341 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461342 // Ignore all but top level navigations.
1343 if (frame->parent())
1344 return;
1345
1346 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1347 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1348 title_direction));
initial.commit09911bf2008-07-26 23:55:291349}
1350
[email protected]310ebd6302011-10-10 19:06:281351void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1352 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291353 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271354 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291355 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301356 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291357 last_encoding_name_ = encoding_name;
1358
[email protected]e38f40152008-09-12 23:08:301359 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291360 }
1361}
1362
[email protected]e15f680732010-11-23 22:30:201363// Sends the last committed session history state to the browser so it will be
1364// saved before we navigate to a new page. This must be called *before* the
1365// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281366void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291367 // If we have a valid page ID at this point, then it corresponds to the page
1368 // we are navigating away from. Otherwise, this is the first navigation, so
1369 // there is no past session history to record.
1370 if (page_id_ == -1)
1371 return;
1372
[email protected]ca948a22009-06-25 19:36:171373 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271374 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171375 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291376 return;
[email protected]ca948a22009-06-25 19:36:171377
1378 Send(new ViewHostMsg_UpdateState(
1379 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291380}
1381
[email protected]310ebd6302011-10-10 19:06:281382void RenderViewImpl::OpenURL(WebFrame* frame,
1383 const GURL& url,
[email protected]445e1042011-12-03 21:03:151384 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281385 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171386 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581387 routing_id_,
1388 url,
1389 referrer,
1390 NavigationPolicyToDisposition(policy),
1391 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171392}
1393
[email protected]79dbc662009-09-04 05:42:511394// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291395
[email protected]310ebd6302011-10-10 19:06:281396void RenderViewImpl::LoadNavigationErrorPage(
1397 WebFrame* frame,
1398 const WebURLRequest& failed_request,
1399 const WebURLError& error,
1400 const std::string& html,
1401 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581402 std::string alt_html;
1403 const std::string* error_html;
1404
1405 if (!html.empty()) {
1406 error_html = &html;
1407 } else {
1408 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1409 failed_request, error, &alt_html, NULL);
1410 error_html = &alt_html;
1411 }
1412
1413 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361414 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251415 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551416 replace);
initial.commit09911bf2008-07-26 23:55:291417}
1418
[email protected]269f86d2011-12-07 02:43:471419bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281420 const string16& message,
1421 const string16& default_value,
1422 const GURL& frame_url,
1423 string16* result) {
initial.commit09911bf2008-07-26 23:55:291424 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411425 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291426 if (!result)
1427 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291428
[email protected]12636df2009-09-28 22:32:211429 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1430 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291431 return success;
1432}
1433
[email protected]310ebd6302011-10-10 19:06:281434bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571435 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1436 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1437 // it is particularly important that we do not call willEnterModalLoop as
1438 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441439 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1440 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571441
1442 message->EnableMessagePumping(); // Runs a nested message loop.
1443 return Send(message);
1444}
1445
[email protected]48c9cf2d2009-09-16 16:47:521446// WebKit::WebViewClient ------------------------------------------------------
1447
[email protected]916dfb62012-03-05 03:39:371448WebView* RenderViewImpl::createView(
1449 WebFrame* creator,
1450 const WebURLRequest& request,
1451 const WebWindowFeatures& features,
1452 const WebString& frame_name,
1453 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521454 // Check to make sure we aren't overloading on popups.
1455 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1456 return NULL;
1457
[email protected]8ab04652010-06-12 02:47:261458 ViewHostMsg_CreateWindow_Params params;
1459 params.opener_id = routing_id_;
1460 params.user_gesture = creator->isProcessingUserGesture();
1461 params.window_container_type = WindowFeaturesToContainerType(features);
1462 params.session_storage_namespace_id = session_storage_namespace_id_;
1463 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111464 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411465 params.opener_url = creator->document().url();
1466 params.opener_security_origin =
1467 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591468 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1469 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111470 if (!request.isNull())
1471 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261472
[email protected]48c9cf2d2009-09-16 16:47:521473 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561474 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341475 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521476
[email protected]380244092011-10-07 17:26:271477 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261478 new ViewHostMsg_CreateWindow(params,
1479 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561480 &surface_id,
[email protected]8ab04652010-06-12 02:47:261481 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211482 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521483 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521484
[email protected]310ebd6302011-10-10 19:06:281485 RenderViewImpl* view = RenderViewImpl::Create(
1486 0,
1487 routing_id_,
1488 renderer_preferences_,
1489 webkit_preferences_,
1490 shared_popup_counter_,
1491 routing_id,
[email protected]9f4f3322012-01-18 22:29:561492 surface_id,
[email protected]310ebd6302011-10-10 19:06:281493 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461494 frame_name,
[email protected]6fd35b72012-03-01 19:46:411495 1,
1496 screen_info_);
[email protected]8ab04652010-06-12 02:47:261497 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521498
[email protected]007a848b2009-10-26 15:55:461499 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591500 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461501
[email protected]48c9cf2d2009-09-16 16:47:521502 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411503 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521504 if (!creator_url.is_valid() || !creator_url.IsStandard())
1505 creator_url = GURL();
1506 view->creator_url_ = creator_url;
1507
1508 // Copy over the alternate error page URL so we can have alt error pages in
1509 // the new render view (we don't need the browser to send the URL back down).
1510 view->alternate_error_page_url_ = alternate_error_page_url_;
1511
1512 return view->webview();
1513}
1514
[email protected]310ebd6302011-10-10 19:06:281515WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411516 RenderWidget* widget =
1517 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521518 return widget->webwidget();
1519}
1520
[email protected]310ebd6302011-10-10 19:06:281521WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441522 // TODO(jcivelli): Remove this deprecated method when its been removed from
1523 // the WebViewClient interface. It's been replaced by
1524 // createExternalPopupMenu.
1525 NOTREACHED();
1526 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521527}
1528
[email protected]310ebd6302011-10-10 19:06:281529WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081530 const WebPopupMenuInfo& popup_menu_info,
1531 WebExternalPopupMenuClient* popup_menu_client) {
1532 DCHECK(!external_popup_menu_.get());
1533 external_popup_menu_.reset(
1534 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1535 return external_popup_menu_.get();
1536}
1537
[email protected]310ebd6302011-10-10 19:06:281538RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521539 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531540 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421541 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411542 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531543 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271544 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391545 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561546 return widget;
[email protected]79c7bed2010-09-14 22:28:391547}
1548
[email protected]310ebd6302011-10-10 19:06:281549WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1550 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341551 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391552 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291553 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1554 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1555 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341556}
1557
[email protected]7e8b4d12012-01-20 23:39:511558WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]40ec0c12012-03-08 12:34:401559 const WebGraphicsContext3D::Attributes& attributes) {
[email protected]7e8b4d12012-01-20 23:39:511560 if (!webview())
1561 return NULL;
1562 // The WebGraphicsContext3DInProcessImpl code path is used for
1563 // layout tests (though not through this code) as well as for
1564 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511565 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571566 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
[email protected]29dea0e2012-03-16 01:46:581567 attributes, true);
[email protected]7e8b4d12012-01-20 23:39:511568 } else {
[email protected]b3e83de2012-02-07 03:33:281569 GURL url;
1570 if (webview()->mainFrame())
1571 url = GURL(webview()->mainFrame()->document().url());
1572
[email protected]b3e83de2012-02-07 03:33:281573 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1574 new WebGraphicsContext3DCommandBufferImpl(
[email protected]29dea0e2012-03-16 01:46:581575 surface_id(), url, RenderThreadImpl::current(), AsWeakPtr()));
[email protected]b3e83de2012-02-07 03:33:281576
1577 if (!context->Initialize(attributes))
[email protected]56200f012012-02-03 23:13:571578 return NULL;
[email protected]d0fb8a72012-03-10 18:54:521579 context_is_web_graphics_context_3d_command_buffer_impl_ = true;
[email protected]56200f012012-02-03 23:13:571580 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511581 }
[email protected]7e8b4d12012-01-20 23:39:511582}
1583
[email protected]310ebd6302011-10-10 19:06:281584void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521585 const WebConsoleMessage& message, const WebString& source_name,
1586 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081587 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511588 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081589 case WebConsoleMessage::LevelTip:
1590 log_severity = logging::LOG_VERBOSE;
1591 break;
1592 case WebConsoleMessage::LevelLog:
1593 log_severity = logging::LOG_INFO;
1594 break;
1595 case WebConsoleMessage::LevelWarning:
1596 log_severity = logging::LOG_WARNING;
1597 break;
1598 case WebConsoleMessage::LevelError:
1599 log_severity = logging::LOG_ERROR;
1600 break;
1601 default:
1602 NOTREACHED();
1603 }
1604
[email protected]48c9cf2d2009-09-16 16:47:521605 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081606 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311607 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521608 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311609 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521610}
1611
[email protected]310ebd6302011-10-10 19:06:281612void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421613 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521614}
1615
[email protected]310ebd6302011-10-10 19:06:281616WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511617 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021618}
1619
[email protected]310ebd6302011-10-10 19:06:281620bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121621 const WebString& path,
1622 WebFileChooserCompletion* chooser_completion) {
1623 int id = enumeration_completion_id_++;
1624 enumeration_completions_[id] = chooser_completion;
1625 return Send(new ViewHostMsg_EnumerateDirectory(
1626 routing_id_,
1627 id,
1628 webkit_glue::WebStringToFilePath(path)));
1629}
1630
[email protected]310ebd6302011-10-10 19:06:281631void RenderViewImpl::didStartLoading() {
[email protected]6dc7ff62012-03-15 06:16:131632#if defined(OS_CHROMEOS)
1633 // crosbug.com/26646.
1634 LOG(ERROR) << "didStartLoading is_loading=" << is_loading_;
1635#endif
[email protected]48c9cf2d2009-09-16 16:47:521636 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141637 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521638 return;
1639 }
1640
1641 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521642
1643 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311644
1645 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521646}
1647
[email protected]310ebd6302011-10-10 19:06:281648void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521649 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141650 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521651 return;
1652 }
1653
1654 is_loading_ = false;
1655
1656 // NOTE: For now we're doing the safest thing, and sending out notification
1657 // when done loading. This currently isn't an issue as the favicon is only
1658 // displayed when done loading. Ideally we would send notification when
1659 // finished parsing the head, but webkit doesn't support that yet.
1660 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521661 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1662
[email protected]90109412010-12-15 17:14:241663 if (load_progress_tracker_ != NULL)
1664 load_progress_tracker_->DidStopLoading();
1665
[email protected]93b9d692011-04-13 00:44:311666 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521667}
1668
[email protected]310ebd6302011-10-10 19:06:281669void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1670 double load_progress) {
[email protected]90109412010-12-15 17:14:241671 if (load_progress_tracker_ != NULL)
1672 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1673}
1674
[email protected]310ebd6302011-10-10 19:06:281675bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061676#if defined(OS_MACOSX)
1677 return true;
1678#else
1679 return false;
1680#endif
1681}
1682
[email protected]310ebd6302011-10-10 19:06:281683bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031684#if defined(OS_WIN)
1685 return true;
1686#else
1687 return false;
1688#endif
1689}
1690
[email protected]310ebd6302011-10-10 19:06:281691void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081692 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031693 return;
[email protected]4fb60142011-08-09 02:22:081694 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011695
[email protected]b781ff282011-08-20 06:19:361696 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031697}
1698
[email protected]310ebd6302011-10-10 19:06:281699void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121700 const std::string& name = UTF16ToUTF8(command_name);
1701 if (StartsWithASCII(name, "Move", true) ||
1702 StartsWithASCII(name, "Insert", true) ||
1703 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031704 return;
[email protected]f1a29a02011-10-06 23:08:441705 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031706}
1707
[email protected]310ebd6302011-10-10 19:06:281708bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101709 if (edit_commands_.empty())
1710 return false;
1711
[email protected]26aa0482009-09-30 16:55:271712 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101713 if (!frame)
1714 return false;
1715
1716 EditCommands::iterator it = edit_commands_.begin();
1717 EditCommands::iterator end = edit_commands_.end();
1718
[email protected]507b33ea2009-09-29 03:56:511719 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101720 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331721 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1722 // key (but it's the exception). Once one edit command is not executed, it
1723 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101724 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1725 WebString::fromUTF8(it->value)))
1726 break;
[email protected]507b33ea2009-09-29 03:56:511727 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101728 }
1729
[email protected]507b33ea2009-09-29 03:56:511730 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101731}
1732
[email protected]310ebd6302011-10-10 19:06:281733bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351734 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471735 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351736 // Do not open the file dialog in a hidden RenderView.
1737 if (is_hidden())
1738 return false;
[email protected]8caadeb2011-11-22 02:45:231739 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261740 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231741 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261742 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231743 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501744 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231745 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261746 else
[email protected]8caadeb2011-11-22 02:45:231747 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471748 ipc_params.title = params.title;
1749 ipc_params.default_file_name =
1750 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461751 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1752 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1753 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471754
1755 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461756}
1757
[email protected]269f86d2011-12-07 02:43:471758void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1759 const WebString& message) {
1760 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411761 message,
1762 string16(),
[email protected]b6cb3a842011-06-24 18:28:411763 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521764 NULL);
1765}
1766
[email protected]269f86d2011-12-07 02:43:471767bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1768 const WebString& message) {
1769 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411770 message,
1771 string16(),
[email protected]b6cb3a842011-06-24 18:28:411772 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521773 NULL);
1774}
1775
[email protected]269f86d2011-12-07 02:43:471776bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1777 const WebString& message,
1778 const WebString& default_value,
1779 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411780 string16 result;
[email protected]269f86d2011-12-07 02:43:471781 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411782 message,
1783 default_value,
[email protected]b6cb3a842011-06-24 18:28:411784 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521785 &result);
1786 if (ok)
[email protected]4f5ce842011-05-27 19:34:411787 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521788 return ok;
1789}
1790
[email protected]310ebd6302011-10-10 19:06:281791bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521792 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151793 // If we are swapping out, we have already run the beforeunload handler.
1794 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1795 // at all, to avoid running it twice.
1796 if (is_swapped_out_)
1797 return true;
1798
[email protected]3b3301f62012-02-29 04:32:321799 bool is_reload = false;
1800 WebDataSource* ds = frame->provisionalDataSource();
1801 if (ds)
1802 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
1803
[email protected]48c9cf2d2009-09-16 16:47:521804 bool success = false;
1805 // This is an ignored return value, but is included so we can accept the same
1806 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411807 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211808 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:321809 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:411810 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521811 return success;
1812}
1813
[email protected]310ebd6302011-10-10 19:06:281814void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441815 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:511816 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:371817
1818 // frame is NULL if invoked by BlockedPlugin.
1819 if (frame)
1820 params.frame_id = frame->identifier();
1821
[email protected]db803aae2011-03-05 02:00:421822 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271823 // it. We replace it with an empty GURL so the appropriate items are disabled
1824 // in the context menu.
1825 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1826 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421827 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271828 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101829 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291830 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441831}
1832
[email protected]310ebd6302011-10-10 19:06:281833void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261834 // TODO(darin): Remove once WebKit roll is complete.
1835 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471836}
1837
[email protected]310ebd6302011-10-10 19:06:281838void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261839 // TODO(darin): Remove once WebKit roll is complete.
1840 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471841}
1842
[email protected]310ebd6302011-10-10 19:06:281843void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521844}
1845
[email protected]310ebd6302011-10-10 19:06:281846void RenderViewImpl::UpdateTargetURL(const GURL& url,
1847 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581848 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521849 if (latest_url == target_url_)
1850 return;
[email protected]163f8242009-10-30 20:19:551851
[email protected]48c9cf2d2009-09-16 16:47:521852 // Tell the browser to display a destination link.
1853 if (target_url_status_ == TARGET_INFLIGHT ||
1854 target_url_status_ == TARGET_PENDING) {
1855 // If we have a request in-flight, save the URL to be sent when we
1856 // receive an ACK to the in-flight request. We can happily overwrite
1857 // any existing pending sends.
1858 pending_target_url_ = latest_url;
1859 target_url_status_ = TARGET_PENDING;
1860 } else {
[email protected]c85f0212011-11-04 16:54:411861 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1862 // see |ParamTraits<GURL>|.
1863 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1864 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521865 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1866 target_url_ = latest_url;
1867 target_url_status_ = TARGET_INFLIGHT;
1868 }
1869}
1870
[email protected]310ebd6302011-10-10 19:06:281871void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311872 int delay;
1873 if (send_content_state_immediately_)
1874 delay = 0;
1875 else if (is_hidden())
1876 delay = kDelaySecondsForContentStateSyncHidden;
1877 else
1878 delay = kDelaySecondsForContentStateSync;
1879
1880 if (nav_state_sync_timer_.IsRunning()) {
1881 // The timer is already running. If the delay of the timer maches the amount
1882 // we want to delay by, then return. Otherwise stop the timer so that it
1883 // gets started with the right delay.
1884 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1885 return;
1886 nav_state_sync_timer_.Stop();
1887 }
1888
[email protected]d323a172011-09-02 18:23:021889 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281890 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311891}
1892
[email protected]310ebd6302011-10-10 19:06:281893void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551894 mouse_over_url_ = GURL(url);
1895 UpdateTargetURL(mouse_over_url_, focus_url_);
1896}
1897
[email protected]310ebd6302011-10-10 19:06:281898void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551899 focus_url_ = GURL(url);
1900 UpdateTargetURL(focus_url_, mouse_over_url_);
1901}
1902
[email protected]310ebd6302011-10-10 19:06:281903void RenderViewImpl::startDragging(const WebDragData& data,
1904 WebDragOperationsMask mask,
1905 const WebImage& image,
1906 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411907#if WEBKIT_USING_SKIA
1908 SkBitmap bitmap(image.getSkBitmap());
1909#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331910 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411911#endif
1912
[email protected]59f4f2fa2011-03-23 01:00:551913 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521914 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411915 mask,
1916 bitmap,
1917 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521918}
1919
[email protected]310ebd6302011-10-10 19:06:281920bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451921 return renderer_preferences_.can_accept_load_drops;
1922}
1923
[email protected]310ebd6302011-10-10 19:06:281924void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521925 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1926}
1927
[email protected]310ebd6302011-10-10 19:06:281928void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521929 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1930}
1931
[email protected]310ebd6302011-10-10 19:06:281932void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511933 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071934
[email protected]38b592902011-04-16 02:08:421935 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491936}
1937
[email protected]169d4282011-11-30 19:33:591938void RenderViewImpl::didUpdateLayout() {
1939 // We don't always want to set up a timer, only if we've been put in that
1940 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1941 // message.
1942 if (!send_preferred_size_changes_ || !webview())
1943 return;
1944
1945 if (check_preferred_size_timer_.IsRunning())
1946 return;
1947 check_preferred_size_timer_.Start(FROM_HERE,
1948 TimeDelta::FromMilliseconds(0), this,
1949 &RenderViewImpl::CheckPreferredSize);
1950}
1951
[email protected]310ebd6302011-10-10 19:06:281952void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521953 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1954}
1955
[email protected]310ebd6302011-10-10 19:06:281956int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001957 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521958}
1959
[email protected]310ebd6302011-10-10 19:06:281960int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001961 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521962}
1963
[email protected]310ebd6302011-10-10 19:06:281964void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321965 const WebAccessibilityObject& obj,
1966 WebAccessibilityNotification notification) {
1967 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1968}
1969
[email protected]310ebd6302011-10-10 19:06:281970void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141971 const WebString& value) {
1972 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1973 key.utf8(),
1974 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261975}
1976
[email protected]79dbc662009-09-04 05:42:511977// WebKit::WebWidgetClient ----------------------------------------------------
1978
[email protected]310ebd6302011-10-10 19:06:281979void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121980 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1981 // we won't have to test for user gesture anymore and we can
1982 // move that code back to render_widget.cc
1983 if (webview() && webview()->mainFrame() &&
1984 webview()->mainFrame()->isProcessingUserGesture()) {
1985 Send(new ViewHostMsg_Focus(routing_id_));
1986 }
1987}
1988
[email protected]310ebd6302011-10-10 19:06:281989void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121990 // TODO(jcivelli): see TODO above in didFocus().
1991 if (webview() && webview()->mainFrame() &&
1992 webview()->mainFrame()->isProcessingUserGesture()) {
1993 Send(new ViewHostMsg_Blur(routing_id_));
1994 }
1995}
1996
initial.commit09911bf2008-07-26 23:55:291997// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281998// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291999// point to dispatch the ShowView message.
2000//
2001// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282002// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292003//
[email protected]310ebd6302011-10-10 19:06:282004void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292005 DCHECK(!did_show_) << "received extraneous Show call";
2006 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2007
2008 if (did_show_)
2009 return;
2010 did_show_ = true;
2011
[email protected]6779aa12011-03-29 17:32:242012 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042013 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042014
[email protected]28295ec2009-10-16 05:34:332015 // Force new windows to a popup if they were not opened with a user gesture.
2016 if (!opened_by_user_gesture_) {
2017 // We exempt background tabs for compat with older versions of Chrome.
2018 // TODO(darin): This seems bogus. These should have a user gesture, so
2019 // we probably don't need this check.
2020 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2021 policy = WebKit::WebNavigationPolicyNewPopup;
2022 }
2023
initial.commit09911bf2008-07-26 23:55:292024 // NOTE: initial_pos_ may still have its default values at this point, but
2025 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2026 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282027 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2028 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292029 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242030 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292031}
2032
[email protected]310ebd6302011-10-10 19:06:282033void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292034 DCHECK(did_show_) << "should already have shown the view";
2035
[email protected]c1f50aa2010-02-18 03:46:572036 // We must keep WebKit's shared timer running in this case in order to allow
2037 // showModalDialog to function properly.
2038 //
2039 // TODO(darin): WebKit should really be smarter about suppressing events and
2040 // timers so that we do not need to manage the shared timer in such a heavy
2041 // handed manner.
2042 //
[email protected]f1a29a02011-10-06 23:08:442043 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2044 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572045
[email protected]12636df2009-09-28 22:32:212046 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292047}
2048
[email protected]2b624c562011-10-27 22:58:262049bool RenderViewImpl::enterFullScreen() {
2050 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2051 return true;
2052}
2053
2054void RenderViewImpl::exitFullScreen() {
2055 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2056}
2057
[email protected]217690d2012-01-27 07:33:112058bool RenderViewImpl::requestPointerLock() {
2059 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2060}
2061
2062void RenderViewImpl::requestPointerUnlock() {
2063 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2064}
2065
2066bool RenderViewImpl::isPointerLocked() {
2067 return mouse_lock_dispatcher_->IsMouseLockedTo(
2068 webwidget_mouse_lock_target_.get());
2069}
2070
[email protected]3d9689372009-09-10 04:29:172071// WebKit::WebFrameClient -----------------------------------------------------
2072
[email protected]310ebd6302011-10-10 19:06:282073WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2074 const WebPluginParams& params) {
[email protected]0361b942012-03-14 06:42:532075 // The browser plugin is a special kind of pepper plugin
2076 // that loads asynchronously. We first create a placeholder here.
2077 // When a guest is ready to be displayed, we swap out the placeholder
2078 // with the guest.
2079 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2080 if (command_line.HasSwitch(switches::kEnableBrowserPlugin) &&
2081 UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType)
2082 return BrowserPluginPlaceholder::Create(this, frame, params);
2083
[email protected]eaacd1f2011-09-23 02:32:552084 WebPlugin* plugin = NULL;
2085 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2086 this, frame, params, &plugin)) {
2087 return plugin;
2088 }
2089
[email protected]a813c8e2011-10-08 01:34:112090 webkit::WebPluginInfo info;
2091 std::string mime_type;
2092 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2093 params.mimeType.utf8(), &info, &mime_type);
2094 if (!found)
2095 return NULL;
2096
2097 WebPluginParams params_to_use = params;
2098 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312099 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172100}
2101
[email protected]310ebd6302011-10-10 19:06:282102WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422103 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372104 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422105
[email protected]30447b62009-11-13 01:13:372106 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512107 bool exists = false;
[email protected]30447b62009-11-13 01:13:372108 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512109 ViewHostMsg_CreateWorker_Params params;
2110 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512111 params.name = name;
2112 params.document_id = document_id;
2113 params.render_view_route_id = routing_id_;
2114 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232115 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372116 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512117 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372118 if (url_mismatch) {
2119 return NULL;
2120 } else {
[email protected]f1a29a02011-10-06 23:08:442121 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492122 document_id,
[email protected]6de0bcf2010-02-17 22:00:512123 exists,
[email protected]30447b62009-11-13 01:13:372124 route_id,
2125 routing_id_);
2126 }
[email protected]9c00f002009-11-05 22:37:422127}
2128
[email protected]310ebd6302011-10-10 19:06:282129WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172130 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442131 FOR_EACH_OBSERVER(
2132 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172133
[email protected]bb6fd402011-12-09 02:45:442134 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502135 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442136 media::FilterCollection* collection = new media::FilterCollection();
2137 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372138
[email protected]9e2269d2012-01-07 00:06:212139 RenderAudioSourceProvider* audio_source_provider = NULL;
2140
[email protected]3d9689372009-09-10 04:29:172141 // Add in any custom filter factories first.
2142 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2143 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212144 // audio_source_provider is a "provider" to WebKit, and a sink
2145 // from the perspective of the audio renderer.
2146 audio_source_provider = new RenderAudioSourceProvider();
2147
2148 // Add the chrome specific audio renderer, using audio_source_provider
2149 // as the sink.
2150 AudioRendererImpl* audio_renderer =
2151 new AudioRendererImpl(audio_source_provider);
2152 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172153 }
2154
[email protected]e1d69d762011-12-13 05:12:182155 // Currently only cros/arm has any HW video decode support in
2156 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2157 // platforms. This is a startup-time optimization. When new VDA
2158 // implementations are added, relax the #if above.
[email protected]d0fb8a72012-03-10 18:54:522159#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
2160 // Note we don't actually use the result of this blind down-cast unless it's
2161 // valid (not NULL and of the right type).
[email protected]43567302012-02-16 23:21:392162 WebGraphicsContext3DCommandBufferImpl* context3d =
2163 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2164 webview()->graphicsContext3D());
[email protected]d0fb8a72012-03-10 18:54:522165 if (context_is_web_graphics_context_3d_command_buffer_impl_ && context3d) {
[email protected]84a83e192012-03-09 18:43:402166 MessageLoop* factories_loop =
2167 RenderThreadImpl::current()->compositor_thread() ?
2168 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
2169 ->message_loop() :
2170 MessageLoop::current();
[email protected]e1d69d762011-12-13 05:12:182171 GpuChannelHost* gpu_channel_host =
2172 RenderThreadImpl::current()->EstablishGpuChannelSync(
2173 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2174 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312175 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
[email protected]84a83e192012-03-09 18:43:402176 factories_loop,
[email protected]8d4359282012-01-14 00:53:312177 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402178 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182179 }
2180#endif
2181
[email protected]da952fd2012-01-13 03:49:252182 webkit_media::WebMediaPlayerImpl* media_player =
2183 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2184 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
2185 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]c4dabe452012-02-08 23:58:122186#if defined(OS_ANDROID)
2187 // TODO(qinmin): Implement for android.
2188 // http://crbug.com/113218
2189#else
[email protected]da952fd2012-01-13 03:49:252190 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562191 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252192 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]9e2269d2012-01-07 00:06:212193 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]bb6fd402011-12-09 02:45:442194 }
[email protected]c4dabe452012-02-08 23:58:122195#endif
[email protected]cec4eb82012-01-12 17:51:562196 return media_player;
[email protected]3d9689372009-09-10 04:29:172197}
2198
[email protected]310ebd6302011-10-10 19:06:282199WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212200 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232201 if (!frame || !frame->view())
2202 return NULL;
[email protected]035545f2010-04-09 13:10:212203 return new RendererWebApplicationCacheHostImpl(
2204 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442205 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212206}
2207
[email protected]310ebd6302011-10-10 19:06:282208WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382209 return &cookie_jar_;
2210}
2211
[email protected]310ebd6302011-10-10 19:06:282212void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512213 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452214}
2215
[email protected]310ebd6302011-10-10 19:06:282216void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512217 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172218}
2219
[email protected]310ebd6302011-10-10 19:06:282220void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172221 WebFrame* frame, const WebURLRequest& request,
2222 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342223 loadURLExternally(frame, request, policy, WebString());
2224}
2225
[email protected]310ebd6302011-10-10 19:06:282226void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342227 WebFrame* frame, const WebURLRequest& request,
2228 WebNavigationPolicy policy,
2229 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592230 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2231 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342232 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2233 suggested_name));
[email protected]efce17b2009-09-11 18:04:592234 } else {
[email protected]445e1042011-12-03 21:03:152235 OpenURL(frame, request.url(),
[email protected]b9fd01ba2012-02-28 01:50:402236 Referrer(referrer, GetReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592237 }
[email protected]3d9689372009-09-10 04:29:172238}
2239
[email protected]310ebd6302011-10-10 19:06:282240WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172241 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222242 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152243 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2244 if (is_swapped_out_) {
[email protected]73eb2602012-02-09 19:50:552245 // It is possible for in-progress navigations to arrive here just after we
2246 // are swapped out, including iframes. We should cancel them.
2247 if (request.url() != GURL("about:swappedout"))
2248 return WebKit::WebNavigationPolicyIgnore;
2249
2250 // Allow about:swappedout to complete.
[email protected]992db4c2011-05-12 15:37:152251 return default_policy;
2252 }
2253
[email protected]3d9689372009-09-10 04:29:172254 // Webkit is asking whether to navigate to a new URL.
2255 // This is fine normally, except if we're showing UI from one security
2256 // context and they're trying to navigate to a different context.
2257 const GURL& url = request.url();
2258
[email protected]d19ea342011-04-20 20:31:132259 // A content initiated navigation may have originated from a link-click,
2260 // script, drag-n-drop operation, etc.
2261 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072262 DocumentState::FromDataSource(frame->provisionalDataSource())->
2263 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132264
[email protected]a8c269a2011-10-25 20:17:222265 // Experimental:
2266 // If --enable-strict-site-isolation is enabled, send all top-level
2267 // navigations to the browser to let it swap processes when crossing site
2268 // boundaries. This is currently expected to break some script calls and
2269 // navigations, such as form submissions.
2270 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102271 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2272 !frame->parent() && (is_content_initiated || is_redirect)) {
2273 WebString origin_str = frame->document().securityOrigin().toString();
2274 GURL frame_url(origin_str.utf8().data());
2275 // TODO(cevans): revisit whether this origin check is still necessary once
2276 // crbug.com/101395 is fixed.
2277 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]445e1042011-12-03 21:03:152278 Referrer referrer(
2279 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402280 GetReferrerPolicyFromRequest(request));
[email protected]313b80bd2011-11-23 03:49:102281 OpenURL(frame, url, referrer, default_policy);
2282 return WebKit::WebNavigationPolicyIgnore;
2283 }
[email protected]a8c269a2011-10-25 20:17:222284 }
2285
[email protected]3d9689372009-09-10 04:29:172286 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302287 // navigations.
[email protected]5f000f272012-01-19 05:25:082288 if (is_content_initiated) {
2289 bool browser_handles_top_level_requests =
2290 renderer_preferences_.browser_handles_top_level_requests &&
2291 IsNonLocalTopLevelNavigation(url, frame, type);
2292 if (browser_handles_top_level_requests ||
2293 renderer_preferences_.browser_handles_all_requests) {
2294 Referrer referrer(
2295 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402296 GetReferrerPolicyFromRequest(request));
[email protected]5f000f272012-01-19 05:25:082297 // Reset these counters as the RenderView could be reused for the next
2298 // navigation.
2299 page_id_ = -1;
2300 last_page_id_sent_to_browser_ = -1;
2301 OpenURL(frame, url, referrer, default_policy);
2302 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2303 }
[email protected]3d9689372009-09-10 04:29:172304 }
2305
[email protected]6101c342010-12-16 22:44:372306 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552307 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042308 // top-level navigations (not iframes). But we sometimes navigate to
2309 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372310 //
[email protected]744c2a22012-03-15 18:42:042311 // Note: this is known to break POST submissions when crossing process
2312 // boundaries until http://crbug.com/101395 is fixed. This is better for
2313 // security than loading a WebUI, extension or app page in the wrong process.
2314 // POST requests don't work because this mechanism does not preserve form
2315 // POST data. We will need to send the request's httpBody data up to the
2316 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572317 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2318 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222319 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042320 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372321 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042322
2323 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2324 // must be handled by the browser process so that the correct bindings and
2325 // data sources can be registered.
2326 // Similarly, navigations to view-source URLs or within ViewSource mode
2327 // must be handled by the browser process.
2328 int cumulative_bindings =
2329 RenderProcess::current()->GetEnabledBindings();
[email protected]6101c342010-12-16 22:44:372330 bool should_fork =
[email protected]744c2a22012-03-15 18:42:042331 content::GetContentClient()->HasWebUIScheme(url) ||
2332 (cumulative_bindings & content::BINDINGS_POLICY_WEB_UI) ||
2333 url.SchemeIs(chrome::kViewSourceScheme) ||
2334 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112335
[email protected]e48869a2011-04-01 19:56:032336 if (!should_fork) {
2337 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042338 // For now, we skip this for POST submissions. This is because
2339 // http://crbug.com/101395 is more likely to cause compatibility issues
2340 // with hosted apps and extensions than WebUI pages. We will remove this
2341 // check when cross-process POST submissions are supported.
2342 if (request.httpMethod() == "GET") {
2343 bool is_initial_navigation = page_id_ == -1;
2344 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2345 frame, url, is_initial_navigation, &send_referrer);
2346 }
[email protected]6101c342010-12-16 22:44:372347 }
2348
2349 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152350 Referrer referrer(
2351 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402352 GetReferrerPolicyFromRequest(request));
[email protected]445e1042011-12-03 21:03:152353 OpenURL(
2354 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112355 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2356 }
[email protected]3d9689372009-09-10 04:29:172357 }
2358
[email protected]43763f982011-08-26 18:33:402359 // Use the frame's original request's URL rather than the document's URL for
2360 // this check. For a popup, the document's URL may become the opener window's
2361 // URL if the opener has called document.write. See http://crbug.com/93517.
2362 GURL old_url(frame->dataSource()->request().url());
2363
[email protected]3d9689372009-09-10 04:29:172364 // Detect when a page is "forking" a new tab that can be safely rendered in
2365 // its own process. This is done by sites like Gmail that try to open links
2366 // in new windows without script connections back to the original page. We
2367 // treat such cases as browser navigations (in which we will create a new
2368 // renderer for a cross-site navigation), rather than WebKit navigations.
2369 //
2370 // We use the following heuristic to decide whether to fork a new page in its
2371 // own process:
2372 // The parent page must open a new tab to about:blank, set the new tab's
2373 // window.opener to null, and then redirect the tab to a cross-site URL using
2374 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462375 //
2376 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2377 // (see below).
[email protected]3d9689372009-09-10 04:29:172378 bool is_fork =
2379 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582380 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172381 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522382 historyBackListCount() < 1 &&
2383 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172384 // The parent page must have set the child's window.opener to null before
2385 // redirecting to the desired URL.
2386 frame->opener() == NULL &&
2387 // Must be a top-level frame.
2388 frame->parent() == NULL &&
2389 // Must not have issued the request from this page.
2390 is_content_initiated &&
2391 // Must be targeted at the current tab.
2392 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2393 // Must be a JavaScript navigation, which appears as "other".
2394 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462395
[email protected]f92ce2b2012-03-06 18:02:592396 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172397 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152398 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172399 return WebKit::WebNavigationPolicyIgnore;
2400 }
2401
2402 return default_policy;
2403}
2404
[email protected]310ebd6302011-10-10 19:06:282405bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492406 WebFrame* frame, const WebURLRequest& request) {
2407 // We allow WebKit to think that everything can be handled even though
2408 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342409 return true;
2410}
2411
[email protected]310ebd6302011-10-10 19:06:282412WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492413 WebFrame* frame, const WebURLRequest& request) {
2414 NOTREACHED(); // Since we said we can handle all requests.
2415 return WebURLError();
2416}
2417
[email protected]310ebd6302011-10-10 19:06:282418WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492419 WebFrame* frame, const WebURLRequest& request) {
2420 WebURLError error;
2421 error.domain = WebString::fromUTF8(net::kErrorDomain);
2422 error.reason = net::ERR_ABORTED;
2423 error.unreachableURL = request.url();
2424 return error;
[email protected]7b7a7dc2009-10-19 02:23:342425}
2426
[email protected]310ebd6302011-10-10 19:06:282427void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492428 WebFrame*, const WebURLError&) {
2429 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342430}
2431
[email protected]310ebd6302011-10-10 19:06:282432void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432433 const WebKit::WebFormElement& form) {
2434 // Some login forms have onSubmit handlers that put a hash of the password
2435 // into a hidden field and then clear the password. (Issue 28910.)
2436 // This method gets called before any of those handlers run, so save away
2437 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072438 DocumentState* document_state =
2439 DocumentState::FromDataSource(frame->dataSource());
2440 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432441 PasswordFormDomManager::CreatePasswordForm(form));
2442}
2443
[email protected]310ebd6302011-10-10 19:06:282444void RenderViewImpl::willSubmitForm(WebFrame* frame,
2445 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072446 DocumentState* document_state =
2447 DocumentState::FromDataSource(frame->provisionalDataSource());
2448 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172449
[email protected]2905f742011-10-13 03:51:582450 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2451 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172452
2453 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352454 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072455 document_state->set_searchable_form_url(web_searchable_form_data.url());
2456 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212457 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432458 PasswordForm* password_form_data =
2459 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072460 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432461
[email protected]098c95cb2011-04-28 16:49:012462 // In order to save the password that the user actually typed and not one
2463 // that may have gotten transformed by the site prior to submit, recover it
2464 // from the form contents already stored by |willSendSubmitEvent| into the
2465 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2466 // which is what we're storing into now.)
2467 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072468 DocumentState* old_document_state =
2469 DocumentState::FromDataSource(frame->dataSource());
2470 if (old_document_state) {
2471 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432472 if (old_form_data && old_form_data->action == password_form_data->action)
2473 password_form_data->password_value = old_form_data->password_value;
2474 }
2475 }
[email protected]3d9689372009-09-10 04:29:172476
[email protected]2a5b1732011-04-01 23:55:552477 FOR_EACH_OBSERVER(
2478 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172479}
2480
[email protected]310ebd6302011-10-10 19:06:282481void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172482 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2483 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382484 FOR_EACH_OBSERVER(
2485 RenderViewObserver, observers_,
2486 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172487}
2488
[email protected]310ebd6302011-10-10 19:06:282489void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382490 FOR_EACH_OBSERVER(
2491 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172492}
2493
[email protected]310ebd6302011-10-10 19:06:282494void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172495 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152496 if (!frame->parent()) {
2497 WebDataSource* ds = frame->provisionalDataSource();
2498 // If there's no provisional data source, it's a reference fragment
2499 // navigation.
2500 completed_client_redirect_src_ = Referrer(
[email protected]b9fd01ba2012-02-28 01:50:402501 from, ds ? GetReferrerPolicyFromRequest(ds->request()) :
[email protected]445e1042011-12-03 21:03:152502 frame->referrerPolicy());
2503 }
[email protected]eb0bff942011-04-07 22:08:382504 FOR_EACH_OBSERVER(
2505 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172506}
2507
[email protected]310ebd6302011-10-10 19:06:282508void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072509 DocumentState* document_state = DocumentState::FromDataSource(ds);
2510 if (!document_state) {
2511 document_state = new DocumentState;
2512 ds->setExtraData(document_state);
2513 }
2514
[email protected]3d9689372009-09-10 04:29:172515 // The rest of RenderView assumes that a WebDataSource will always have a
2516 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072517 bool content_initiated = !pending_navigation_params_.get();
2518 if (content_initiated)
2519 document_state->set_navigation_state(
2520 NavigationState::CreateContentInitiated());
2521 else
2522 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512523
[email protected]007733c2011-11-17 00:34:072524 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512525 // navigating from a page that used prefetching using a link on that
2526 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072527 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512528 // this value appropriately.
2529 // TODO(gavinp): catch the important case of navigation in a new
2530 // renderer process.
2531 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302532 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522533 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512534 const GURL referrer(
2535 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2536 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072537 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512538 old_frame->dataSource())->was_prefetcher()) {
2539 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2540 WebDataSource* old_frame_ds = old_frame->dataSource();
2541 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072542 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512543 break;
2544 }
2545 }
2546 }
2547 }
2548 }
2549
[email protected]4c1b6f0b2010-02-07 16:38:182550 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522551 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512552 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182553 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072554 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182555 break;
2556 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072557 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182558 break;
2559 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072560 document_state->set_load_type(
2561 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182562 break;
2563 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072564 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182565 break;
2566 }
2567 }
[email protected]fa7b6b542009-11-03 05:02:302568
[email protected]946a0032011-03-31 18:42:282569 FOR_EACH_OBSERVER(
2570 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172571}
2572
[email protected]007733c2011-11-17 00:34:072573void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2574 DocumentState* document_state) {
2575 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2576
2577 if (document_state->request_time().is_null())
2578 document_state->set_request_time(params.request_time);
2579
2580 // A navigation resulting from loading a javascript URL should not be treated
2581 // as a browser initiated event. Instead, we want it to look as if the page
2582 // initiated any load resulting from JS execution.
2583 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2584 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2585 params.page_id,
2586 params.pending_history_list_offset,
2587 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482588 navigation_state->set_transferred_request_child_id(
2589 params.transferred_request_child_id);
2590 navigation_state->set_transferred_request_request_id(
2591 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072592 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2593 // We're doing a load of a page that was restored from the last session.
2594 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2595 // which can result in stale data for pages that are set to expire. We
2596 // explicitly override that by setting the policy here so that as
2597 // necessary we load from the network.
2598 document_state->set_cache_policy_override(
2599 WebURLRequest::UseProtocolCachePolicy);
2600 }
2601 document_state->set_navigation_state(navigation_state);
2602 } else {
2603 document_state->set_navigation_state(
2604 NavigationState::CreateContentInitiated());
2605 }
2606
2607 if (IsReload(params))
2608 document_state->set_load_type(DocumentState::RELOAD);
2609 else if (!params.state.empty())
2610 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2611 else
2612 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2613
2614 pending_navigation_params_.reset();
2615}
2616
[email protected]310ebd6302011-10-10 19:06:282617void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172618 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072619 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172620
[email protected]3d9689372009-09-10 04:29:172621 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072622 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172623 double event_time = ds->triggeringEventTime();
2624 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072625 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172626 }
2627
[email protected]05c8e502010-08-15 15:13:522628 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072629 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522630
[email protected]3d9689372009-09-10 04:29:172631 bool is_top_most = !frame->parent();
2632 if (is_top_most) {
2633 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132634 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172635
2636 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152637 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172638 } else if (frame->parent()->isLoading()) {
2639 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002640 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072641 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582642 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172643 }
2644
[email protected]28685da92011-02-07 21:49:172645 FOR_EACH_OBSERVER(
2646 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2647
[email protected]3d9689372009-09-10 04:29:172648 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592649 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262650 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172651}
2652
[email protected]310ebd6302011-10-10 19:06:282653void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2654 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172655 if (frame->parent())
2656 return;
2657 // Received a redirect on the main frame.
2658 WebDataSource* data_source = frame->provisionalDataSource();
2659 if (!data_source) {
2660 // Should only be invoked when we have a data source.
2661 NOTREACHED();
2662 return;
2663 }
2664 std::vector<GURL> redirects;
2665 GetRedirectChain(data_source, &redirects);
2666 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512667 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592668 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172669 }
2670}
2671
[email protected]310ebd6302011-10-10 19:06:282672void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2673 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172674 // Notify the browser that we failed a provisional load with an error.
2675 //
2676 // Note: It is important this notification occur before DidStopLoading so the
2677 // SSL manager can react to the provisional load failure before being
2678 // notified the load stopped.
2679 //
2680 WebDataSource* ds = frame->provisionalDataSource();
2681 DCHECK(ds);
2682
2683 const WebURLRequest& failed_request = ds->request();
2684
[email protected]28685da92011-02-07 21:49:172685 FOR_EACH_OBSERVER(
2686 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2687
[email protected]3d9689372009-09-10 04:29:172688 bool show_repost_interstitial =
2689 (error.reason == net::ERR_CACHE_MISS &&
2690 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582691
2692 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2693 params.frame_id = frame->identifier();
2694 params.is_main_frame = !frame->parent();
2695 params.error_code = error.reason;
2696 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2697 failed_request,
2698 error,
2699 NULL,
2700 &params.error_description);
2701 params.url = error.unreachableURL;
2702 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172703 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582704 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172705
2706 // Don't display an error page if this is simply a cancelled load. Aside
2707 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2708 if (error.reason == net::ERR_ABORTED)
2709 return;
[email protected]b553edd52012-01-10 12:15:232710 // Don't display an error message if the request was handled by an
2711 // external protocol handler.
2712 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2713 return;
[email protected]3d9689372009-09-10 04:29:172714
2715 // Make sure we never show errors in view source mode.
2716 frame->enableViewSourceMode(false);
2717
[email protected]007733c2011-11-17 00:34:072718 DocumentState* document_state = DocumentState::FromDataSource(ds);
2719 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172720
2721 // If this is a failed back/forward/reload navigation, then we need to do a
2722 // 'replace' load. This is necessary to avoid messing up session history.
2723 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2724 // as session history is concerned.
2725 //
2726 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2727 // the page id.
2728 //
2729 bool replace =
2730 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582731 navigation_state->transition_type() ==
2732 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172733
2734 // If we failed on a browser initiated request, then make sure that our error
2735 // page load is regarded as the same browser initiated request.
2736 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072737 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2738 pending_navigation_params_->page_id =
2739 navigation_state->pending_page_id();
2740 pending_navigation_params_->pending_history_list_offset =
2741 navigation_state->pending_history_list_offset();
2742 pending_navigation_params_->transition =
2743 navigation_state->transition_type();
2744 pending_navigation_params_->request_time =
2745 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172746 }
2747
2748 // Provide the user with a more helpful error page?
2749 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2750 return;
2751
2752 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082753 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172754}
2755
[email protected]310ebd6302011-10-10 19:06:282756void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172757 WebFrame* frame, const char* data, size_t data_len,
2758 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072759 DocumentState* document_state =
2760 DocumentState::FromDataSource(frame->dataSource());
2761 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172762}
2763
[email protected]310ebd6302011-10-10 19:06:282764void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2765 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072766 DocumentState* document_state =
2767 DocumentState::FromDataSource(frame->dataSource());
2768 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172769
[email protected]007733c2011-11-17 00:34:072770 if (document_state->commit_load_time().is_null())
2771 document_state->set_commit_load_time(Time::Now());
2772
[email protected]3d9689372009-09-10 04:29:172773 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202774 // When we perform a new navigation, we need to update the last committed
2775 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172776 UpdateSessionHistory(frame);
2777
2778 // We bump our Page ID to correspond with the new session history entry.
2779 page_id_ = next_page_id_++;
2780
[email protected]69ddf852012-02-21 23:21:312781 // Don't update history_page_ids_ (etc) for about:swappedout, since we
2782 // don't want to forget the entry that was there, and since we will
2783 // never come back to about:swappedout. Note that we have to call
2784 // UpdateSessionHistory and update page_id_ even in this case, so that
2785 // the current entry gets a state update and so that we don't send a
2786 // state update to the wrong entry when we swap back in.
2787 if (GetLoadingUrl(frame) != GURL("about:swappedout")) {
2788 // Advance our offset in session history, applying the length limit.
2789 // There is now no forward history.
2790 history_list_offset_++;
2791 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2792 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
2793 history_list_length_ = history_list_offset_ + 1;
2794 history_page_ids_.resize(history_list_length_, -1);
2795 history_page_ids_[history_list_offset_] = page_id_;
2796 }
[email protected]3d9689372009-09-10 04:29:172797 } else {
2798 // Inspect the navigation_state on this frame to see if the navigation
2799 // corresponds to a session history navigation... Note: |frame| may or
2800 // may not be the toplevel frame, but for the case of capturing session
2801 // history, the first committed frame suffices. We keep track of whether
2802 // we've seen this commit before so that only capture session history once
2803 // per navigation.
2804 //
2805 // Note that we need to check if the page ID changed. In the case of a
2806 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2807 // previous URL and the current page ID, which would be wrong.
2808 if (navigation_state->pending_page_id() != -1 &&
2809 navigation_state->pending_page_id() != page_id_ &&
2810 !navigation_state->request_committed()) {
2811 // This is a successful session history navigation!
2812 UpdateSessionHistory(frame);
2813 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002814
2815 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032816
2817 // If the history list is valid, our list of page IDs should be correct.
2818 DCHECK(history_list_length_ <= 0 ||
2819 history_list_offset_ < 0 ||
2820 history_list_offset_ >= history_list_length_ ||
2821 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172822 }
2823 }
2824
[email protected]28685da92011-02-07 21:49:172825 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2826 DidCommitProvisionalLoad(frame, is_new_navigation));
2827
[email protected]3d9689372009-09-10 04:29:172828 // Remember that we've already processed this request, so we don't update
2829 // the session history again. We do this regardless of whether this is
2830 // a session history navigation, because if we attempted a session history
2831 // navigation without valid HistoryItem state, WebCore will think it is a
2832 // new navigation.
2833 navigation_state->set_request_committed(true);
2834
2835 UpdateURL(frame);
2836
2837 // If this committed load was initiated by a client redirect, we're
2838 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152839 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172840
2841 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272842 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172843}
2844
[email protected]310ebd6302011-10-10 19:06:282845void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102846 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2847 DidClearWindowObject(frame));
2848
[email protected]b6cb3a842011-06-24 18:28:412849 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212850 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252851 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2852 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272853 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172854 }
[email protected]766a7082012-02-03 23:39:152855
2856 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
2857 if (!dom_automation_controller_.get())
2858 dom_automation_controller_.reset(new DomAutomationController());
2859 dom_automation_controller_->set_message_sender(
2860 static_cast<content::RenderView*>(this));
2861 dom_automation_controller_->set_routing_id(routing_id());
2862 dom_automation_controller_->BindToJavascript(frame,
2863 "domAutomationController");
2864 }
[email protected]3d9689372009-09-10 04:29:172865}
2866
[email protected]310ebd6302011-10-10 19:06:282867void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172868 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412869 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252870 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272871 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172872 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2873 }
[email protected]e48869a2011-04-01 19:56:032874
2875 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2876 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172877}
2878
[email protected]310ebd6302011-10-10 19:06:282879void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2880 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462881 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172882
2883 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272884 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172885}
2886
[email protected]310ebd6302011-10-10 19:06:282887void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132888 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2889 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582890}
2891
[email protected]310ebd6302011-10-10 19:06:282892void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172893 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072894 DocumentState* document_state = DocumentState::FromDataSource(ds);
2895 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172896
[email protected]622474d2010-11-04 09:21:082897 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172898
[email protected]28685da92011-02-07 21:49:172899 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2900 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172901
2902 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272903 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172904}
2905
[email protected]310ebd6302011-10-10 19:06:282906void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082907 if (webview()->mainFrame() == frame) {
2908 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2909 page_id_));
2910 }
[email protected]3d9689372009-09-10 04:29:172911}
2912
[email protected]310ebd6302011-10-10 19:06:282913void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312914 WebDataSource* ds = frame->dataSource();
2915 DCHECK(ds);
2916
2917
[email protected]28685da92011-02-07 21:49:172918 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312919
2920 const WebURLRequest& failed_request = ds->request();
2921 string16 error_description;
2922 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2923 failed_request,
2924 error,
2925 NULL,
2926 &error_description);
2927 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2928 frame->identifier(),
2929 failed_request.url(),
2930 !frame->parent(),
2931 error.reason,
2932 error_description));
[email protected]3d9689372009-09-10 04:29:172933}
2934
[email protected]310ebd6302011-10-10 19:06:282935void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172936 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072937 DocumentState* document_state = DocumentState::FromDataSource(ds);
2938 if (document_state->finish_load_time().is_null())
2939 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412940
[email protected]676126f72011-01-15 00:03:512941 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172942
[email protected]1a55c5be2011-11-29 11:36:312943 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2944 frame->identifier(),
2945 ds->request().url(),
2946 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172947}
2948
[email protected]310ebd6302011-10-10 19:06:282949void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172950 WebFrame* frame, bool is_new_navigation) {
2951 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072952 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172953 // update the ExtraData on the datasource so that others who read the
2954 // ExtraData will get the new NavigationState. Similarly, if we did not
2955 // initiate this navigation, then we need to take care to reset any pre-
2956 // existing navigation state to a content-initiated navigation state.
2957 // DidCreateDataSource conveniently takes care of this for us.
2958 didCreateDataSource(frame, frame->dataSource());
2959
[email protected]007733c2011-11-17 00:34:072960 DocumentState* document_state =
2961 DocumentState::FromDataSource(frame->dataSource());
2962 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092963 new_state->set_was_within_same_page(true);
2964
[email protected]3d9689372009-09-10 04:29:172965 didCommitProvisionalLoad(frame, is_new_navigation);
2966
[email protected]750fcf872011-08-03 23:10:472967 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2968 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172969}
2970
[email protected]310ebd6302011-10-10 19:06:282971void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312972 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592973}
2974
[email protected]310ebd6302011-10-10 19:06:282975void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172976 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2977 // Ignore
2978}
2979
[email protected]310ebd6302011-10-10 19:06:282980void RenderViewImpl::willSendRequest(WebFrame* frame,
2981 unsigned identifier,
2982 WebURLRequest& request,
2983 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302984 WebFrame* top_frame = frame->top();
2985 if (!top_frame)
2986 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512987 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2988 WebDataSource* top_data_source = top_frame->dataSource();
2989 WebDataSource* data_source =
2990 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222991
[email protected]78d5cfe2011-02-04 08:43:222992 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032993 GURL new_url;
2994 if (content::GetContentClient()->renderer()->WillSendRequest(
2995 frame, request_url, &new_url)) {
2996 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222997 }
2998
[email protected]2905f742011-10-13 03:51:582999 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073000 DocumentState* document_state = DocumentState::FromDataSource(data_source);
3001 NavigationState* navigation_state = document_state->navigation_state();
3002 if (document_state) {
3003 if (document_state->is_cache_policy_override_set())
3004 request.setCachePolicy(document_state->cache_policy_override());
3005 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:303006 }
[email protected]8a3125a712010-08-09 18:58:513007
[email protected]91043a8232011-11-04 16:41:193008 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:063009 new RequestExtraData(frame->referrerPolicy(),
3010 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193011 frame->identifier(),
3012 frame->parent() == top_frame,
3013 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:483014 transition_type,
3015 navigation_state->transferred_request_child_id(),
3016 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573017
[email protected]007733c2011-11-17 00:34:073018 DocumentState* top_document_state =
3019 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573020 // TODO(gavinp): separate out prefetching and prerender field trials
3021 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073022 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:573023 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
3024 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:073025 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513026
[email protected]3d9689372009-09-10 04:29:173027 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133028 request.setHasUserGesture(frame->isProcessingUserGesture());
3029
[email protected]0a8db0d2011-04-13 15:15:403030 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133031 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173032}
3033
[email protected]310ebd6302011-10-10 19:06:283034void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173035 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493036
[email protected]3d9689372009-09-10 04:29:173037 // Only do this for responses that correspond to a provisional data source
3038 // of the top-most frame. If we have a provisional data source, then we
3039 // can't have any sub-resources yet, so we know that this response must
3040 // correspond to a frame load.
3041 if (!frame->provisionalDataSource() || frame->parent())
3042 return;
3043
3044 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083045 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173046 if (frame->isViewSourceModeEnabled())
3047 return;
3048
[email protected]007733c2011-11-17 00:34:073049 DocumentState* document_state =
3050 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083051 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533052
[email protected]972ebdff2010-06-10 22:59:073053 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073054 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3055 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403056 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3057 if (extra_data) {
3058 document_state->set_npn_negotiated_protocol(
3059 extra_data->npn_negotiated_protocol());
3060 }
[email protected]007733c2011-11-17 00:34:073061 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573062 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073063 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3064 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093065 // Whether or not the http status code actually corresponds to an error is
3066 // only checked when the page is done loading, if |use_error_page| is
3067 // still true.
[email protected]007733c2011-11-17 00:34:073068 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173069}
3070
[email protected]310ebd6302011-10-10 19:06:283071void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173072 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073073 DocumentState* document_state =
3074 DocumentState::FromDataSource(frame->dataSource());
3075 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173076 return;
3077
[email protected]7bfc153f2011-09-23 22:00:203078 // Do not show error page when DevTools is attached.
3079 if (devtools_agent_->IsAttached())
3080 return;
3081
[email protected]06333afe2011-02-24 14:55:093082 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073083 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083084 if (http_status_code == 404) {
3085 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413086 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173087
[email protected]b6cb3a842011-06-24 18:28:413088 const GURL& error_page_url =
3089 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093090 if (error_page_url.is_valid()) {
3091 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473092 original_error.domain = "http";
3093 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413094 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173095
[email protected]007733c2011-11-17 00:34:073096 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093097 new AltErrorPageResourceFetcher(
3098 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083099 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3100 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093101 return;
3102 }
3103 }
[email protected]3d9689372009-09-10 04:29:173104
[email protected]e6a2ce52011-10-08 01:40:133105 std::string error_domain;
3106 if (content::GetContentClient()->renderer()->HasErrorPage(
3107 http_status_code, &error_domain)) {
3108 WebURLError error;
3109 error.unreachableURL = frame->document().url();
3110 error.domain = WebString::fromUTF8(error_domain);
3111 error.reason = http_status_code;
3112
3113 LoadNavigationErrorPage(
3114 frame, frame->dataSource()->request(), error, std::string(), true);
3115 }
[email protected]3d9689372009-09-10 04:29:173116}
3117
[email protected]310ebd6302011-10-10 19:06:283118void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173119 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3120 // Ignore
3121}
3122
[email protected]310ebd6302011-10-10 19:06:283123void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173124 WebFrame* frame, const WebURLRequest& request,
3125 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003126 // The recipients of this message have no use for data: URLs: they don't
3127 // affect the page's insecure content list and are not in the disk cache. To
3128 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3129 // filter them out here.
3130 GURL url(request.url());
3131 if (url.SchemeIs("data"))
3132 return;
3133
[email protected]3d9689372009-09-10 04:29:173134 // Let the browser know we loaded a resource from the memory cache. This
3135 // message is needed to display the correct SSL indicators.
3136 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3137 routing_id_,
[email protected]84703292011-10-28 20:44:003138 url,
[email protected]70435962011-08-02 20:13:283139 response.securityInfo(),
3140 request.httpMethod().utf8(),
3141 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173142}
3143
[email protected]310ebd6302011-10-10 19:06:283144void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293145 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3146}
3147
[email protected]310ebd6302011-10-10 19:06:283148void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023149 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293150 Send(new ViewHostMsg_DidRunInsecureContent(
3151 routing_id_,
[email protected]92771112011-01-20 00:13:023152 origin.toString().utf8(),
3153 target));
[email protected]e3d60e5d2009-09-25 21:08:293154}
3155
[email protected]310ebd6302011-10-10 19:06:283156void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033157 webkit_glue::WebURLLoaderImpl* loader_impl =
3158 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3159 loader_impl->UpdateRoutingId(routing_id_);
3160}
3161
[email protected]310ebd6302011-10-10 19:06:283162void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173163 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3164}
3165
[email protected]310ebd6302011-10-10 19:06:283166void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3167 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583168 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283169 int world_id) {
[email protected]5bc10932011-09-21 21:03:303170 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583171 frame, context, extension_group, world_id);
3172}
3173
3174void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3175 v8::Handle<v8::Context> context,
3176 int world_id) {
3177 content::GetContentClient()->renderer()->DidCreateScriptContext(
3178 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283179}
3180
[email protected]310ebd6302011-10-10 19:06:283181void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3182 v8::Handle<v8::Context> context,
3183 int world_id) {
[email protected]5bc10932011-09-21 21:03:303184 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3185 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283186}
3187
[email protected]310ebd6302011-10-10 19:06:283188void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073189 // We don't always want to send the change messages over IPC, only if we've
3190 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3191 // message.
3192 if (!send_preferred_size_changes_ || !webview())
3193 return;
3194
[email protected]705243f2010-05-05 19:58:073195 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3196 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533197
3198 // In the presence of zoom, these sizes are still reported as if unzoomed,
3199 // so we need to adjust.
3200 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3201 size.set_width(static_cast<int>(size.width() * zoom_factor));
3202 size.set_height(static_cast<int>(size.height() * zoom_factor));
3203
[email protected]705243f2010-05-05 19:58:073204 if (size == preferred_size_)
3205 return;
[email protected]c27324b2009-11-19 22:44:293206
[email protected]705243f2010-05-05 19:58:073207 preferred_size_ = size;
3208 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3209 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173210}
3211
[email protected]273558fb2012-01-12 15:03:513212void RenderViewImpl::EnsureMediaStreamImpl() {
3213#if defined(ENABLE_P2P_APIS)
3214 if (!p2p_socket_dispatcher_)
3215 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3216#endif
3217
[email protected]5b87e782012-02-09 18:19:323218#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513219 if (!media_stream_dispatcher_)
3220 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3221
3222 if (!media_stream_impl_.get()) {
3223 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3224 media_stream_impl_ = new MediaStreamImpl(
3225 media_stream_dispatcher_,
3226 p2p_socket_dispatcher_,
3227 RenderThreadImpl::current()->video_capture_impl_manager(),
3228 factory);
3229 }
[email protected]5b87e782012-02-09 18:19:323230#endif
[email protected]273558fb2012-01-12 15:03:513231}
3232
[email protected]310ebd6302011-10-10 19:06:283233void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3234 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313235 if (webview()->mainFrame() != frame)
3236 return;
3237 WebView* frameView = frame->view();
3238 if (!frameView)
3239 return;
3240
3241 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3242 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3243
3244 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3245 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3246 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3247 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3248
3249 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3250 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3251 }
3252}
3253
[email protected]310ebd6302011-10-10 19:06:283254void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313255 WebSize offset = frame->scrollOffset();
3256 WebSize minimum_offset = frame->minimumScrollOffset();
3257 WebSize maximum_offset = frame->maximumScrollOffset();
3258
3259 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3260 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3261
3262 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3263 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3264 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3265 routing_id_, is_pinned_to_left, is_pinned_to_right));
3266
3267 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3268 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3269 }
3270}
3271
[email protected]310ebd6302011-10-10 19:06:283272void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493273 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313274
3275 if (webview()->mainFrame() == frame)
3276 UpdateScrollState(frame);
3277}
3278
[email protected]310ebd6302011-10-10 19:06:283279void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313280 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493281}
3282
[email protected]ea931252012-02-15 22:01:033283void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3284 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3285}
3286
[email protected]310ebd6302011-10-10 19:06:283287void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3288 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113289 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3290 if (!count)
3291 active_match_ordinal = 0;
3292
3293 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3294 routing_id_,
3295 request_id,
3296 count,
3297 gfx::Rect(),
3298 active_match_ordinal,
3299 final_update);
3300
[email protected]8922e1f2009-10-03 05:01:263301 // If we have a message that has been queued up, then we should just replace
3302 // it. The ACK from the browser will make sure it gets sent when the browser
3303 // wants it.
3304 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263305 queued_find_reply_message_.reset(msg);
3306 } else {
3307 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113308 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263309 }
3310}
3311
[email protected]310ebd6302011-10-10 19:06:283312void RenderViewImpl::reportFindInPageSelection(int request_id,
3313 int active_match_ordinal,
3314 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263315 // Send the search result over to the browser process.
3316 Send(new ViewHostMsg_Find_Reply(routing_id_,
3317 request_id,
3318 -1,
3319 selection_rect,
3320 active_match_ordinal,
3321 false));
3322}
3323
[email protected]310ebd6302011-10-10 19:06:283324void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223325 WebFrame* frame,
3326 WebFileSystem::Type type,
3327 long long size,
[email protected]d275d7a2010-11-03 01:34:493328 bool create,
[email protected]2b06a992010-08-21 05:48:223329 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083330 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223331
[email protected]b6cb3a842011-06-24 18:28:413332 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563333 if (origin.isUnique()) {
3334 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083335 callbacks->didFail(WebKit::WebFileErrorAbort);
3336 return;
3337 }
[email protected]2b06a992010-08-21 05:48:223338
[email protected]c5a272d2010-09-27 18:37:083339 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3340 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493341 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223342}
3343
[email protected]310ebd6302011-10-10 19:06:283344void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403345 WebFrame* frame,
3346 WebStorageQuotaType type,
3347 WebStorageQuotaCallbacks* callbacks) {
3348 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413349 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563350 if (origin.isUnique()) {
3351 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403352 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3353 return;
3354 }
3355 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533356 GURL(origin.toString()),
3357 static_cast<quota::StorageType>(type),
3358 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403359}
3360
[email protected]310ebd6302011-10-10 19:06:283361void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403362 WebFrame* frame,
3363 WebStorageQuotaType type,
3364 unsigned long long requested_size,
3365 WebStorageQuotaCallbacks* callbacks) {
3366 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413367 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563368 if (origin.isUnique()) {
3369 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403370 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3371 return;
3372 }
3373 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533374 routing_id(), GURL(origin.toString()),
3375 static_cast<quota::StorageType>(type), requested_size,
3376 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403377}
3378
[email protected]8b5af492011-11-28 21:50:583379void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153380 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063381 string16 title = service.title();
3382 if (title.empty())
3383 title = webview()->mainFrame()->document().title();
3384
[email protected]8b5af492011-11-28 21:50:583385 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3386 service.action(),
3387 service.type(),
3388 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063389 title,
[email protected]8b5af492011-11-28 21:50:583390 service.disposition()));
3391}
3392
[email protected]ffc8bed2012-01-21 01:23:153393void RenderViewImpl::dispatchIntent(
3394 WebFrame* frame, const WebIntentRequest& intentRequest) {
3395 webkit_glue::WebIntentData intent_data(intentRequest.intent());
3396 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583397 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153398 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583399}
3400
[email protected]18d5be92011-07-25 18:00:193401// WebKit::WebPageSerializerClient implementation ------------------------------
3402
[email protected]310ebd6302011-10-10 19:06:283403void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193404 const WebURL& frame_url,
3405 const WebCString& data,
3406 WebPageSerializerClient::PageSerializationStatus status) {
3407 Send(new ViewHostMsg_SendSerializedHtmlData(
3408 routing_id(),
3409 frame_url,
3410 data.data(),
3411 static_cast<int32>(status)));
3412}
3413
[email protected]a2ef54c2011-10-10 16:20:313414// content::RenderView implementation ------------------------------------------
3415
[email protected]310ebd6302011-10-10 19:06:283416bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313417 return RenderWidget::Send(message);
3418}
3419
[email protected]9f76c1e2012-03-05 15:15:583420int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:313421 return routing_id_;
3422}
3423
[email protected]310ebd6302011-10-10 19:06:283424int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313425 return page_id_;
3426}
3427
[email protected]310ebd6302011-10-10 19:06:283428gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313429 return size();
3430}
3431
[email protected]310ebd6302011-10-10 19:06:283432gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313433 return host_window();
3434}
3435
[email protected]310ebd6302011-10-10 19:06:283436WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313437 return webkit_preferences_;
3438}
3439
[email protected]310ebd6302011-10-10 19:06:283440WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313441 return webview();
3442}
3443
[email protected]310ebd6302011-10-10 19:06:283444WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313445 if (!webview())
3446 return WebNode();
3447 WebFrame* focused_frame = webview()->focusedFrame();
3448 if (focused_frame) {
3449 WebDocument doc = focused_frame->document();
3450 if (!doc.isNull())
3451 return doc.focusedNode();
3452 }
3453
3454 return WebNode();
3455}
3456
[email protected]310ebd6302011-10-10 19:06:283457WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313458 return context_menu_node_;
3459}
3460
[email protected]310ebd6302011-10-10 19:06:283461bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313462 bool is_editable_node = false;
3463 if (!node.isNull()) {
3464 if (node.isContentEditable()) {
3465 is_editable_node = true;
3466 } else if (node.isElementNode()) {
3467 is_editable_node =
3468 node.toConst<WebElement>().isTextFormControlElement();
3469 }
3470 }
3471 return is_editable_node;
3472}
3473
[email protected]310ebd6302011-10-10 19:06:283474WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313475 WebKit::WebFrame* frame,
3476 const webkit::WebPluginInfo& info,
3477 const WebKit::WebPluginParams& params) {
3478 bool pepper_plugin_was_registered = false;
3479 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3480 pepper_delegate_.CreatePepperPluginModule(info,
3481 &pepper_plugin_was_registered));
3482 if (pepper_plugin_was_registered) {
3483 if (!pepper_module)
3484 return NULL;
3485 return new webkit::ppapi::WebPluginImpl(
3486 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3487 }
3488
[email protected]34b27e442012-01-20 20:07:413489#if defined(USE_AURA)
3490 return NULL;
3491#else
[email protected]a2ef54c2011-10-10 16:20:313492 return new webkit::npapi::WebPluginImpl(
3493 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413494#endif
[email protected]a2ef54c2011-10-10 16:20:313495}
3496
[email protected]310ebd6302011-10-10 19:06:283497void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3498 const string16& jscript,
3499 int id,
3500 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313501 v8::Handle<v8::Value> result;
3502 WebFrame* web_frame = GetChildFrame(frame_xpath);
3503 if (web_frame)
3504 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3505 if (notify_result) {
3506 ListValue list;
3507 if (!result.IsEmpty() && web_frame) {
3508 v8::HandleScope handle_scope;
3509 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3510 v8::Context::Scope context_scope(context);
3511 V8ValueConverterImpl converter;
3512 converter.set_allow_date(true);
3513 converter.set_allow_regexp(true);
3514 list.Set(0, converter.FromV8Value(result, context));
3515 } else {
3516 list.Set(0, Value::CreateNullValue());
3517 }
3518 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3519 }
3520}
3521
[email protected]310ebd6302011-10-10 19:06:283522bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313523 return (!send_preferred_size_changes_ ||
3524 (disable_scrollbars_size_limit_.width() <= width ||
3525 disable_scrollbars_size_limit_.height() <= height));
3526}
3527
[email protected]310ebd6302011-10-10 19:06:283528int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313529 return enabled_bindings_;
3530}
3531
[email protected]310ebd6302011-10-10 19:06:283532bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313533 return send_content_state_immediately_;
3534}
3535
[email protected]310ebd6302011-10-10 19:06:283536float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313537 return filtered_time_per_frame();
3538}
3539
[email protected]310ebd6302011-10-10 19:06:283540void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3541 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313542 showContextMenu(frame, data);
3543}
3544
[email protected]310ebd6302011-10-10 19:06:283545WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313546 return visibilityState();
3547}
3548
[email protected]310ebd6302011-10-10 19:06:283549void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3550 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313551 return runModalAlertDialog(frame, message);
3552}
3553
[email protected]310ebd6302011-10-10 19:06:283554void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313555 WebKit::WebFrame* frame,
3556 const WebKit::WebURLRequest& request,
3557 WebKit::WebNavigationPolicy policy) {
3558 loadURLExternally(frame, request, policy);
3559}
3560
3561// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513562
[email protected]310ebd6302011-10-10 19:06:283563webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533564 const FilePath& file_path,
3565 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203566 if (!PluginChannelHost::IsListening()) {
3567 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593568 return NULL;
[email protected]94752ee2012-02-10 10:38:203569 }
[email protected]f103ab72009-09-02 17:10:593570
[email protected]00c39612010-03-06 02:53:283571 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463572 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323573#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223574 return webkit::npapi::WebPluginDelegateImpl::Create(
3575 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093576#else
[email protected]7398dcc2011-09-06 21:40:323577 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223578 NOTIMPLEMENTED();
3579 return NULL;
[email protected]7b6616f2010-01-14 18:07:553580#endif
[email protected]f103ab72009-09-02 17:10:593581 }
3582
[email protected]4e0616e2010-05-28 14:55:533583 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593584}
3585
[email protected]310ebd6302011-10-10 19:06:283586void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033587#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273588 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593589#endif
3590}
3591
[email protected]310ebd6302011-10-10 19:06:283592void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033593#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273594 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593595#endif
3596 CleanupWindowInPluginMoves(window);
3597}
3598
[email protected]310ebd6302011-10-10 19:06:283599void RenderViewImpl::DidMovePlugin(
3600 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593601 SchedulePluginMove(move);
3602}
3603
[email protected]310ebd6302011-10-10 19:06:283604void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593605 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523606 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593607}
3608
[email protected]310ebd6302011-10-10 19:06:283609void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593610 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523611 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593612}
3613
[email protected]310ebd6302011-10-10 19:06:283614WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513615 return &cookie_jar_;
3616}
3617
[email protected]a9288f52011-11-17 05:18:163618void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073619 Send(new ViewHostMsg_MediaNotification(routing_id_,
3620 reinterpret_cast<int64>(player),
3621 player->hasVideo(),
3622 player->hasAudio(),
3623 true));
3624}
3625
[email protected]a9288f52011-11-17 05:18:163626void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073627 Send(new ViewHostMsg_MediaNotification(routing_id_,
3628 reinterpret_cast<int64>(player),
3629 player->hasVideo(),
3630 player->hasAudio(),
3631 false));
3632}
3633
[email protected]a9288f52011-11-17 05:18:163634void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073635 DidPause(player);
3636}
3637
[email protected]310ebd6302011-10-10 19:06:283638void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293639 if (!webview())
3640 return;
3641
[email protected]26aa0482009-09-30 16:55:273642 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173643 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293644 return;
[email protected]ca948a22009-06-25 19:36:173645
3646 Send(new ViewHostMsg_UpdateState(
3647 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293648}
3649
[email protected]310ebd6302011-10-10 19:06:283650void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363651 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003652 if (!frame)
3653 return;
[email protected]b781ff282011-08-20 06:19:363654
[email protected]e99ef6f2011-10-16 01:13:003655 string16 text;
3656 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:523657 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:003658
[email protected]3c8c74c2012-03-15 07:34:523659 if (pepper_delegate_.IsPluginFocused()) {
3660 pepper_delegate_.GetSurroundingText(&text, &range);
3661 offset = 0; // Pepper API does not support offset reporting.
3662 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:003663 } else {
[email protected]3c8c74c2012-03-15 07:34:523664 size_t location, length;
3665 if (!webview()->caretOrSelectionRange(&location, &length))
3666 return;
3667
3668 range = ui::Range(location, location + length);
3669
3670 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3671 // If current focused element is editable, we will send 100 more chars
3672 // before and after selection. It is for input method surrounding text
3673 // feature.
3674 if (location > kExtraCharsBeforeAndAfterSelection)
3675 offset = location - kExtraCharsBeforeAndAfterSelection;
3676 else
3677 offset = 0;
3678 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3679 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3680 if (!webrange.isNull())
3681 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3682 } else {
3683 offset = location;
3684 text = frame->selectionAsText();
3685 // http://crbug.com/101435
3686 // In some case, frame->selectionAsText() returned text's length is not
3687 // equal to the length returned from webview()->caretOrSelectionRange().
3688 // So we have to set the range according to text.length().
3689 range.set_end(range.start() + text.length());
3690 }
[email protected]b781ff282011-08-20 06:19:363691 }
3692
[email protected]b781ff282011-08-20 06:19:363693 // Sometimes we get repeated didChangeSelection calls from webkit when
3694 // the selection hasn't actually changed. We don't want to report these
3695 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003696 if (selection_text_offset_ != offset ||
3697 selection_range_ != range ||
3698 selection_text_ != text) {
3699 selection_text_ = text;
3700 selection_text_offset_ = offset;
3701 selection_range_ = range;
3702 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3703 }
[email protected]b781ff282011-08-20 06:19:363704}
3705
[email protected]310ebd6302011-10-10 19:06:283706GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3707 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553708 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293709 // If the URL that failed was secure, then the embedding web page was not
3710 // expecting a network attacker to be able to manipulate its contents. As
3711 // we fetch alternate error pages over HTTP, we would be allowing a network
3712 // attacker to manipulate the contents of the response if we tried to use
3713 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153714 return GURL();
initial.commit09911bf2008-07-26 23:55:293715 }
3716
3717 // Grab the base URL from the browser process.
3718 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153719 return GURL();
initial.commit09911bf2008-07-26 23:55:293720
3721 // Strip query params from the failed URL.
3722 GURL::Replacements remove_params;
3723 remove_params.ClearUsername();
3724 remove_params.ClearPassword();
3725 remove_params.ClearQuery();
3726 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553727 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503728 std::string spec_to_send = url_to_send.spec();
3729 // Notify link doctor of the url truncation by sending of "?" at the end.
3730 if (failed_url.has_query())
3731 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293732
3733 // Construct the query params to send to link doctor.
3734 std::string params(alternate_error_page_url_.query());
3735 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023736 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293737 params.append("&sourceid=chrome");
3738 params.append("&error=");
3739 switch (error_type) {
3740 case DNS_ERROR:
3741 params.append("dnserror");
3742 break;
3743
3744 case HTTP_404:
3745 params.append("http404");
3746 break;
3747
[email protected]5df266ac2008-10-15 19:50:133748 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333749 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133750 break;
3751
initial.commit09911bf2008-07-26 23:55:293752 default:
3753 NOTREACHED() << "unknown ErrorPageType";
3754 }
3755
3756 // OK, build the final url to return.
3757 GURL::Replacements link_doctor_params;
3758 link_doctor_params.SetQueryStr(params);
3759 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3760 return url;
3761}
3762
[email protected]310ebd6302011-10-10 19:06:283763GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593764 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3765 return GURL();
3766 else
3767 return creator_url_;
3768}
3769
[email protected]69ddf852012-02-21 23:21:313770GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
3771 WebDataSource* ds = frame->dataSource();
3772 if (ds->hasUnreachableURL())
3773 return ds->unreachableURL();
3774
3775 const WebURLRequest& request = ds->request();
3776 return request.url();
3777}
3778
[email protected]310ebd6302011-10-10 19:06:283779WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273780 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313781 web_ui_bindings_.reset(new WebUIBindings(
3782 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463783 }
[email protected]c50008512011-02-03 01:17:273784 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463785}
3786
[email protected]310ebd6302011-10-10 19:06:283787WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013788 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493789}
3790
[email protected]310ebd6302011-10-10 19:06:283791void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3792 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273793 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493794
[email protected]872542532011-06-23 00:43:163795 // Check if the plugin still exists in the document.
3796 if (main_frame->document().isPluginDocument() &&
3797 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493798 if (options.findNext) {
3799 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013800 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493801 } else {
[email protected]afdbd142010-07-10 08:01:233802 if (GetWebPluginFromPluginDocument()->startFind(
3803 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493804 } else {
[email protected]e7c58a32010-08-13 19:47:113805 // Send "no results".
3806 Send(new ViewHostMsg_Find_Reply(routing_id_,
3807 request_id,
3808 0,
3809 gfx::Rect(),
3810 0,
3811 true));
[email protected]24a7f3c2010-03-25 08:26:493812 }
3813 }
3814 return;
3815 }
3816
[email protected]b4bb2502009-10-01 22:35:273817 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273818 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293819 WebFrame* search_frame = focused_frame; // start searching focused frame.
3820
3821 bool multi_frame = (frame_after_main != main_frame);
3822
3823 // If we have multiple frames, we don't want to wrap the search within the
3824 // frame, so we check here if we only have main_frame in the chain.
3825 bool wrap_within_frame = !multi_frame;
3826
[email protected]b3f2b912009-04-09 16:18:523827 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293828 bool result = false;
3829
[email protected]7830da3e2009-11-06 16:27:263830 // If something is selected when we start searching it means we cannot just
3831 // increment the current match ordinal; we need to re-generate it.
3832 WebRange current_selection = focused_frame->selectionRange();
3833
initial.commit09911bf2008-07-26 23:55:293834 do {
[email protected]dd7daa82009-08-10 05:46:453835 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593836 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293837
3838 if (!result) {
3839 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223840 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293841
3842 // Find the next frame, but skip the invisible ones.
3843 do {
3844 // What is the next frame to search? (we might be going backwards). Note
3845 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593846 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273847 search_frame->traverseNext(true) :
3848 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453849 } while (!search_frame->hasVisibleContent() &&
3850 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293851
[email protected]884db412008-11-24 23:46:503852 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223853 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293854
3855 // If we have multiple frames and we have wrapped back around to the
3856 // focused frame, we need to search it once more allowing wrap within
3857 // the frame, otherwise it will report 'no match' if the focused frame has
3858 // reported matches, but no frames after the focused_frame contain a
3859 // match for the search word(s).
3860 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453861 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593862 request_id, search_text, options, true, // Force wrapping.
3863 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293864 }
3865 }
3866
[email protected]26aa0482009-09-30 16:55:273867 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293868 } while (!result && search_frame != focused_frame);
3869
[email protected]7830da3e2009-11-06 16:27:263870 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293871 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453872 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293873 } else {
3874 // If nothing is found, set result to "0 of 0", otherwise, set it to
3875 // "-1 of 1" to indicate that we found at least one item, but we don't know
3876 // yet what is active.
3877 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3878 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293879
[email protected]4f3dc372009-02-24 00:10:293880 // If we find no matches then this will be our last status update.
3881 // Otherwise the scoping effort will send more results.
3882 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293883
[email protected]4f3dc372009-02-24 00:10:293884 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403885 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593886 request_id,
[email protected]4f3dc372009-02-24 00:10:293887 match_count,
3888 selection_rect,
3889 ordinal,
3890 final_status_update));
initial.commit09911bf2008-07-26 23:55:293891
initial.commit09911bf2008-07-26 23:55:293892 // Scoping effort begins, starting with the mainframe.
3893 search_frame = main_frame;
3894
[email protected]dd7daa82009-08-10 05:46:453895 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293896
3897 do {
3898 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453899 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293900
3901 // We don't start another scoping effort unless at least one match has
3902 // been found.
3903 if (result) {
3904 // Start new scoping request. If the scoping function determines that it
3905 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453906 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593907 search_text,
3908 options,
initial.commit09911bf2008-07-26 23:55:293909 true); // reset the tickmarks
3910 }
3911
3912 // Iterate to the next frame. The frame will not necessarily scope, for
3913 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273914 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293915 } while (search_frame != main_frame);
3916 }
3917}
3918
[email protected]815dd9872011-11-23 18:40:303919void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493920 WebView* view = webview();
3921 if (!view)
3922 return;
3923
3924 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163925 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013926 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493927 return;
3928 }
3929
[email protected]815dd9872011-11-23 18:40:303930 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493931 if (clear_selection)
3932 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3933
3934 WebFrame* frame = view->mainFrame();
3935 while (frame) {
3936 frame->stopFinding(clear_selection);
3937 frame = frame->traverseNext(false);
3938 }
3939
[email protected]815dd9872011-11-23 18:40:303940 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493941 WebFrame* focused_frame = view->focusedFrame();
3942 if (focused_frame) {
3943 WebDocument doc = focused_frame->document();
3944 if (!doc.isNull()) {
3945 WebNode node = doc.focusedNode();
3946 if (!node.isNull())
3947 node.simulateClick();
3948 }
3949 }
3950 }
3951}
3952
[email protected]310ebd6302011-10-10 19:06:283953void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493954 // Check if there is any queued up request waiting to be sent.
3955 if (queued_find_reply_message_.get()) {
3956 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423957 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493958 }
3959}
3960
[email protected]54087fe2011-10-28 22:02:483961void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513962 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3963 return;
3964
[email protected]258d31122010-05-09 10:59:413965 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103966
[email protected]b75b8292010-10-01 07:28:253967 double old_zoom_level = webview()->zoomLevel();
3968 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483969 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253970 zoom_level = 0;
3971 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3972 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483973 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253974 } else {
3975 // Either the user hit the zoom factor limit and thus the zoom level is now
3976 // not a whole number, or a plugin changed it to a custom value. We want
3977 // to go to the next whole number so that the user can always get back to
3978 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483979 if ((old_zoom_level > 1 && zoom > 0) ||
3980 (old_zoom_level < 1 && zoom < 0)) {
3981 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253982 } else {
3983 // We're going towards 100%, so first go to the next whole number.
3984 zoom_level = static_cast<int>(old_zoom_level);
3985 }
3986 }
[email protected]b75b8292010-10-01 07:28:253987 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413988 zoomLevelChanged();
3989}
3990
3991void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3992 int zoom_center_x, int zoom_center_y) {
3993 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3994 kScalingIncrementForGesture);
3995}
3996
3997void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3998 int zoom_center_x,
3999 int zoom_center_y,
4000 float scaling_increment) {
4001 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4002 return;
4003
[email protected]c514d6372011-08-16 22:54:444004 double old_page_scale_factor = webview()->pageScaleFactor();
4005 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:484006 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444007 page_scale_factor = 1.0;
4008 } else {
4009 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414010 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444011 }
[email protected]47578fa02011-11-02 19:34:414012 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094013 webview()->setPageScaleFactor(page_scale_factor,
4014 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414015 }
[email protected]40bd6582009-12-04 23:49:514016}
4017
[email protected]310ebd6302011-10-10 19:06:284018void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174019 webview()->hidePopups();
4020 webview()->setZoomLevel(false, zoom_level);
4021 zoomLevelChanged();
4022}
4023
[email protected]310ebd6302011-10-10 19:06:284024void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4025 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544026 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294027}
4028
[email protected]310ebd6302011-10-10 19:06:284029void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274030 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294031}
4032
[email protected]310ebd6302011-10-10 19:06:284033void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274034 WebString no_encoding;
4035 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184036}
4037
[email protected]310ebd6302011-10-10 19:06:284038WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454039 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274040 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454041
4042 // xpath string can represent a frame deep down the tree (across multiple
4043 // frame DOMs).
4044 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4045 // should break into 2 xpaths
4046 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414047 std::vector<string16> xpaths;
4048 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454049
[email protected]26aa0482009-09-30 16:55:274050 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414051 for (std::vector<string16>::const_iterator i = xpaths.begin();
4052 frame && i != xpaths.end(); ++i) {
4053 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294054 }
4055
[email protected]dd7daa82009-08-10 05:46:454056 return frame;
initial.commit09911bf2008-07-26 23:55:294057}
4058
[email protected]310ebd6302011-10-10 19:06:284059void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4060 const string16& jscript,
4061 int id,
4062 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:534063 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294064}
4065
[email protected]310ebd6302011-10-10 19:06:284066void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4067 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414068 WebFrame* frame = GetChildFrame(frame_xpath);
4069 if (!frame)
[email protected]216813952011-05-19 22:21:264070 return;
[email protected]ae461542009-06-19 19:03:414071
[email protected]01cf589c2011-07-28 18:04:034072 frame->document().insertUserStyleSheet(
4073 WebString::fromUTF8(css),
4074 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484075}
4076
[email protected]310ebd6302011-10-10 19:06:284077void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094078 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:044079
4080 // Keep track of the total bindings accumulated in this process.
4081 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:294082}
4083
[email protected]310ebd6302011-10-10 19:06:284084void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4085 const std::string& value) {
[email protected]808bda52012-03-09 22:43:324086 if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI)
4087 GetWebUIBindings()->SetProperty(name, value);
4088 else
4089 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:294090}
4091
[email protected]310ebd6302011-10-10 19:06:284092void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4093 const gfx::Point& client_point,
4094 const gfx::Point& screen_point,
4095 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554096 WebDragOperation operation = webview()->dragTargetDragEnter(
4097 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554098 client_point,
4099 screen_point,
4100 ops);
4101
4102 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4103}
4104
[email protected]310ebd6302011-10-10 19:06:284105void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4106 const gfx::Point& screen_point,
4107 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554108 WebDragOperation operation = webview()->dragTargetDragOver(
4109 client_point,
4110 screen_point,
4111 ops);
4112
4113 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4114}
4115
[email protected]310ebd6302011-10-10 19:06:284116void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554117 webview()->dragTargetDragLeave();
4118}
4119
[email protected]310ebd6302011-10-10 19:06:284120void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
4121 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:554122 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:574123
4124 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554125}
4126
[email protected]310ebd6302011-10-10 19:06:284127void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4128 const gfx::Point& screen_point,
4129 bool ended,
4130 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034131 if (ended) {
[email protected]26aa0482009-09-30 16:55:274132 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204133 } else {
4134 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034135 }
initial.commit09911bf2008-07-26 23:55:294136}
4137
[email protected]310ebd6302011-10-10 19:06:284138void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274139 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294140}
4141
[email protected]310ebd6302011-10-10 19:06:284142void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594143 webkit_preferences_ = prefs;
4144 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294145}
4146
[email protected]310ebd6302011-10-10 19:06:284147void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294148 alternate_error_page_url_ = url;
4149}
4150
[email protected]310ebd6302011-10-10 19:06:284151void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514152 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084153 unsigned action) {
4154 if (custom_context.is_pepper_menu)
4155 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4156 else
4157 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584158 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4159 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334160}
4161
[email protected]310ebd6302011-10-10 19:06:284162void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514163 int id,
4164 const std::vector<FilePath>& paths) {
4165 if (!enumeration_completions_[id])
4166 return;
4167
4168 WebVector<WebString> ws_file_names(paths.size());
4169 for (size_t i = 0; i < paths.size(); ++i)
4170 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4171
4172 enumeration_completions_[id]->didChooseFile(ws_file_names);
4173 enumeration_completions_.erase(id);
4174}
4175
[email protected]fb11b6a42012-03-14 07:25:124176void RenderViewImpl::OnFileChooserResponse(
4177 const std::vector<content::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:364178 // This could happen if we navigated to a different page before the user
4179 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474180 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364181 return;
4182
[email protected]b5188522012-03-15 00:18:044183 // Convert Chrome's SelectedFileInfo list to WebKit's.
4184 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
4185 files.size());
4186 for (size_t i = 0; i < files.size(); ++i) {
4187 WebFileChooserCompletion::SelectedFileInfo selected_file;
4188 selected_file.path = webkit_glue::FilePathToWebString(files[i].path);
4189 selected_file.displayName = webkit_glue::FilePathStringToWebString(
4190 files[i].display_name);
4191 selected_files[i] = selected_file;
4192 }
[email protected]a1128322009-10-06 18:38:464193
[email protected]cdaf8d02010-03-30 19:52:474194 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:044195 file_chooser_completions_.front()->completion->didChooseFile(
4196 selected_files);
[email protected]cdaf8d02010-03-30 19:52:474197 file_chooser_completions_.pop_front();
4198
4199 // If there are more pending file chooser requests, schedule one now.
4200 if (!file_chooser_completions_.empty()) {
4201 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4202 file_chooser_completions_.front()->params));
4203 }
initial.commit09911bf2008-07-26 23:55:294204}
4205
[email protected]244ac1892011-12-02 17:04:474206void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4207 const gfx::Size& max_size) {
4208 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4209 if (!webview())
4210 return;
[email protected]61e2b3cc2012-03-02 16:13:344211 webview()->enableAutoResizeMode(min_size, max_size);
4212}
4213
4214void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
4215 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4216 if (!webview())
4217 return;
4218 webview()->disableAutoResizeMode();
4219
4220 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:474221}
4222
[email protected]2bf834f2011-11-17 20:02:214223void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244224 if (send_preferred_size_changes_)
4225 return;
[email protected]9fb325e2010-05-06 18:23:244226 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394227
[email protected]d812fd12011-05-27 23:05:074228 // Start off with an initial preferred size notification (in case
4229 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594230 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084231}
4232
[email protected]310ebd6302011-10-10 19:06:284233void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104234 const gfx::Size& disable_scrollbar_size_limit) {
4235 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4236}
4237
[email protected]310ebd6302011-10-10 19:06:284238void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314239 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504240 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514241 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374242 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134243#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414244 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4245 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464246 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:514247 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344248 renderer_prefs.thumb_inactive_color,
4249 renderer_prefs.thumb_active_color,
4250 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324251
[email protected]644d77e2010-01-27 01:03:104252 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324253 webview()->setScrollbarColors(
4254 renderer_prefs.thumb_inactive_color,
4255 renderer_prefs.thumb_active_color,
4256 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104257 webview()->setSelectionColors(
4258 renderer_prefs.active_selection_bg_color,
4259 renderer_prefs.active_selection_fg_color,
4260 renderer_prefs.inactive_selection_bg_color,
4261 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464262 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104263 }
[email protected]7a74e102009-09-03 00:16:564264#endif
[email protected]d051d9a2011-12-10 02:02:504265 // If the zoom level for this page matches the old zoom default, and this
4266 // is not a plugin, update the zoom level to match the new default.
4267 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4268 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4269 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4270 zoomLevelChanged();
4271 }
[email protected]80d96fa2009-06-10 22:34:514272}
4273
[email protected]310ebd6302011-10-10 19:06:284274void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4275 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284276 if (webview())
4277 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564278}
4279
[email protected]81375e872012-01-11 21:40:364280void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4281 const WebPluginAction& action) {
4282 if (webview())
4283 webview()->performPluginAction(action, location);
4284}
4285
[email protected]310ebd6302011-10-10 19:06:284286void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194287 const GURL& page_url) {
4288 // Prepare list to storage all savable resource links.
4289 std::vector<GURL> resources_list;
4290 std::vector<GURL> referrers_list;
4291 std::vector<GURL> frames_list;
4292 webkit_glue::SavableResourcesResult result(&resources_list,
4293 &referrers_list,
4294 &frames_list);
4295
[email protected]445e1042011-12-03 21:03:154296 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4297 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194298 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4299 webview(),
4300 page_url,
4301 &result,
[email protected]0a35efc2012-03-13 17:28:134302 content::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194303 // If something is wrong when collecting all savable resource links,
4304 // send empty list to embedder(browser) to tell it failed.
4305 referrers_list.clear();
4306 resources_list.clear();
4307 frames_list.clear();
4308 }
4309
4310 // Send result of all savable resource links to embedder.
4311 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4312 resources_list,
4313 referrers_list,
4314 frames_list));
4315}
4316
[email protected]310ebd6302011-10-10 19:06:284317void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194318 const std::vector<GURL>& links,
4319 const std::vector<FilePath>& local_paths,
4320 const FilePath& local_directory_name) {
4321
4322 // Convert std::vector of GURLs to WebVector<WebURL>
4323 WebVector<WebURL> weburl_links(links);
4324
4325 // Convert std::vector of std::strings to WebVector<WebString>
4326 WebVector<WebString> webstring_paths(local_paths.size());
4327 for (size_t i = 0; i < local_paths.size(); i++)
4328 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4329
4330 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4331 webstring_paths,
4332 webkit_glue::FilePathToWebString(
4333 local_directory_name));
4334}
4335
[email protected]310ebd6302011-10-10 19:06:284336void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:124337 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:274338 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:124339 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
4340 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
4341 before_unload_start_time,
4342 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:294343}
4344
[email protected]310ebd6302011-10-10 19:06:284345void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:314346 // Ensure that no other in-progress navigation continues.
4347 OnStop();
4348
[email protected]73eb2602012-02-09 19:50:554349 // Only run unload if we're not swapped out yet, but send the ack either way.
4350 if (!is_swapped_out_) {
4351 // Swap this RenderView out so the tab can navigate to a page rendered by a
4352 // different process. This involves running the unload handler and clearing
4353 // the page. Once WasSwappedOut is called, we also allow this process to
4354 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154355
[email protected]73eb2602012-02-09 19:50:554356 // Send an UpdateState message before we get swapped out.
4357 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154358
[email protected]73eb2602012-02-09 19:50:554359 // Synchronously run the unload handler before sending the ACK.
4360 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154361
[email protected]73eb2602012-02-09 19:50:554362 // Swap out and stop sending any IPC messages that are not ACKs.
4363 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154364
[email protected]73eb2602012-02-09 19:50:554365 // Replace the page with a blank dummy URL. The unload handler will not be
4366 // run a second time, thanks to a check in FrameLoader::stopLoading.
[email protected]69ddf852012-02-21 23:21:314367 // We use loadRequest instead of loadHTMLString because the former commits
4368 // synchronously. Otherwise a new navigation can interrupt the navigation
4369 // to about:swappedout. If that happens to be to the page we had been
4370 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]73eb2602012-02-09 19:50:554371 // TODO(creis): Need to add a better way to do this that avoids running the
4372 // beforeunload handler. For now, we just run it a second time silently.
[email protected]69ddf852012-02-21 23:21:314373 WebURLRequest request(GURL("about:swappedout"));
4374 webview()->mainFrame()->loadRequest(request);
[email protected]73eb2602012-02-09 19:50:554375 }
[email protected]992db4c2011-05-12 15:37:154376
4377 // Just echo back the params in the ACK.
4378 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4379}
4380
[email protected]310ebd6302011-10-10 19:06:284381void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374382 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294383 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4384 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4385 // in the onunload handler from appearing. For now, we're bypassing that and
4386 // calling the FrameLoader's CloseURL method directly. This should be
4387 // revisited to avoid having two ways to close a page. Having a single way
4388 // to close that can run onunload is also useful for fixing
4389 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274390 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294391
[email protected]992db4c2011-05-12 15:37:154392 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294393}
4394
[email protected]310ebd6302011-10-10 19:06:284395void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024396#if defined(USE_AURA)
4397 // Aura doesn't care if we switch themes.
4398#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164399 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464400 if (webview())
4401 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574402#else // defined(OS_WIN)
4403 // TODO(port): we don't support theming on non-Windows platforms yet
4404 NOTIMPLEMENTED();
4405#endif
initial.commit09911bf2008-07-26 23:55:294406}
4407
[email protected]310ebd6302011-10-10 19:06:284408void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084409 if (decrement_shared_popup_at_destruction_)
4410 shared_popup_counter_->data--;
4411 shared_popup_counter_ = new SharedRenderViewCounter(0);
4412 decrement_shared_popup_at_destruction_ = false;
4413}
4414
[email protected]310ebd6302011-10-10 19:06:284415bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4416 const WebURLError& error,
4417 bool replace) {
[email protected]15d79e12009-08-02 19:23:454418 // We only show alternate error pages in the main frame. They are
4419 // intended to assist the user when navigating, so there is not much
4420 // value in showing them for failed subframes. Ideally, we would be
4421 // able to use the TYPED transition type for this, but that flag is
4422 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454423 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454424 return false;
4425
4426 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374427 // connection failure.
[email protected]15d79e12009-08-02 19:23:454428 int ec = error.reason;
4429 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4430 ec != net::ERR_CONNECTION_FAILED &&
4431 ec != net::ERR_CONNECTION_REFUSED &&
4432 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374433 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454434 return false;
4435
4436 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554437 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454438 if (!error_page_url.is_valid())
4439 return false;
4440
4441 // Load an empty page first so there is an immediate response to the error,
4442 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454443 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364444 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454445 error.unreachableURL,
4446 replace);
4447
4448 // Now, create a fetcher for the error page and associate it with the data
4449 // source we just created via the LoadHTMLString call. That way if another
4450 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074451 DocumentState* document_state =
4452 DocumentState::FromDataSource(frame->provisionalDataSource());
4453 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454454 new AltErrorPageResourceFetcher(
4455 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084456 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4457 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454458 return true;
4459}
4460
[email protected]310ebd6302011-10-10 19:06:284461void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4462 const WebURLError& original_error,
4463 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454464 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094465 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554466 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094467 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454468}
4469
[email protected]310ebd6302011-10-10 19:06:284470void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004471 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474472 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004473}
4474
[email protected]310ebd6302011-10-10 19:06:284475void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094476 const gfx::Rect& resizer_rect,
4477 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104478 if (webview()) {
[email protected]7ddea9802012-02-22 23:08:054479 // This setting has no effect if fixed layout is not enabled.
[email protected]43d9d782012-03-01 15:40:094480 if (webkit_preferences_.default_device_scale_factor)
[email protected]7ddea9802012-02-22 23:08:054481 webview()->settings()->setLayoutFallbackWidth(
[email protected]43d9d782012-03-01 15:40:094482 new_size.width() / webkit_preferences_.default_device_scale_factor);
[email protected]a72a1fa2010-05-03 22:18:474483 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104484 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204485 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314486 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104487 }
[email protected]dd6afca2011-08-13 03:44:314488 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104489 }
4490
[email protected]ee41e7d22011-10-14 19:34:094491 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004492}
[email protected]0aa477bd2009-03-23 22:21:434493
[email protected]29ed96a2012-02-04 18:12:164494void RenderViewImpl::WillInitiatePaint() {
4495 // Notify the pepper plugins that we're about to paint.
4496 pepper_delegate_.ViewWillInitiatePaint();
4497}
4498
[email protected]310ebd6302011-10-10 19:06:284499void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164500 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014501 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284502}
4503
[email protected]310ebd6302011-10-10 19:06:284504void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284505 // Notify any pepper plugins that we painted. This will call into the plugin,
4506 // and we it may ask to close itself as a result. This will, in turn, modify
4507 // our set, possibly invalidating the iterator. So we iterate on a copy that
4508 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014509 pepper_delegate_.ViewFlushedPaint();
4510
[email protected]5b1dec8c2012-02-07 04:35:384511 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4512 // See crbug.com/112921.
4513 if (!webview())
4514 return;
4515
[email protected]00c39612010-03-06 02:53:284516 WebFrame* main_frame = webview()->mainFrame();
4517
4518 // If we have a provisional frame we are between the start and commit stages
4519 // of loading and we don't want to save stats.
4520 if (!main_frame->provisionalDataSource()) {
4521 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074522 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284523
[email protected]05c8e502010-08-15 15:13:524524 // TODO(jar): The following code should all be inside a method, probably in
4525 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284526 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074527 if (document_state->first_paint_time().is_null()) {
4528 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284529 }
[email protected]007733c2011-11-17 00:34:074530 if (document_state->first_paint_after_load_time().is_null() &&
4531 !document_state->finish_load_time().is_null()) {
4532 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284533 }
4534 }
4535}
4536
[email protected]310ebd6302011-10-10 19:06:284537void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084538 RenderWidget::OnSwapBuffersPosted();
4539}
4540
[email protected]310ebd6302011-10-10 19:06:284541void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244542 RenderWidget::OnSwapBuffersComplete();
4543}
4544
[email protected]310ebd6302011-10-10 19:06:284545void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244546 RenderWidget::OnSwapBuffersAborted();
4547}
4548
[email protected]310ebd6302011-10-10 19:06:284549webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154550 const gfx::Rect& paint_bounds,
4551 TransportDIB** dib,
4552 gfx::Rect* location,
4553 gfx::Rect* clip) {
4554 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4555 paint_bounds, dib, location, clip);
4556}
4557
[email protected]310ebd6302011-10-10 19:06:284558gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074559 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434560 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524561}
4562
[email protected]310ebd6302011-10-10 19:06:284563void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164564 if (webview())
[email protected]26aa0482009-09-30 16:55:274565 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164566}
4567
[email protected]310ebd6302011-10-10 19:06:284568void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144569 if (webview())
[email protected]b4bb2502009-10-01 22:35:274570 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144571
4572 SetBackground(background);
4573}
4574
[email protected]310ebd6302011-10-10 19:06:284575void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344576 if (webview())
[email protected]b4bb2502009-10-01 22:35:274577 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264578
4579#if defined(OS_MACOSX)
4580 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4581 for (plugin_it = plugin_delegates_.begin();
4582 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4583 (*plugin_it)->SetWindowFocus(active);
4584 }
4585#endif
[email protected]8c66c5a2009-07-22 17:26:344586}
4587
[email protected]7a17bac02012-03-07 21:58:124588void RenderViewImpl::OnSetNavigationStartTime(
4589 const base::TimeTicks& browser_navigation_start) {
4590 if (!webview())
4591 return;
4592
4593 // Only the initial navigation can be a cross-renderer navigation. If we've
4594 // already navigated away from that page, we can ignore this message.
4595 if (page_id_ != -1)
4596 return;
4597
4598 // browser_navigation_start is likely before this process existed, so we can't
4599 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
4600 // ensure we don't report a bogus value in the future.
4601 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
4602 browser_navigation_start);
4603 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
4604 (navigation_start - base::TimeTicks()).InSecondsF());
4605}
4606
[email protected]6ce7abc52010-02-02 18:40:144607#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284608void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144609 // Inform plugins that their container has changed visibility.
4610 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4611 for (plugin_it = plugin_delegates_.begin();
4612 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4613 (*plugin_it)->SetContainerVisibility(visible);
4614 }
4615}
[email protected]1e6e3c992010-02-08 15:52:134616
[email protected]310ebd6302011-10-10 19:06:284617void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4618 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134619 // Inform plugins that their window's frame has changed.
4620 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4621 for (plugin_it = plugin_delegates_.begin();
4622 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4623 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4624 }
4625}
[email protected]935d63d2010-10-15 23:31:554626
[email protected]310ebd6302011-10-10 19:06:284627void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4628 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134629 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554630 // applies to it or not, so inform all the delegates.
4631 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4632 for (plugin_it = plugin_delegates_.begin();
4633 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134634 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554635 }
4636}
[email protected]6ce7abc52010-02-02 18:40:144637#endif // OS_MACOSX
4638
[email protected]310ebd6302011-10-10 19:06:284639void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484640 const EditCommands& edit_commands) {
4641 edit_commands_ = edit_commands;
4642}
4643
[email protected]310ebd6302011-10-10 19:06:284644void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594645 // We need to grab a pointer to the doomed WebView before we destroy it.
4646 WebView* doomed = webview();
4647 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494648 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594649}
4650
[email protected]310ebd6302011-10-10 19:06:284651void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484652 edit_commands_.clear();
4653}
4654
[email protected]310ebd6302011-10-10 19:06:284655bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:114656 pepper_delegate_.WillHandleMouseEvent();
4657
4658 // If the mouse is locked, only the current owner of the mouse lock can
4659 // process mouse events.
4660 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374661}
4662
[email protected]310ebd6302011-10-10 19:06:284663void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514664 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064665}
4666
[email protected]310ebd6302011-10-10 19:06:284667void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244668 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4669}
4670
[email protected]310ebd6302011-10-10 19:06:284671void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434672 RenderWidget::OnWasHidden();
4673
[email protected]a6939ca42011-02-18 17:58:074674 if (webview()) {
4675 webview()->settings()->setMinimumTimerInterval(
4676 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444677 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074678 }
4679
[email protected]204f1df2012-01-04 20:21:134680 // Inform PPAPI plugins that their page is no longer visible.
4681 pepper_delegate_.PageVisibilityChanged(false);
4682
[email protected]a6939ca42011-02-18 17:58:074683#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134684 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434685 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4686 for (plugin_it = plugin_delegates_.begin();
4687 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4688 (*plugin_it)->SetContainerVisibility(false);
4689 }
[email protected]a6939ca42011-02-18 17:58:074690#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434691}
4692
[email protected]310ebd6302011-10-10 19:06:284693void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434694 RenderWidget::OnWasRestored(needs_repainting);
4695
[email protected]a6939ca42011-02-18 17:58:074696 if (webview()) {
4697 webview()->settings()->setMinimumTimerInterval(
4698 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444699 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074700 }
4701
[email protected]204f1df2012-01-04 20:21:134702 // Inform PPAPI plugins that their page is visible.
4703 pepper_delegate_.PageVisibilityChanged(true);
4704
[email protected]a6939ca42011-02-18 17:58:074705#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134706 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434707 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4708 for (plugin_it = plugin_delegates_.begin();
4709 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4710 (*plugin_it)->SetContainerVisibility(true);
4711 }
[email protected]784ea1ab2010-09-18 00:02:344712#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074713}
[email protected]1e6e3c992010-02-08 15:52:134714
[email protected]310ebd6302011-10-10 19:06:284715bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384716 if (WebWidgetHandlesCompositorScheduling())
4717 return false;
4718
[email protected]05a980d7a2012-02-07 22:16:424719 if (queried_for_swapbuffers_complete_callback_)
4720 return context_has_swapbuffers_complete_callback_;
4721
4722 queried_for_swapbuffers_complete_callback_ = true;
4723
[email protected]65225772011-05-12 21:10:244724 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:424725 if (context && context->makeContextCurrent()) {
4726 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4727 context_has_swapbuffers_complete_callback_ =
4728 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
4729 != std::string::npos;
4730 }
4731
4732 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:244733}
4734
[email protected]310ebd6302011-10-10 19:06:284735void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134736 RenderWidget::OnSetFocus(enable);
4737
[email protected]7d3c02c2010-05-05 23:10:314738 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074739 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134740 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4741 for (plugin_it = plugin_delegates_.begin();
4742 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344743#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314744 // RenderWidget's call to setFocus can cause the underlying webview's
4745 // activation state to change just like a call to setIsActive.
4746 if (enable)
4747 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344748#endif
[email protected]7d3c02c2010-05-05 23:10:314749 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134750 }
[email protected]589621b2010-09-23 22:01:074751
4752 // Notify all Pepper plugins.
4753 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134754 }
4755}
[email protected]941e4552010-02-01 21:23:434756
[email protected]310ebd6302011-10-10 19:06:284757void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004758 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504759 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574760}
4761
[email protected]73bf95812011-10-12 11:38:324762void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004763 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324764}
4765
[email protected]3f783362011-10-21 22:40:504766void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4767 UpdateSelectionBounds();
4768}
4769
[email protected]b25b3ee2012-01-13 05:19:544770bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4771 if (!pepper_delegate_.IsPluginFocused())
4772 return false;
4773 *rect = pepper_delegate_.GetCaretBounds();
4774 return true;
4775}
4776
[email protected]73bf95812011-10-12 11:38:324777void RenderViewImpl::PpapiPluginCancelComposition() {
4778 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4779 ui::Range range(ui::Range::InvalidRange());
4780 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4781}
4782
[email protected]3c8c74c2012-03-15 07:34:524783void RenderViewImpl::PpapiPluginSelectionChanged() {
4784 SyncSelectionIfRequired();
4785}
4786
[email protected]310ebd6302011-10-10 19:06:284787void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574788 const string16& text,
4789 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4790 int selection_start,
4791 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324792 if (pepper_delegate_.IsPluginFocused()) {
4793 // When a PPAPI plugin has focus, we bypass WebKit.
4794 pepper_delegate_.OnImeSetComposition(text,
4795 underlines,
4796 selection_start,
4797 selection_end);
4798 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234799#if defined(OS_WIN)
4800 // When a plug-in has focus, we create platform-specific IME data used by
4801 // our IME emulator and send it directly to the focused plug-in, i.e. we
4802 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4803 // instance ID is the same one as the specified ID.)
4804 if (focused_plugin_id_ >= 0) {
4805 std::vector<int> clauses;
4806 std::vector<int> target;
4807 for (size_t i = 0; i < underlines.size(); ++i) {
4808 clauses.push_back(underlines[i].startOffset);
4809 clauses.push_back(underlines[i].endOffset);
4810 if (underlines[i].thick) {
4811 target.clear();
4812 target.push_back(underlines[i].startOffset);
4813 target.push_back(underlines[i].endOffset);
4814 }
4815 }
4816 std::set<WebPluginDelegateProxy*>::iterator it;
4817 for (it = plugin_delegates_.begin();
4818 it != plugin_delegates_.end(); ++it) {
4819 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4820 focused_plugin_id_);
4821 }
4822 return;
4823 }
4824#endif
[email protected]56ea1a62011-05-30 07:05:574825 RenderWidget::OnImeSetComposition(text,
4826 underlines,
4827 selection_start,
4828 selection_end);
4829 }
4830}
4831
[email protected]4de6d1692011-10-12 08:45:444832void RenderViewImpl::OnImeConfirmComposition(
4833 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574834 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324835 // When a PPAPI plugin has focus, we bypass WebKit.
4836 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574837 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234838#if defined(OS_WIN)
4839 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4840 // plug-ins. When we send IME text directly to plug-ins, we should not send
4841 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444842 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234843 if (focused_plugin_id_ >= 0) {
4844 std::set<WebPluginDelegateProxy*>::iterator it;
4845 for (it = plugin_delegates_.begin();
4846 it != plugin_delegates_.end(); ++it) {
4847 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4848 }
4849 return;
4850 }
4851#endif
[email protected]ebd28ac2011-10-13 18:49:054852 if (replacement_range.IsValid() && webview()) {
4853 // Select the text in |replacement_range|, it will then be replaced by
4854 // text added by the call to RenderWidget::OnImeConfirmComposition().
4855 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164856 WebRange webrange = WebRange::fromDocumentRange(
4857 frame, replacement_range.start(), replacement_range.length());
4858 if (!webrange.isNull())
4859 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054860 }
4861 }
[email protected]4de6d1692011-10-12 08:45:444862 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574863 }
4864}
4865
[email protected]310ebd6302011-10-10 19:06:284866ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324867 return pepper_delegate_.IsPluginFocused() ?
4868 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4869}
4870
[email protected]3f783362011-10-21 22:40:504871void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4872 if (pepper_delegate_.IsPluginFocused()) {
4873 // TODO(kinaba) http://crbug.com/101101
4874 // Current Pepper IME API does not handle selection bounds. So we simply
4875 // use the caret position as an empty range for now. It will be updated
4876 // after Pepper API equips features related to surrounding text retrieval.
4877 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4878 *start = caret;
4879 *end = caret;
4880 return;
4881 }
4882 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454883}
4884
[email protected]310ebd6302011-10-10 19:06:284885bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324886 return pepper_delegate_.IsPluginFocused() ?
4887 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574888}
4889
[email protected]e6ae0f6c2011-10-04 10:39:234890#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284891void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234892 if (focused)
4893 focused_plugin_id_ = plugin_id;
4894 else
4895 focused_plugin_id_ = -1;
4896}
4897#endif
4898
[email protected]43f28f832010-02-03 02:28:484899#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284900void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134901 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4902 focused, plugin_id);
4903 Send(msg);
4904}
4905
[email protected]310ebd6302011-10-10 19:06:284906void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134907 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554908 // This message can be sent during event-handling, and needs to be delivered
4909 // within that context.
4910 msg->set_unblock(true);
4911 Send(msg);
4912}
4913
[email protected]310ebd6302011-10-10 19:06:284914gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234915 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484916 gfx::PluginWindowHandle window = NULL;
4917 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234918 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114919 if (window) {
4920 fake_plugin_window_handles_.insert(window);
4921 }
[email protected]43f28f832010-02-03 02:28:484922 return window;
4923}
4924
[email protected]310ebd6302011-10-10 19:06:284925void RenderViewImpl::DestroyFakePluginWindowHandle(
4926 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114927 if (window && fake_plugin_window_handles_.find(window) !=
4928 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484929 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114930 fake_plugin_window_handles_.erase(window);
4931 }
[email protected]43f28f832010-02-03 02:28:484932}
4933
[email protected]310ebd6302011-10-10 19:06:284934void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4935 gfx::PluginWindowHandle window,
4936 int32 width,
4937 int32 height,
4938 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334939 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484940 routing_id(), window, width, height, io_surface_identifier));
4941}
4942
[email protected]310ebd6302011-10-10 19:06:284943void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334944 gfx::PluginWindowHandle window,
4945 int32 width,
4946 int32 height,
4947 TransportDIB::Handle transport_dib) {
4948 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074949 routing_id(), window, width, height, transport_dib));
4950}
4951
[email protected]310ebd6302011-10-10 19:06:284952TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334953 size_t size) {
[email protected]1aef98132010-02-23 18:00:074954 TransportDIB::Handle dib_handle;
4955 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384956 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074957 return dib_handle;
4958 // Return an invalid handle if Send() fails.
4959 return TransportDIB::DefaultHandleValue();
4960}
4961
[email protected]310ebd6302011-10-10 19:06:284962void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4963 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074964 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4965}
4966
[email protected]310ebd6302011-10-10 19:06:284967void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:324968 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:144969 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:324970 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:484971}
4972#endif
[email protected]58c321d2010-02-19 12:11:284973
[email protected]310ebd6302011-10-10 19:06:284974bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234975 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474976 WebFileChooserCompletion* completion) {
4977 static const size_t kMaximumPendingFileChooseRequests = 4;
4978 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4979 // This sanity check prevents too many file choose requests from getting
4980 // queued which could DoS the user. Getting these is most likely a
4981 // programming error (there are many ways to DoS the user so it's not
4982 // considered a "real" security check), either in JS requesting many file
4983 // choosers to pop up, or in a plugin.
4984 //
4985 // TODO(brettw) we might possibly want to require a user gesture to open
4986 // a file picker, which will address this issue in a better way.
4987 return false;
4988 }
4989
4990 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4991 new PendingFileChooser(params, completion)));
4992 if (file_chooser_completions_.size() == 1) {
4993 // Actually show the browse dialog when this is the first request.
4994 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4995 }
4996 return true;
4997}
4998
[email protected]310ebd6302011-10-10 19:06:284999WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515000 if (!geolocation_dispatcher_)
5001 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5002 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255003}
[email protected]61c9f032010-03-31 23:04:195004
[email protected]310ebd6302011-10-10 19:06:285005WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:115006 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:225007#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:025008 if (!input_tag_speech_dispatcher_)
5009 input_tag_speech_dispatcher_ =
5010 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:225011#endif
[email protected]c52b2892012-03-07 11:01:025012 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:115013}
5014
[email protected]310ebd6302011-10-10 19:06:285015WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515016 if (!device_orientation_dispatcher_)
5017 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5018 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535019}
5020
[email protected]310ebd6302011-10-10 19:06:285021void RenderViewImpl::zoomLimitsChanged(double minimum_level,
5022 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:255023 // For now, don't remember plugin zoom values. We don't want to mix them with
5024 // normal web content (i.e. a fixed layout plugin would usually want them
5025 // different).
5026 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5027
[email protected]b75b8292010-10-01 07:28:255028 int minimum_percent = static_cast<int>(
5029 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5030 int maximum_percent = static_cast<int>(
5031 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255032
5033 Send(new ViewHostMsg_UpdateZoomLimits(
5034 routing_id_, minimum_percent, maximum_percent, remember));
5035}
5036
[email protected]310ebd6302011-10-10 19:06:285037void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:255038 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:085039 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:255040 // Tell the browser which url got zoomed so it can update the menu and the
5041 // saved values if necessary
5042 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:085043 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:415044 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:255045}
5046
[email protected]310ebd6302011-10-10 19:06:285047void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
5048 const WebString& base_url,
5049 const WebString& url,
5050 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:485051 GURL base(base_url);
5052 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
5053 if (base.GetOrigin() != absolute_url.GetOrigin()) {
5054 return;
5055 }
[email protected]f1a29a02011-10-06 23:08:445056 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
5057 UTF16ToUTF8(scheme),
5058 absolute_url,
5059 title));
[email protected]a6d36cc2011-02-23 00:39:485060}
5061
[email protected]310ebd6302011-10-10 19:06:285062WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:445063 WebKit::WebPageVisibilityState current_state = is_hidden() ?
5064 WebKit::WebPageVisibilityStateHidden :
5065 WebKit::WebPageVisibilityStateVisible;
5066 WebKit::WebPageVisibilityState override_state = current_state;
5067 if (content::GetContentClient()->renderer()->
5068 ShouldOverridePageVisibilityState(this,
5069 &override_state))
5070 return override_state;
5071 return current_state;
[email protected]94dec932011-05-26 20:04:215072}
5073
[email protected]273558fb2012-01-12 15:03:515074WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
5075 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
5076 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
5077 return NULL;
5078 EnsureMediaStreamImpl();
5079 return media_stream_impl_;
5080}
5081
[email protected]310ebd6302011-10-10 19:06:285082bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195083 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455084 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195085 if (frame->parent() != NULL)
5086 return false;
5087
[email protected]f0a3d0b2010-08-06 22:51:535088 // Navigations initiated within Webkit are not sent out to the external host
5089 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275090 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:135091 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535092 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:135093 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:335094 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:535095 return false;
5096
[email protected]2fc22d12010-12-02 23:08:165097 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325098 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015099 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165100 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015101 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325102 // The opener relationship between the new window and the parent allows the
5103 // new window to script the parent and vice versa. This is not allowed if
5104 // the origins of the two domains are different. This can be treated as a
5105 // top level navigation and routed back to the host.
5106 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275107 if (!opener) {
[email protected]86965362011-04-21 18:42:515108 return true;
[email protected]d19ea342011-04-20 20:31:135109 } else {
[email protected]b6cb3a842011-06-24 18:28:415110 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:325111 return true;
5112 }
5113 }
[email protected]61c9f032010-03-31 23:04:195114 return false;
5115}
[email protected]2b06a992010-08-21 05:48:225116
[email protected]310ebd6302011-10-10 19:06:285117void RenderViewImpl::OnAsyncFileOpened(
5118 base::PlatformFileError error_code,
5119 IPC::PlatformFileForTransit file_for_transit,
5120 int message_id) {
[email protected]27a9ef32010-09-10 04:06:245121 pepper_delegate_.OnAsyncFileOpened(
5122 error_code,
5123 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5124 message_id);
5125}
[email protected]caf706f2010-10-26 17:54:085126
[email protected]310ebd6302011-10-10 19:06:285127void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:475128 int request_id,
5129 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:435130 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:475131 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
5132 broker_process_handle,
5133 handle);
[email protected]eb415bf0e2011-04-14 02:45:425134}
5135
[email protected]caf706f2010-10-26 17:54:085136#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285137void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155138 if (external_popup_menu_ == NULL) {
5139 // Crash reports from the field indicate that we can be notified with a
5140 // NULL external popup menu (we probably get notified twice).
5141 // If you hit this please file a bug against jcivelli and include the page
5142 // and steps to repro.
5143 NOTREACHED();
5144 return;
5145 }
[email protected]caf706f2010-10-26 17:54:085146 external_popup_menu_->DidSelectItem(selected_index);
5147 external_popup_menu_.reset();
5148}
5149#endif
[email protected]bb461532010-11-26 21:50:235150
[email protected]1b4209f2011-01-07 00:25:405151#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:285152void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:405153 int request_id,
5154 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:495155 const PP_NetAddress_Private& local_addr,
5156 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:405157 pepper_delegate_.OnConnectTcpACK(
5158 request_id,
5159 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5160 local_addr,
5161 remote_addr);
5162}
5163#endif
[email protected]a6097f42011-01-10 08:50:515164
[email protected]310ebd6302011-10-10 19:06:285165void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515166 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085167 if (custom_context.is_pepper_menu)
5168 pepper_delegate_.OnContextMenuClosed(custom_context);
5169 else
5170 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105171}
[email protected]5a7b15a2011-08-22 22:48:185172
[email protected]310ebd6302011-10-10 19:06:285173void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185174 if (!webview())
5175 return;
5176 WebFrame* main_frame = webview()->mainFrame();
5177 if (!main_frame)
5178 return;
5179 main_frame->enableViewSourceMode(true);
5180}
[email protected]67bfb83f2011-09-22 03:36:375181
[email protected]310ebd6302011-10-10 19:06:285182bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085183 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405184}
[email protected]7f3c7af2011-10-20 22:52:515185
[email protected]64d0e192011-12-09 14:44:205186void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:515187 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:185188#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:205189 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:185190#endif
[email protected]7f3c7af2011-10-20 22:52:515191}