blob: e07eb6c664297c92d5b2cbba27a70a51e80262b8 [file] [log] [blame]
[email protected]b553edd52012-01-10 12:15:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]310ebd6302011-10-10 19:06:285#include "content/renderer/render_view_impl.h"
initial.commit09911bf2008-07-26 23:55:296
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
initial.commit09911bf2008-07-26 23:55:299#include <string>
10#include <vector>
11
[email protected]6e806822011-11-19 01:51:0812#include "base/bind.h"
13#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5015#include "base/compiler_specific.h"
[email protected]b1cf3372011-04-20 21:28:1016#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4917#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2819#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
[email protected]7ddea9802012-02-22 23:08:0521#include "base/string_number_conversions.h"
[email protected]0a35efc2012-03-13 17:28:1322#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4123#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2924#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2825#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2626#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2227#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1028#include "content/common/appcache/appcache_dispatcher.h"
[email protected]127dd582011-03-16 21:32:1029#include "content/common/clipboard_messages.h"
[email protected]37666cf2011-03-13 21:51:4230#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5531#include "content/common/drag_messages.h"
[email protected]16dd6e22012-03-01 19:08:2032#include "content/common/fileapi/file_system_dispatcher.h"
33#include "content/common/fileapi/webfilesystem_callback_dispatcher.h"
[email protected]c26ad882012-02-07 06:41:2034#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]a2ef54c2011-10-10 16:20:3135#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5136#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1037#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0038#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4039#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0540#include "content/common/request_extra_data.h"
[email protected]5fa3a062012-03-21 15:39:3441#include "content/common/socket_stream_handle_data.h"
[email protected]778574e2011-03-21 22:03:5042#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2143#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0444#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4845#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2946#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5147#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2348#include "content/public/common/file_chooser_params.h"
[email protected]fb11b6a42012-03-14 07:25:1249#include "content/public/common/selected_file_info.h"
[email protected]a1d29162011-10-14 17:14:0350#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3451#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0752#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3253#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4454#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3655#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1956#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0257#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1558#include "content/renderer/dom_automation_controller.h"
[email protected]55722152011-03-22 01:33:5359#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1960#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4061#include "content/renderer/gpu/compositor_thread.h"
[email protected]1784b2f2011-11-24 10:53:4862#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0263#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4264#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0265#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0866#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3767#include "content/renderer/media/audio_renderer_impl.h"
[email protected]273558fb2012-01-12 15:03:5168#include "content/renderer/media/media_stream_dependency_factory.h"
69#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4070#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4871#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4072#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4873#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]4a19be92011-09-22 14:25:0274#include "content/renderer/mhtml_generator.h"
[email protected]217690d2012-01-27 07:33:1175#include "content/renderer/mouse_lock_dispatcher.h"
[email protected]230b7ef2011-03-16 22:30:1976#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3777#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3578#include "content/renderer/plugin_channel_host.h"
[email protected]0361b942012-03-14 06:42:5379#include "content/renderer/browser_plugin/browser_plugin_constants.h"
80#include "content/renderer/browser_plugin/browser_plugin_placeholder.h"
[email protected]8704f89b2011-04-15 00:30:0581#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4482#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4483#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3284#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0185#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:2086#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]663bd9e2011-03-21 01:07:0187#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]86a7d3c2011-09-12 16:45:3288#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1989#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:1390#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:0191#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3592#include "content/renderer/webplugin_delegate_proxy.h"
93#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4994#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4195#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:5096#include "media/base/message_loop_factory.h"
[email protected]e1d69d762011-12-13 05:12:1897#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2998#include "net/base/escape.h"
99#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04100#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:57101#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:37102#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:37103#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:37104#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37105#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37107#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
111#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37112#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37113#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57114#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58115#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44116#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58117#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14118#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37119#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19120#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37121#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36122#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37123#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37126#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37127#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17130#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37131#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37132#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40133#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51134#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08135#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]273558fb2012-01-12 15:03:51141#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08143#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34146#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37147#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
152#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26153#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47154#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38155#include "ui/gfx/native_widget_types.h"
156#include "ui/gfx/point.h"
157#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55158#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04159#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]9c4bf232011-12-15 02:25:08160#include "webkit/forms/form_data.h"
161#include "webkit/forms/form_field.h"
162#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43163#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19164#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24165#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29166#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07167#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29168#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03169#include "webkit/glue/weburlloader_impl.h"
[email protected]b9fd01ba2012-02-28 01:50:40170#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51171#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16172#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50173#include "webkit/plugins/npapi/plugin_list.h"
174#include "webkit/plugins/npapi/webplugin_delegate.h"
175#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
176#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52177#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29178
[email protected]6c8afae52009-01-22 02:24:57179#if defined(OS_WIN)
180// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57181// * theming
[email protected]08397d52011-02-05 01:53:38182#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03183#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37184#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51185#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33186#elif defined(OS_MACOSX)
187#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57188#endif
189
[email protected]9892b472010-09-16 00:23:42190using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08191using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21192using WebKit::WebApplicationCacheHost;
193using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26194using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41195using WebKit::WebColor;
196using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59197using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44198using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51199using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55200using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28201using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00202using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58203using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25204using WebKit::WebDragOperation;
205using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51206using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51207using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08208using WebKit::WebExternalPopupMenu;
209using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47210using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22211using WebKit::WebFileSystem;
212using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49213using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59214using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48215using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45216using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51217using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17218using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13219using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41220using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50221using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15222using WebKit::WebIntentRequest;
223using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17224using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28225using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17226using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28227using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28228using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51229using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19230using WebKit::WebPageSerializer;
231using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17232using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36233using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40234using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49235using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09236using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52237using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59238using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51239using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52240using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15241using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40242using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35243using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29244using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17245using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59246using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42247using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02248using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34249using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34250using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40251using WebKit::WebStorageQuotaCallbacks;
252using WebKit::WebStorageQuotaError;
253using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28254using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51255using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52256using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24257using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28258using WebKit::WebURL;
259using WebKit::WebURLError;
260using WebKit::WebURLRequest;
261using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28262using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03263using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28264using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26265using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26266using appcache::WebApplicationCacheHostImpl;
267using base::Time;
268using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07269using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32270using content::NavigationState;
[email protected]380244092011-10-07 17:26:27271using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44272using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36273using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15274using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19275using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08276using webkit::forms::FormField;
277using webkit::forms::PasswordForm;
278using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26279using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23280using webkit_glue::ResourceFetcher;
[email protected]b9fd01ba2012-02-28 01:50:40281using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33282
initial.commit09911bf2008-07-26 23:55:29283//-----------------------------------------------------------------------------
284
[email protected]310ebd6302011-10-10 19:06:28285typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49286static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02287
[email protected]882daa92009-11-05 16:31:31288// Time, in seconds, we delay before sending content state changes (such as form
289// state and scroll position) to the browser. We delay sending changes to avoid
290// spamming the browser.
291// To avoid having tab/session restore require sending a message to get the
292// current content state during tab closing we use a shorter timeout for the
293// foreground renderer. This means there is a small window of time from which
294// content state is modified and not sent to session restore, but this is
295// better than having to wake up all renderers during shutdown.
296static const int kDelaySecondsForContentStateSyncHidden = 5;
297static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29298
[email protected]e99ef6f2011-10-16 01:13:00299static const size_t kExtraCharsBeforeAndAfterSelection = 100;
300
[email protected]0aa55312008-10-17 21:53:08301// The maximum number of popups that can be spawned from one page.
302static const int kMaximumNumberOfUnacknowledgedPopups = 25;
303
[email protected]c514d6372011-08-16 22:54:44304static const float kScalingIncrement = 0.1f;
305
[email protected]47578fa02011-11-02 19:34:41306static const float kScalingIncrementForGesture = 0.01f;
307
[email protected]726985e22009-06-18 21:09:28308static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
309 WebVector<WebURL> urls;
310 ds->redirectChain(urls);
311 result->reserve(urls.size());
312 for (size_t i = 0; i < urls.size(); ++i)
313 result->push_back(urls[i]);
314}
315
[email protected]007733c2011-11-17 00:34:07316// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44317// the AltErrorPageResourceFetcher is reset.
318static void StopAltErrorPageFetcher(WebDataSource* data_source) {
319 if (data_source) {
[email protected]007733c2011-11-17 00:34:07320 DocumentState* document_state = DocumentState::FromDataSource(data_source);
321 if (document_state)
322 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44323 }
324}
325
[email protected]007733c2011-11-17 00:34:07326static bool IsReload(const ViewMsg_Navigate_Params& params) {
327 return
328 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
329 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
330}
331
[email protected]b9fd01ba2012-02-28 01:50:40332static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]445e1042011-12-03 21:03:15333 const WebURLRequest& request) {
334 return request.extraData() ?
335 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
336 WebKit::WebReferrerPolicyDefault;
337}
338
[email protected]b9fd01ba2012-02-28 01:50:40339static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
340 const WebURLResponse& response) {
341 return static_cast<WebURLResponseExtraDataImpl*>(
342 response.extraData());
343}
344
[email protected]2149cc622012-02-14 01:12:12345NOINLINE static void CrashIntentionally() {
346 // NOTE(shess): Crash directly rather than using NOTREACHED() so
347 // that the signature is easier to triage in crash reports.
348 volatile int* zero = NULL;
349 *zero = 0;
350}
351
[email protected]8bf1048012012-02-08 01:22:18352static void MaybeHandleDebugURL(const GURL& url) {
353 if (!url.SchemeIs(chrome::kChromeUIScheme))
354 return;
355 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12356 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18357 } else if (url == GURL(chrome::kChromeUIKillURL)) {
358 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
359 } else if (url == GURL(chrome::kChromeUIHangURL)) {
360 for (;;) {
361 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
362 }
363 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
364 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
365 }
366}
367
initial.commit09911bf2008-07-26 23:55:29368///////////////////////////////////////////////////////////////////////////////
369
[email protected]310ebd6302011-10-10 19:06:28370struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23371 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47372 WebFileChooserCompletion* c)
373 : params(p),
374 completion(c) {
375 }
[email protected]8caadeb2011-11-22 02:45:23376 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47377 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
378};
379
[email protected]217690d2012-01-27 07:33:11380namespace {
381
382class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
383 public:
[email protected]82114f52012-03-20 22:53:41384 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11385 : webwidget_(webwidget) {}
386
387 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
388 if (succeeded)
389 webwidget_->didAcquirePointerLock();
390 else
391 webwidget_->didNotAcquirePointerLock();
392 }
393
394 virtual void OnMouseLockLost() OVERRIDE {
395 webwidget_->didLosePointerLock();
396 }
397
398 virtual bool HandleMouseLockedInputEvent(
399 const WebKit::WebMouseEvent &event) OVERRIDE {
400 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
401 return false;
402 }
403
404 private:
405 WebKit::WebWidget* webwidget_;
406};
407
[email protected]86cd9472012-02-03 19:51:05408int64 ExtractPostId(const WebHistoryItem& item) {
409 if (item.isNull())
410 return -1;
411
412 if (item.httpBody().isNull())
413 return -1;
414
415 return item.httpBody().identifier();
416}
417
[email protected]217690d2012-01-27 07:33:11418} // namespace
419
[email protected]daf82f82011-10-31 22:35:31420RenderViewImpl::RenderViewImpl(
421 gfx::NativeViewId parent_hwnd,
422 int32 opener_id,
423 const content::RendererPreferences& renderer_prefs,
424 const WebPreferences& webkit_prefs,
425 SharedRenderViewCounter* counter,
426 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56427 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31428 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46429 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41430 int32 next_page_id,
[email protected]8cca3da2012-03-20 08:26:34431 const WebKit::WebScreenInfo& screen_info,
432 bool guest)
[email protected]6fd35b72012-03-01 19:46:41433 : RenderWidget(WebKit::WebPopupTypeNone, screen_info),
[email protected]676126f72011-01-15 00:03:51434 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02435 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09436 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02437 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24438 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21439 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02440 opened_by_user_gesture_(true),
441 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24442 page_id_(-1),
443 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46444 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00445 history_list_offset_(-1),
446 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02447 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55448 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31449 cached_is_main_frame_pinned_to_left_(false),
450 cached_is_main_frame_pinned_to_right_(false),
451 cached_has_main_frame_horizontal_scrollbar_(false),
452 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]05a980d7a2012-02-07 22:16:42453 context_has_swapbuffers_complete_callback_(false),
454 queried_for_swapbuffers_complete_callback_(false),
[email protected]d0fb8a72012-03-10 18:54:52455 context_is_web_graphics_context_3d_command_buffer_impl_(false),
[email protected]3354d3e2010-06-10 19:53:02456 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51457 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02458 input_tag_speech_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51459 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51460 media_stream_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18461 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41462 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32463 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11464 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08465 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18466 handling_select_range_(false),
467#if defined(OS_WIN)
468 focused_plugin_id_(-1),
469#endif
[email protected]8cca3da2012-03-20 08:26:34470 guest_(guest),
[email protected]ef5e98e2011-12-06 09:49:18471 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51472 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56473 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51474 if (opener_id != MSG_ROUTING_NONE)
475 opener_id_ = opener_id;
476
[email protected]74ce1ad2011-12-16 21:51:46477 // Ensure we start with a valid next_page_id_ from the browser.
478 DCHECK_GE(next_page_id_, 0);
479
[email protected]21b3a6ae2011-11-30 00:45:29480#if defined(ENABLE_NOTIFICATIONS)
481 notification_provider_ = new NotificationProvider(this);
482#else
483 notification_provider_ = NULL;
484#endif
485
[email protected]11fee2332011-03-29 20:36:35486 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11487 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35488
[email protected]676126f72011-01-15 00:03:51489 if (counter) {
490 shared_popup_counter_ = counter;
491 shared_popup_counter_->data++;
492 decrement_shared_popup_at_destruction_ = true;
493 } else {
494 shared_popup_counter_ = new SharedRenderViewCounter(0);
495 decrement_shared_popup_at_destruction_ = false;
496 }
497
[email protected]380244092011-10-07 17:26:27498 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51499 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47500 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51501 AddRef();
502
503 // If this is a popup, we must wait for the CreatingNew_ACK message before
504 // completing initialization. Otherwise, we can finish it now.
505 if (opener_id == MSG_ROUTING_NONE) {
506 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55507 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51508 }
509
[email protected]34c61bd52011-05-02 19:38:33510 g_view_map.Get().insert(std::make_pair(webview(), this));
511 webkit_preferences_.Apply(webview());
512 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35513 if (!frame_name.empty())
514 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33515 webview()->settings()->setMinimumTimerInterval(
516 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
517 webkit_glue::kForegroundTabTimerInterval);
518
519 OnSetRendererPrefs(renderer_prefs);
520
[email protected]676126f72011-01-15 00:03:51521 host_window_ = parent_hwnd;
522
[email protected]a026daa2011-04-20 15:49:51523#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51524 if (!p2p_socket_dispatcher_)
525 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51526#endif
[email protected]cae8c8492011-03-03 11:12:18527
[email protected]5b87e782012-02-09 18:19:32528#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02529 if (!media_stream_dispatcher_)
530 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32531#endif
[email protected]735873d2012-01-25 23:31:02532
[email protected]8f6a3b852011-07-19 16:48:56533 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32534#if defined(OS_MACOSX)
535 new TextInputClientObserver(this);
536#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56537
[email protected]217690d2012-01-27 07:33:11538 // The next group of objects all implement RenderViewObserver, so are deleted
539 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41540 devtools_agent_ = new DevToolsAgent(this);
[email protected]063afcb2011-09-29 07:54:32541 renderer_accessibility_ = new RendererAccessibility(this);
[email protected]217690d2012-01-27 07:33:11542 mouse_lock_dispatcher_ = new MouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40543 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32544
[email protected]1784b2f2011-11-24 10:53:48545 new IdleUserDetector(this);
546
[email protected]766a7082012-02-03 23:39:15547 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
548 if (command_line.HasSwitch(switches::kDomAutomationController))
549 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
550
[email protected]7ddea9802012-02-22 23:08:05551 bool enable_fixed_layout =
552 command_line.HasSwitch(switches::kEnableFixedLayout);
553 webview()->enableFixedLayoutMode(enable_fixed_layout);
554 if (enable_fixed_layout)
555 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
[email protected]7ddea9802012-02-22 23:08:05556
[email protected]e48869a2011-04-01 19:56:03557 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29558}
559
[email protected]310ebd6302011-10-10 19:06:28560RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03561 history_page_ids_.clear();
562
[email protected]0aa55312008-10-17 21:53:08563 if (decrement_shared_popup_at_destruction_)
564 shared_popup_counter_->data--;
565
[email protected]a1128322009-10-06 18:38:46566 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47567 while (!file_chooser_completions_.empty()) {
568 if (file_chooser_completions_.front()->completion) {
569 file_chooser_completions_.front()->completion->didChooseFile(
570 WebVector<WebString>());
571 }
572 file_chooser_completions_.pop_front();
573 }
[email protected]a1128322009-10-06 18:38:46574
[email protected]83dde542009-09-11 20:59:55575#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11576 // Destroy all fake plugin window handles on the browser side.
577 while (!fake_plugin_window_handles_.empty()) {
578 // Make sure no NULL plugin window handles were inserted into this list.
579 DCHECK(*fake_plugin_window_handles_.begin());
580 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
581 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
582 }
[email protected]83dde542009-09-11 20:59:55583#endif
[email protected]98324892009-09-09 21:16:05584
[email protected]60c42a8c72009-10-09 04:08:59585#ifndef NDEBUG
586 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49587 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59588 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
589 DCHECK_NE(this, it->second) << "Failed to call Close?";
590#endif
[email protected]676126f72011-01-15 00:03:51591
[email protected]273558fb2012-01-12 15:03:51592 // MediaStreamImpl holds weak references to RenderViewObserver objects,
593 // ensure it's deleted before the observers.
594 media_stream_impl_ = NULL;
595
[email protected]310ebd6302011-10-10 19:06:28596 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51597 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59598}
599
600/*static*/
[email protected]310ebd6302011-10-10 19:06:28601RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31602 ViewMap* views = g_view_map.Pointer();
603 ViewMap::iterator it = views->find(webview);
604 return it == views->end() ? NULL : it->second;
605}
606
607/*static*/
608content::RenderView*
609 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28610 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31611}
612
613/*static*/
614void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49615 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59616 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
617 if (!visitor->Visit(it->second))
618 return;
619 }
620}
621
622/*static*/
[email protected]310ebd6302011-10-10 19:06:28623RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15624 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08625 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31626 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08627 const WebPreferences& webkit_prefs,
628 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34629 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56630 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26631 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46632 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41633 int32 next_page_id,
[email protected]8cca3da2012-03-20 08:26:34634 const WebKit::WebScreenInfo& screen_info,
635 bool guest) {
initial.commit09911bf2008-07-26 23:55:29636 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28637 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51638 parent_hwnd,
639 opener_id,
640 renderer_prefs,
641 webkit_prefs,
642 counter,
643 routing_id,
[email protected]9f4f3322012-01-18 22:29:56644 surface_id,
[email protected]676126f72011-01-15 00:03:51645 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46646 frame_name,
[email protected]6fd35b72012-03-01 19:46:41647 next_page_id,
[email protected]8cca3da2012-03-20 08:26:34648 screen_info,
649 guest);
initial.commit09911bf2008-07-26 23:55:29650}
651
[email protected]273558fb2012-01-12 15:03:51652WebKit::WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
653 WebKit::WebPeerConnectionHandlerClient* client) {
654 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
655 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
656 return NULL;
657 EnsureMediaStreamImpl();
[email protected]5b87e782012-02-09 18:19:32658 if (!media_stream_impl_.get())
659 return NULL;
[email protected]273558fb2012-01-12 15:03:51660 return media_stream_impl_->CreatePeerConnectionHandler(client);
661}
662
[email protected]310ebd6302011-10-10 19:06:28663void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51664 observers_.AddObserver(observer);
665}
666
[email protected]310ebd6302011-10-10 19:06:28667void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
668 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51669 observers_.RemoveObserver(observer);
670}
671
[email protected]310ebd6302011-10-10 19:06:28672WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26673 return static_cast<WebKit::WebView*>(webwidget());
674}
675
[email protected]310ebd6302011-10-10 19:06:28676void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40677 if (!enabled) {
678 load_progress_tracker_.reset(NULL);
679 return;
680 }
681 if (load_progress_tracker_ == NULL)
682 load_progress_tracker_.reset(new LoadProgressTracker(this));
683}
684
[email protected]310ebd6302011-10-10 19:06:28685void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51686 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29687}
688
[email protected]310ebd6302011-10-10 19:06:28689void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26690 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30691 // If the renderer is visible, set initial visibility and focus state.
692 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34693#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30694 delegate->SetContainerVisibility(true);
695 if (webview() && webview()->isActive())
696 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34697#endif
[email protected]49232292010-09-03 19:07:30698 }
[email protected]784ea1ab2010-09-18 00:02:34699 // Plugins start assuming the content has focus (so that they work in
700 // environments where RenderView isn't hosting them), so we always have to
701 // set the initial state. See webplugin_delegate_impl.h for details.
702 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26703}
704
[email protected]310ebd6302011-10-10 19:06:28705void RenderViewImpl::UnregisterPluginDelegate(
706 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26707 plugin_delegates_.erase(delegate);
708}
[email protected]d8fd6fa2010-02-01 15:54:26709
[email protected]310ebd6302011-10-10 19:06:28710bool RenderViewImpl::GetPluginInfo(const GURL& url,
711 const GURL& page_url,
712 const std::string& mime_type,
713 webkit::WebPluginInfo* plugin_info,
714 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08715 bool found = false;
716 Send(new ViewHostMsg_GetPluginInfo(
717 routing_id_, url, page_url, mime_type, &found, plugin_info,
718 actual_mime_type));
719 return found;
720}
721
[email protected]310ebd6302011-10-10 19:06:28722bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27723 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27724 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41725 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26726
[email protected]676126f72011-01-15 00:03:51727 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
728 RenderViewObserver* observer;
729 while ((observer = it.GetNext()) != NULL)
730 if (observer->OnMessageReceived(message))
731 return true;
[email protected]b2abac72009-02-26 12:39:28732
[email protected]a95986a82010-12-24 06:19:28733 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40734 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28735 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29736 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
737 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56738 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29739 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
740 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
741 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
742 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27743#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35744 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27745#endif
initial.commit09911bf2008-07-26 23:55:29746 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15747 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29748 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
749 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
750 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08751 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29752 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15753 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29754 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49755 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
756 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17757 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17758 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41759 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54760 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
761 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29762 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18763 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
764 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29765 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48766 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55767 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
768 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
769 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
770 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
771 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
772 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
773 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45774 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40775 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29776 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19777 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
778 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29779 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
780 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
781 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51782 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
783 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29784 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04785 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15786 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29787 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
788 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08789 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
790 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00791 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16792 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14793 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25794 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
795 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47796 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34797 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10798 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
799 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51800 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56801 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36802 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34803 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:12804 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
805 OnSetNavigationStartTime)
[email protected]6ce7abc52010-02-02 18:40:14806#if defined(OS_MACOSX)
807 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13808 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13809 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
810 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14811#endif
[email protected]446705872009-09-10 07:22:48812 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33813 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33814 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
815 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24816 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42817 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
818 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19819 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
820 OnGetAllSavableResourceLinksForCurrentPage)
821 IPC_MESSAGE_HANDLER(
822 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
823 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08824#if defined(OS_MACOSX)
825 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
826#endif
[email protected]521b2482011-01-15 00:10:10827 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51828 // TODO(viettrungluu): Move to a separate message filter.
829#if defined(ENABLE_FLAPPER_HACKS)
830 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
831#endif
[email protected]54ca3ca892011-06-07 21:14:54832#if defined(OS_MACOSX)
833 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
834#endif
[email protected]9e1ad4b2011-08-14 16:49:19835 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
836 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18837 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51838 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19839
initial.commit09911bf2008-07-26 23:55:29840 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28841 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29842 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40843
844 if (!msg_is_ok) {
845 // The message had a handler, but its deserialization failed.
846 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28847 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40848 }
849
[email protected]a95986a82010-12-24 06:19:28850 return handled;
initial.commit09911bf2008-07-26 23:55:29851}
852
[email protected]310ebd6302011-10-10 19:06:28853void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:18854 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:29855 if (!webview())
856 return;
857
[email protected]440a0e52011-09-13 17:38:58858 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
859
[email protected]007733c2011-11-17 00:34:07860 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03861
862 // If this is a stale back/forward (due to a recent navigation the browser
863 // didn't know about), ignore it.
864 if (IsBackForwardToStaleEntry(params, is_reload))
865 return;
866
[email protected]992db4c2011-05-12 15:37:15867 // Swap this renderer back in if necessary.
868 if (is_swapped_out_)
869 SetSwappedOut(false);
870
[email protected]3cc72b12010-03-18 23:03:00871 history_list_offset_ = params.current_history_list_offset;
872 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03873 if (history_list_length_ >= 0)
874 history_page_ids_.resize(history_list_length_, -1);
875 if (params.pending_history_list_offset >= 0 &&
876 params.pending_history_list_offset < history_list_length_)
877 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00878
[email protected]38b592902011-04-16 02:08:42879 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29880
[email protected]26aa0482009-09-30 16:55:27881 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45882 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29883 // We cannot reload if we do not have any history state. This happens, for
884 // example, when recovering from a crash. Our workaround here is a bit of
885 // a hack since it means that reload after a crashed tab does not cause an
886 // end-to-end cache validation.
887 is_reload = false;
888 }
889
[email protected]007733c2011-11-17 00:34:07890 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
891 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50892
[email protected]04d3c6e2009-05-22 17:00:13893 // If we are reloading, then WebKit will use the history state of the current
894 // page, so we should just ignore any given history state. Otherwise, if we
895 // have history state, then we need to navigate to it, which corresponds to a
896 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55897 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29898 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02899 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29900 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55901 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13902 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58903 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45904 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17905 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13906 } else {
907 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28908 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29909
[email protected]e6f546c32009-07-01 17:12:55910 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23911 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13912
[email protected]dd7daa82009-08-10 05:46:45913 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55914 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13915
[email protected]445e1042011-12-03 21:03:15916 if (params.referrer.url.is_valid()) {
917 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
918 params.referrer.policy,
919 params.url,
920 WebString::fromUTF8(params.referrer.url.spec()));
921 if (!referrer.isEmpty())
922 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28923 }
[email protected]04d3c6e2009-05-22 17:00:13924
[email protected]52c68652010-12-07 17:47:04925 if (!params.extra_headers.empty()) {
926 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
927 params.extra_headers.end(), "\n");
928 i.GetNext(); ) {
929 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
930 WebString::fromUTF8(i.values()));
931 }
932 }
[email protected]dd7daa82009-08-10 05:46:45933 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50934 }
935
[email protected]77f17a82009-05-21 04:42:54936 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07937 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29938}
939
[email protected]310ebd6302011-10-10 19:06:28940bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03941 const ViewMsg_Navigate_Params& params,
942 bool is_reload) {
943 // Make sure this isn't a back/forward to an entry we have already cropped
944 // or replaced from our history, before the browser knew about it. If so,
945 // a new navigation has committed in the mean time, and we can ignore this.
946 bool is_back_forward = !is_reload && !params.state.empty();
947
948 // Note: if the history_list_length_ is 0 for a back/forward, we must be
949 // restoring from a previous session. We'll update our state in OnNavigate.
950 if (!is_back_forward || history_list_length_ <= 0)
951 return false;
952
953 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
954
955 // Check for whether the forward history has been cropped due to a recent
956 // navigation the browser didn't know about.
957 if (params.pending_history_list_offset >= history_list_length_)
958 return true;
959
960 // Check for whether this entry has been replaced with a new one.
961 int expected_page_id =
962 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44963 if (expected_page_id > 0 && params.page_id != expected_page_id) {
964 if (params.page_id < expected_page_id)
965 return true;
966
967 // Otherwise we've removed an earlier entry and should have shifted all
968 // entries left. For now, it's ok to lazily update the list.
969 // TODO(creis): Notify all live renderers when we remove entries from
970 // the front of the list, so that we don't hit this case.
971 history_page_ids_[params.pending_history_list_offset] = params.page_id;
972 }
[email protected]d466b8a2011-07-15 21:48:03973
974 return false;
975}
976
initial.commit09911bf2008-07-26 23:55:29977// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28978void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44979 if (webview()) {
980 WebFrame* main_frame = webview()->mainFrame();
981 // Stop the alt error page fetcher. If we let it continue it may complete
982 // and cause RenderViewHostManager to swap to this RenderView, even though
983 // it may no longer be active.
984 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
985 StopAltErrorPageFetcher(main_frame->dataSource());
986 main_frame->stopLoading();
987 }
initial.commit09911bf2008-07-26 23:55:29988}
989
[email protected]ecbf10d2010-02-18 13:03:29990// Reload current focused frame.
991// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28992void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29993 if (webview() && webview()->focusedFrame()) {
994 // We always obey the cache (ignore_cache=false) here.
995 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
996 // a cache-ignoring reload of the frame.
997 webview()->focusedFrame()->reload(false);
998 }
[email protected]1dda4022010-01-28 18:24:56999}
1000
[email protected]310ebd6302011-10-10 19:06:281001void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271002 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291003}
1004
[email protected]310ebd6302011-10-10 19:06:281005void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251006 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271007 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251008 return;
1009
[email protected]26aa0482009-09-30 16:55:271010 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451011 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251012}
1013
[email protected]310ebd6302011-10-10 19:06:281014void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291015 // Check if there is a targeturl waiting to be sent.
1016 if (target_url_status_ == TARGET_PENDING) {
1017 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1018 pending_target_url_));
1019 }
1020
1021 target_url_status_ = TARGET_NONE;
1022}
1023
[email protected]310ebd6302011-10-10 19:06:281024void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291025 if (!webview())
1026 return;
1027
[email protected]26aa0482009-09-30 16:55:271028 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291029}
1030
[email protected]310ebd6302011-10-10 19:06:281031void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291032 if (!webview())
1033 return;
1034
[email protected]26aa0482009-09-30 16:55:271035 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291036}
1037
[email protected]310ebd6302011-10-10 19:06:281038void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291039 if (!webview())
1040 return;
1041
[email protected]26aa0482009-09-30 16:55:271042 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291043}
1044
[email protected]310ebd6302011-10-10 19:06:281045void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291046 if (!webview())
1047 return;
1048
[email protected]f6b1856b2011-06-29 22:02:531049 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1050 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291051}
1052
[email protected]c0cc3092009-09-12 08:27:271053#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281054void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351055 if (!webview())
1056 return;
1057
1058 // Since the find pasteboard supports only plain text, this can be simpler
1059 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271060 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351061 if (frame->hasSelection()) {
1062 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271063 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171064 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351065 }
[email protected]a954bf72009-09-12 07:30:351066}
[email protected]c0cc3092009-09-12 08:27:271067#endif
[email protected]a954bf72009-09-12 07:30:351068
[email protected]310ebd6302011-10-10 19:06:281069void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291070 if (!webview())
1071 return;
1072
[email protected]26aa0482009-09-30 16:55:271073 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291074}
1075
[email protected]44bf7002011-10-16 02:46:151076void RenderViewImpl::OnPasteAndMatchStyle() {
1077 if (!webview())
1078 return;
1079
1080 webview()->focusedFrame()->executeCommand(
1081 WebString::fromUTF8("PasteAndMatchStyle"));
1082}
1083
[email protected]310ebd6302011-10-10 19:06:281084void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291085 if (!webview())
1086 return;
1087
[email protected]1ff7a032010-02-03 02:46:031088 WebFrame* frame = webview()->focusedFrame();
1089 if (!frame->hasSelection())
1090 frame->selectWordAroundCaret();
1091 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291092}
1093
[email protected]310ebd6302011-10-10 19:06:281094void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291095 if (!webview())
1096 return;
1097
[email protected]26aa0482009-09-30 16:55:271098 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291099}
1100
[email protected]310ebd6302011-10-10 19:06:281101void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291102 if (!webview())
1103 return;
1104
[email protected]26aa0482009-09-30 16:55:271105 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221106 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291107}
1108
[email protected]310ebd6302011-10-10 19:06:281109void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1110 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081111 if (!webview())
1112 return;
1113
1114 handling_select_range_ = true;
1115 webview()->focusedFrame()->selectRange(start, end);
1116 handling_select_range_ = false;
1117}
1118
[email protected]310ebd6302011-10-10 19:06:281119void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1120 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191121 DCHECK(history_length >= 0);
1122 DCHECK(history_list_offset_ == history_list_length_ - 1);
1123 DCHECK(minimum_page_id >= -1);
1124
1125 // Generate the new list.
1126 std::vector<int32> new_history_page_ids(history_length, -1);
1127 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1128 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1129 continue;
1130 new_history_page_ids.push_back(history_page_ids_[i]);
1131 }
1132 new_history_page_ids.swap(history_page_ids_);
1133
1134 // Update indexes.
1135 history_list_length_ = history_page_ids_.size();
1136 history_list_offset_ = history_list_length_ - 1;
1137}
1138
1139
[email protected]310ebd6302011-10-10 19:06:281140void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291141 if (!webview())
1142 return;
[email protected]26aa0482009-09-30 16:55:271143 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291144}
1145
[email protected]54ca3ca892011-06-07 21:14:541146#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281147void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331148 if (!webview())
1149 return;
1150 if (in_live_resize)
1151 webview()->willStartLiveResize();
1152 else
1153 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541154}
1155#endif
1156
[email protected]310ebd6302011-10-10 19:06:281157void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1158 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091159 WebKit::WebNode node = GetFocusedNode();
1160 if (!node.isNull()) {
1161 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191162 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511163 }
1164}
1165
initial.commit09911bf2008-07-26 23:55:291166///////////////////////////////////////////////////////////////////////////////
1167
1168// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281169void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451170 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291171 DCHECK(ds);
1172
[email protected]726985e22009-06-18 21:09:281173 const WebURLRequest& request = ds->request();
1174 const WebURLRequest& original_request = ds->originalRequest();
1175 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291176
[email protected]007733c2011-11-17 00:34:071177 DocumentState* document_state = DocumentState::FromDataSource(ds);
1178 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291179
1180 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281181 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291182 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051183 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291184 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071185 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191186 params.socket_address.set_host(response.remoteIPAddress().utf8());
1187 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031188 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091189 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071190 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291191 // SSL state specified in the request takes precedence over the one in the
1192 // response.
1193 // So far this is only intended for error pages that are not expected to be
1194 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281195 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071196 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291197 } else {
[email protected]726985e22009-06-18 21:09:281198 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291199 }
1200
1201 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311202 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291203
[email protected]5f9b8712011-11-23 08:55:571204 if (frame->document().baseURL() != params.url)
1205 params.base_url = frame->document().baseURL();
1206
[email protected]726985e22009-06-18 21:09:281207 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241208 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041209 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291210
[email protected]007733c2011-11-17 00:34:071211 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351212 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071213 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291214
1215 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071216 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291217 if (password_form_data)
1218 params.password_form = *password_form_data;
1219
1220 params.gesture = navigation_gesture_;
1221 navigation_gesture_ = NavigationGestureUnknown;
1222
[email protected]0f38dc4552011-02-25 11:24:001223 // Make navigation state a part of the FrameNavigate message so that commited
1224 // entry had it at all times.
1225 const WebHistoryItem& item = frame->currentHistoryItem();
1226 if (!item.isNull()) {
1227 params.content_state = webkit_glue::HistoryItemToString(item);
1228 } else {
1229 params.content_state =
1230 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1231 }
1232
[email protected]dd7daa82009-08-10 05:46:451233 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291234 // Top-level navigation.
1235
[email protected]b75b8292010-10-01 07:28:251236 // Set zoom level, but don't do it for full-page plugin since they don't use
1237 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011238 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541239 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251240 if (webview()->mainFrame()->document().isPluginDocument()) {
1241 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251242 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251243 } else {
1244 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251245 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251246 }
1247
[email protected]f85f0702010-01-30 09:31:011248 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511249 // This zoom level was merely recorded transiently for this load. We can
1250 // erase it now. If at some point we reload this page, the browser will
1251 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011252 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511253 }
1254
[email protected]b75b8292010-10-01 07:28:251255 // Reset the zoom limits in case a plugin had changed them previously. This
1256 // will also call us back which will cause us to send a message to
1257 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251258 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011259 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1260 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251261
initial.commit09911bf2008-07-26 23:55:291262 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551263 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291264
[email protected]daa8c58e2009-06-15 17:21:101265 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581266 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291267 // If the main frame does a load, it should not be reported as a subframe
1268 // navigation. This can occur in the following case:
1269 // 1. You're on a site with frames.
1270 // 2. You do a subframe navigation. This is stored with transition type
1271 // MANUAL_SUBFRAME.
1272 // 3. You navigate to some non-frame site, say, google.com.
1273 // 4. You navigate back to the page from step 2. Since it was initially
1274 // MANUAL_SUBFRAME, it will be that same transition type here.
1275 // We don't want that, because any navigation that changes the toplevel
1276 // frame should be tracked as a toplevel navigation (this allows us to
1277 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581278 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291279 }
1280
initial.commit09911bf2008-07-26 23:55:291281 // If we have a valid consumed client redirect source,
1282 // the page contained a client redirect (meta refresh, document.loc...),
1283 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151284 if (completed_client_redirect_src_.url.is_valid()) {
1285 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291286 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581287 params.transition = static_cast<content::PageTransition>(
1288 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291289 } else {
1290 // Bug 654101: the referrer will be empty on https->http transitions. It
1291 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151292 params.referrer = Referrer(GURL(
1293 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:401294 GetReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291295 }
1296
[email protected]726985e22009-06-18 21:09:281297 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051298 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291299 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051300 params.post_id = ExtractPostId(item);
1301 }
initial.commit09911bf2008-07-26 23:55:291302
[email protected]c2a797d2009-09-21 16:46:321303 // Save some histogram data so we can compute the average memory used per
1304 // page load of the glyphs.
1305 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1306 webkit_glue::GetGlyphPageCount());
1307
[email protected]15cf526b2010-02-12 06:33:491308 // This message needs to be sent before any of allowScripts(),
1309 // allowImages(), allowPlugins() is called for the new page, so that when
1310 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1311 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291312 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1313 } else {
1314 // Subframe navigation: the type depends on whether this navigation
1315 // generated a new session history entry. When they do generate a session
1316 // history entry, it means the user initiated the navigation and we should
1317 // mark it as such. This test checks if this is the first time UpdateURL
1318 // has been called since WillNavigateToURL was called to initiate the load.
1319 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581320 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291321 else
[email protected]2905f742011-10-13 03:51:581322 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291323
initial.commit09911bf2008-07-26 23:55:291324 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1325 }
1326
1327 last_page_id_sent_to_browser_ =
1328 std::max(last_page_id_sent_to_browser_, page_id_);
1329
1330 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101331 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581332 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291333}
1334
1335// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281336void RenderViewImpl::UpdateTitle(WebFrame* frame,
1337 const string16& title,
1338 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461339 // Ignore all but top level navigations.
1340 if (frame->parent())
1341 return;
1342
1343 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1344 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1345 title_direction));
initial.commit09911bf2008-07-26 23:55:291346}
1347
[email protected]310ebd6302011-10-10 19:06:281348void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1349 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291350 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271351 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291352 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301353 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291354 last_encoding_name_ = encoding_name;
1355
[email protected]e38f40152008-09-12 23:08:301356 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291357 }
1358}
1359
[email protected]e15f680732010-11-23 22:30:201360// Sends the last committed session history state to the browser so it will be
1361// saved before we navigate to a new page. This must be called *before* the
1362// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281363void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291364 // If we have a valid page ID at this point, then it corresponds to the page
1365 // we are navigating away from. Otherwise, this is the first navigation, so
1366 // there is no past session history to record.
1367 if (page_id_ == -1)
1368 return;
1369
[email protected]ca948a22009-06-25 19:36:171370 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271371 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051372 SendUpdateState(item);
1373}
1374
1375void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171376 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291377 return;
[email protected]ca948a22009-06-25 19:36:171378
[email protected]6459800a2012-03-27 23:57:051379 // Don't send state updates for chrome::kSwappedOutURL.
1380 if (item.urlString() == WebString::fromUTF8(chrome::kSwappedOutURL))
1381 return;
1382
[email protected]ca948a22009-06-25 19:36:171383 Send(new ViewHostMsg_UpdateState(
1384 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291385}
1386
[email protected]310ebd6302011-10-10 19:06:281387void RenderViewImpl::OpenURL(WebFrame* frame,
1388 const GURL& url,
[email protected]445e1042011-12-03 21:03:151389 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281390 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171391 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581392 routing_id_,
1393 url,
1394 referrer,
1395 NavigationPolicyToDisposition(policy),
1396 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171397}
1398
[email protected]79dbc662009-09-04 05:42:511399// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291400
[email protected]310ebd6302011-10-10 19:06:281401void RenderViewImpl::LoadNavigationErrorPage(
1402 WebFrame* frame,
1403 const WebURLRequest& failed_request,
1404 const WebURLError& error,
1405 const std::string& html,
1406 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581407 std::string alt_html;
1408 const std::string* error_html;
1409
1410 if (!html.empty()) {
1411 error_html = &html;
1412 } else {
1413 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1414 failed_request, error, &alt_html, NULL);
1415 error_html = &alt_html;
1416 }
1417
1418 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361419 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251420 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551421 replace);
initial.commit09911bf2008-07-26 23:55:291422}
1423
[email protected]269f86d2011-12-07 02:43:471424bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281425 const string16& message,
1426 const string16& default_value,
1427 const GURL& frame_url,
1428 string16* result) {
initial.commit09911bf2008-07-26 23:55:291429 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411430 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291431 if (!result)
1432 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291433
[email protected]12636df2009-09-28 22:32:211434 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1435 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291436 return success;
1437}
1438
[email protected]310ebd6302011-10-10 19:06:281439bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571440 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1441 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1442 // it is particularly important that we do not call willEnterModalLoop as
1443 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441444 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1445 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571446
1447 message->EnableMessagePumping(); // Runs a nested message loop.
1448 return Send(message);
1449}
1450
[email protected]48c9cf2d2009-09-16 16:47:521451// WebKit::WebViewClient ------------------------------------------------------
1452
[email protected]916dfb62012-03-05 03:39:371453WebView* RenderViewImpl::createView(
1454 WebFrame* creator,
1455 const WebURLRequest& request,
1456 const WebWindowFeatures& features,
1457 const WebString& frame_name,
1458 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521459 // Check to make sure we aren't overloading on popups.
1460 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1461 return NULL;
1462
[email protected]8ab04652010-06-12 02:47:261463 ViewHostMsg_CreateWindow_Params params;
1464 params.opener_id = routing_id_;
1465 params.user_gesture = creator->isProcessingUserGesture();
1466 params.window_container_type = WindowFeaturesToContainerType(features);
1467 params.session_storage_namespace_id = session_storage_namespace_id_;
1468 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111469 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411470 params.opener_url = creator->document().url();
1471 params.opener_security_origin =
1472 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591473 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1474 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111475 if (!request.isNull())
1476 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261477
[email protected]48c9cf2d2009-09-16 16:47:521478 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561479 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341480 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521481
[email protected]380244092011-10-07 17:26:271482 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261483 new ViewHostMsg_CreateWindow(params,
1484 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561485 &surface_id,
[email protected]8ab04652010-06-12 02:47:261486 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211487 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521488 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521489
[email protected]8cca3da2012-03-20 08:26:341490 // TODO(fsamuel): The host renderer needs to be able to control whether
1491 // the guest renderer is allowed to do this or not. This current
1492 // behavior is not well defined.
[email protected]310ebd6302011-10-10 19:06:281493 RenderViewImpl* view = RenderViewImpl::Create(
1494 0,
1495 routing_id_,
1496 renderer_preferences_,
1497 webkit_preferences_,
1498 shared_popup_counter_,
1499 routing_id,
[email protected]9f4f3322012-01-18 22:29:561500 surface_id,
[email protected]310ebd6302011-10-10 19:06:281501 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461502 frame_name,
[email protected]6fd35b72012-03-01 19:46:411503 1,
[email protected]8cca3da2012-03-20 08:26:341504 screen_info_,
1505 guest_);
[email protected]8ab04652010-06-12 02:47:261506 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521507
[email protected]007a848b2009-10-26 15:55:461508 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591509 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461510
[email protected]48c9cf2d2009-09-16 16:47:521511 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411512 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521513 if (!creator_url.is_valid() || !creator_url.IsStandard())
1514 creator_url = GURL();
1515 view->creator_url_ = creator_url;
1516
1517 // Copy over the alternate error page URL so we can have alt error pages in
1518 // the new render view (we don't need the browser to send the URL back down).
1519 view->alternate_error_page_url_ = alternate_error_page_url_;
1520
1521 return view->webview();
1522}
1523
[email protected]310ebd6302011-10-10 19:06:281524WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411525 RenderWidget* widget =
1526 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521527 return widget->webwidget();
1528}
1529
[email protected]310ebd6302011-10-10 19:06:281530WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441531 // TODO(jcivelli): Remove this deprecated method when its been removed from
1532 // the WebViewClient interface. It's been replaced by
1533 // createExternalPopupMenu.
1534 NOTREACHED();
1535 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521536}
1537
[email protected]310ebd6302011-10-10 19:06:281538WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081539 const WebPopupMenuInfo& popup_menu_info,
1540 WebExternalPopupMenuClient* popup_menu_client) {
1541 DCHECK(!external_popup_menu_.get());
1542 external_popup_menu_.reset(
1543 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1544 return external_popup_menu_.get();
1545}
1546
[email protected]310ebd6302011-10-10 19:06:281547RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521548 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531549 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421550 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411551 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531552 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271553 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391554 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561555 return widget;
[email protected]79c7bed2010-09-14 22:28:391556}
1557
[email protected]310ebd6302011-10-10 19:06:281558WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1559 unsigned quota) {
[email protected]c09f12c62012-03-24 00:03:561560#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND
1561 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1562 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1563 session_storage_namespace_id_);
1564#else
[email protected]bd92c3a2010-01-13 05:02:341565 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391566 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291567 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1568 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1569 session_storage_namespace_id_);
[email protected]c09f12c62012-03-24 00:03:561570#endif
[email protected]bd92c3a2010-01-13 05:02:341571}
1572
[email protected]7e8b4d12012-01-20 23:39:511573WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]40ec0c12012-03-08 12:34:401574 const WebGraphicsContext3D::Attributes& attributes) {
[email protected]7e8b4d12012-01-20 23:39:511575 if (!webview())
1576 return NULL;
1577 // The WebGraphicsContext3DInProcessImpl code path is used for
1578 // layout tests (though not through this code) as well as for
1579 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511580 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571581 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
[email protected]29dea0e2012-03-16 01:46:581582 attributes, true);
[email protected]7e8b4d12012-01-20 23:39:511583 } else {
[email protected]b3e83de2012-02-07 03:33:281584 GURL url;
1585 if (webview()->mainFrame())
1586 url = GURL(webview()->mainFrame()->document().url());
1587
[email protected]b3e83de2012-02-07 03:33:281588 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1589 new WebGraphicsContext3DCommandBufferImpl(
[email protected]29dea0e2012-03-16 01:46:581590 surface_id(), url, RenderThreadImpl::current(), AsWeakPtr()));
[email protected]b3e83de2012-02-07 03:33:281591
1592 if (!context->Initialize(attributes))
[email protected]56200f012012-02-03 23:13:571593 return NULL;
[email protected]d0fb8a72012-03-10 18:54:521594 context_is_web_graphics_context_3d_command_buffer_impl_ = true;
[email protected]56200f012012-02-03 23:13:571595 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511596 }
[email protected]7e8b4d12012-01-20 23:39:511597}
1598
[email protected]310ebd6302011-10-10 19:06:281599void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521600 const WebConsoleMessage& message, const WebString& source_name,
1601 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081602 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511603 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081604 case WebConsoleMessage::LevelTip:
1605 log_severity = logging::LOG_VERBOSE;
1606 break;
1607 case WebConsoleMessage::LevelLog:
1608 log_severity = logging::LOG_INFO;
1609 break;
1610 case WebConsoleMessage::LevelWarning:
1611 log_severity = logging::LOG_WARNING;
1612 break;
1613 case WebConsoleMessage::LevelError:
1614 log_severity = logging::LOG_ERROR;
1615 break;
1616 default:
1617 NOTREACHED();
1618 }
1619
[email protected]48c9cf2d2009-09-16 16:47:521620 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081621 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311622 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521623 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311624 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521625}
1626
[email protected]310ebd6302011-10-10 19:06:281627void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421628 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521629}
1630
[email protected]310ebd6302011-10-10 19:06:281631WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511632 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021633}
1634
[email protected]310ebd6302011-10-10 19:06:281635bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121636 const WebString& path,
1637 WebFileChooserCompletion* chooser_completion) {
1638 int id = enumeration_completion_id_++;
1639 enumeration_completions_[id] = chooser_completion;
1640 return Send(new ViewHostMsg_EnumerateDirectory(
1641 routing_id_,
1642 id,
1643 webkit_glue::WebStringToFilePath(path)));
1644}
1645
[email protected]310ebd6302011-10-10 19:06:281646void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521647 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141648 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521649 return;
1650 }
1651
1652 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521653
1654 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311655
1656 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521657}
1658
[email protected]310ebd6302011-10-10 19:06:281659void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521660 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141661 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521662 return;
1663 }
1664
1665 is_loading_ = false;
1666
1667 // NOTE: For now we're doing the safest thing, and sending out notification
1668 // when done loading. This currently isn't an issue as the favicon is only
1669 // displayed when done loading. Ideally we would send notification when
1670 // finished parsing the head, but webkit doesn't support that yet.
1671 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521672 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1673
[email protected]90109412010-12-15 17:14:241674 if (load_progress_tracker_ != NULL)
1675 load_progress_tracker_->DidStopLoading();
1676
[email protected]93b9d692011-04-13 00:44:311677 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521678}
1679
[email protected]310ebd6302011-10-10 19:06:281680void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1681 double load_progress) {
[email protected]90109412010-12-15 17:14:241682 if (load_progress_tracker_ != NULL)
1683 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1684}
1685
[email protected]310ebd6302011-10-10 19:06:281686bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061687#if defined(OS_MACOSX)
1688 return true;
1689#else
1690 return false;
1691#endif
1692}
1693
[email protected]310ebd6302011-10-10 19:06:281694bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031695#if defined(OS_WIN)
1696 return true;
1697#else
1698 return false;
1699#endif
1700}
1701
[email protected]310ebd6302011-10-10 19:06:281702void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081703 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031704 return;
[email protected]4fb60142011-08-09 02:22:081705 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011706
[email protected]b781ff282011-08-20 06:19:361707 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031708}
1709
[email protected]310ebd6302011-10-10 19:06:281710void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121711 const std::string& name = UTF16ToUTF8(command_name);
1712 if (StartsWithASCII(name, "Move", true) ||
1713 StartsWithASCII(name, "Insert", true) ||
1714 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031715 return;
[email protected]f1a29a02011-10-06 23:08:441716 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031717}
1718
[email protected]310ebd6302011-10-10 19:06:281719bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101720 if (edit_commands_.empty())
1721 return false;
1722
[email protected]26aa0482009-09-30 16:55:271723 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101724 if (!frame)
1725 return false;
1726
1727 EditCommands::iterator it = edit_commands_.begin();
1728 EditCommands::iterator end = edit_commands_.end();
1729
[email protected]507b33ea2009-09-29 03:56:511730 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101731 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331732 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1733 // key (but it's the exception). Once one edit command is not executed, it
1734 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101735 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1736 WebString::fromUTF8(it->value)))
1737 break;
[email protected]507b33ea2009-09-29 03:56:511738 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101739 }
1740
[email protected]507b33ea2009-09-29 03:56:511741 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101742}
1743
[email protected]da8543762012-03-20 08:52:201744WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
1745 WebKit::WebColorChooserClient* client,
1746 const WebKit::WebColor& initial_color) {
1747 RendererWebColorChooserImpl* color_chooser =
1748 new RendererWebColorChooserImpl(this, client);
1749 color_chooser->Open(static_cast<SkColor>(initial_color));
1750 return color_chooser;
1751}
1752
[email protected]310ebd6302011-10-10 19:06:281753bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351754 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471755 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351756 // Do not open the file dialog in a hidden RenderView.
1757 if (is_hidden())
1758 return false;
[email protected]8caadeb2011-11-22 02:45:231759 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261760 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231761 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261762 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231763 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501764 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231765 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261766 else
[email protected]8caadeb2011-11-22 02:45:231767 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471768 ipc_params.title = params.title;
1769 ipc_params.default_file_name =
1770 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461771 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1772 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1773 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471774
1775 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461776}
1777
[email protected]269f86d2011-12-07 02:43:471778void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1779 const WebString& message) {
1780 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411781 message,
1782 string16(),
[email protected]b6cb3a842011-06-24 18:28:411783 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521784 NULL);
1785}
1786
[email protected]269f86d2011-12-07 02:43:471787bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1788 const WebString& message) {
1789 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411790 message,
1791 string16(),
[email protected]b6cb3a842011-06-24 18:28:411792 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521793 NULL);
1794}
1795
[email protected]269f86d2011-12-07 02:43:471796bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1797 const WebString& message,
1798 const WebString& default_value,
1799 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411800 string16 result;
[email protected]269f86d2011-12-07 02:43:471801 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411802 message,
1803 default_value,
[email protected]b6cb3a842011-06-24 18:28:411804 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521805 &result);
1806 if (ok)
[email protected]4f5ce842011-05-27 19:34:411807 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521808 return ok;
1809}
1810
[email protected]310ebd6302011-10-10 19:06:281811bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521812 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151813 // If we are swapping out, we have already run the beforeunload handler.
1814 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1815 // at all, to avoid running it twice.
1816 if (is_swapped_out_)
1817 return true;
1818
[email protected]3b3301f62012-02-29 04:32:321819 bool is_reload = false;
1820 WebDataSource* ds = frame->provisionalDataSource();
1821 if (ds)
1822 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
1823
[email protected]48c9cf2d2009-09-16 16:47:521824 bool success = false;
1825 // This is an ignored return value, but is included so we can accept the same
1826 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411827 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211828 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:321829 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:411830 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521831 return success;
1832}
1833
[email protected]310ebd6302011-10-10 19:06:281834void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441835 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:511836 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:371837
1838 // frame is NULL if invoked by BlockedPlugin.
1839 if (frame)
1840 params.frame_id = frame->identifier();
1841
[email protected]db803aae2011-03-05 02:00:421842 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271843 // it. We replace it with an empty GURL so the appropriate items are disabled
1844 // in the context menu.
1845 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1846 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421847 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271848 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101849 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291850 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441851}
1852
[email protected]310ebd6302011-10-10 19:06:281853void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521854}
1855
[email protected]310ebd6302011-10-10 19:06:281856void RenderViewImpl::UpdateTargetURL(const GURL& url,
1857 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581858 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521859 if (latest_url == target_url_)
1860 return;
[email protected]163f8242009-10-30 20:19:551861
[email protected]48c9cf2d2009-09-16 16:47:521862 // Tell the browser to display a destination link.
1863 if (target_url_status_ == TARGET_INFLIGHT ||
1864 target_url_status_ == TARGET_PENDING) {
1865 // If we have a request in-flight, save the URL to be sent when we
1866 // receive an ACK to the in-flight request. We can happily overwrite
1867 // any existing pending sends.
1868 pending_target_url_ = latest_url;
1869 target_url_status_ = TARGET_PENDING;
1870 } else {
[email protected]c85f0212011-11-04 16:54:411871 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1872 // see |ParamTraits<GURL>|.
1873 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1874 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521875 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1876 target_url_ = latest_url;
1877 target_url_status_ = TARGET_INFLIGHT;
1878 }
1879}
1880
[email protected]310ebd6302011-10-10 19:06:281881void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311882 int delay;
1883 if (send_content_state_immediately_)
1884 delay = 0;
1885 else if (is_hidden())
1886 delay = kDelaySecondsForContentStateSyncHidden;
1887 else
1888 delay = kDelaySecondsForContentStateSync;
1889
1890 if (nav_state_sync_timer_.IsRunning()) {
1891 // The timer is already running. If the delay of the timer maches the amount
1892 // we want to delay by, then return. Otherwise stop the timer so that it
1893 // gets started with the right delay.
1894 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1895 return;
1896 nav_state_sync_timer_.Stop();
1897 }
1898
[email protected]d323a172011-09-02 18:23:021899 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281900 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311901}
1902
[email protected]310ebd6302011-10-10 19:06:281903void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551904 mouse_over_url_ = GURL(url);
1905 UpdateTargetURL(mouse_over_url_, focus_url_);
1906}
1907
[email protected]310ebd6302011-10-10 19:06:281908void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551909 focus_url_ = GURL(url);
1910 UpdateTargetURL(focus_url_, mouse_over_url_);
1911}
1912
[email protected]310ebd6302011-10-10 19:06:281913void RenderViewImpl::startDragging(const WebDragData& data,
1914 WebDragOperationsMask mask,
1915 const WebImage& image,
1916 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411917#if WEBKIT_USING_SKIA
1918 SkBitmap bitmap(image.getSkBitmap());
1919#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331920 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411921#endif
1922
[email protected]59f4f2fa2011-03-23 01:00:551923 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521924 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411925 mask,
1926 bitmap,
1927 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521928}
1929
[email protected]310ebd6302011-10-10 19:06:281930bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451931 return renderer_preferences_.can_accept_load_drops;
1932}
1933
[email protected]310ebd6302011-10-10 19:06:281934void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521935 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1936}
1937
[email protected]310ebd6302011-10-10 19:06:281938void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521939 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1940}
1941
[email protected]310ebd6302011-10-10 19:06:281942void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511943 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071944
[email protected]38b592902011-04-16 02:08:421945 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491946}
1947
[email protected]169d4282011-11-30 19:33:591948void RenderViewImpl::didUpdateLayout() {
1949 // We don't always want to set up a timer, only if we've been put in that
1950 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1951 // message.
1952 if (!send_preferred_size_changes_ || !webview())
1953 return;
1954
1955 if (check_preferred_size_timer_.IsRunning())
1956 return;
1957 check_preferred_size_timer_.Start(FROM_HERE,
1958 TimeDelta::FromMilliseconds(0), this,
1959 &RenderViewImpl::CheckPreferredSize);
1960}
1961
[email protected]310ebd6302011-10-10 19:06:281962void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521963 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1964}
1965
[email protected]310ebd6302011-10-10 19:06:281966int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001967 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521968}
1969
[email protected]310ebd6302011-10-10 19:06:281970int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001971 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521972}
1973
[email protected]310ebd6302011-10-10 19:06:281974void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321975 const WebAccessibilityObject& obj,
1976 WebAccessibilityNotification notification) {
1977 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1978}
1979
[email protected]310ebd6302011-10-10 19:06:281980void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141981 const WebString& value) {
1982 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1983 key.utf8(),
1984 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261985}
1986
[email protected]79dbc662009-09-04 05:42:511987// WebKit::WebWidgetClient ----------------------------------------------------
1988
[email protected]310ebd6302011-10-10 19:06:281989void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121990 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1991 // we won't have to test for user gesture anymore and we can
1992 // move that code back to render_widget.cc
1993 if (webview() && webview()->mainFrame() &&
1994 webview()->mainFrame()->isProcessingUserGesture()) {
1995 Send(new ViewHostMsg_Focus(routing_id_));
1996 }
1997}
1998
[email protected]310ebd6302011-10-10 19:06:281999void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122000 // TODO(jcivelli): see TODO above in didFocus().
2001 if (webview() && webview()->mainFrame() &&
2002 webview()->mainFrame()->isProcessingUserGesture()) {
2003 Send(new ViewHostMsg_Blur(routing_id_));
2004 }
2005}
2006
initial.commit09911bf2008-07-26 23:55:292007// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282008// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292009// point to dispatch the ShowView message.
2010//
2011// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282012// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292013//
[email protected]310ebd6302011-10-10 19:06:282014void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292015 DCHECK(!did_show_) << "received extraneous Show call";
2016 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2017
2018 if (did_show_)
2019 return;
2020 did_show_ = true;
2021
[email protected]6779aa12011-03-29 17:32:242022 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042023 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042024
[email protected]28295ec2009-10-16 05:34:332025 // Force new windows to a popup if they were not opened with a user gesture.
2026 if (!opened_by_user_gesture_) {
2027 // We exempt background tabs for compat with older versions of Chrome.
2028 // TODO(darin): This seems bogus. These should have a user gesture, so
2029 // we probably don't need this check.
2030 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2031 policy = WebKit::WebNavigationPolicyNewPopup;
2032 }
2033
initial.commit09911bf2008-07-26 23:55:292034 // NOTE: initial_pos_ may still have its default values at this point, but
2035 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2036 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282037 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2038 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292039 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242040 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292041}
2042
[email protected]310ebd6302011-10-10 19:06:282043void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292044 DCHECK(did_show_) << "should already have shown the view";
2045
[email protected]c1f50aa2010-02-18 03:46:572046 // We must keep WebKit's shared timer running in this case in order to allow
2047 // showModalDialog to function properly.
2048 //
2049 // TODO(darin): WebKit should really be smarter about suppressing events and
2050 // timers so that we do not need to manage the shared timer in such a heavy
2051 // handed manner.
2052 //
[email protected]f1a29a02011-10-06 23:08:442053 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2054 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572055
[email protected]12636df2009-09-28 22:32:212056 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292057}
2058
[email protected]2b624c562011-10-27 22:58:262059bool RenderViewImpl::enterFullScreen() {
2060 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2061 return true;
2062}
2063
2064void RenderViewImpl::exitFullScreen() {
2065 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2066}
2067
[email protected]217690d2012-01-27 07:33:112068bool RenderViewImpl::requestPointerLock() {
2069 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2070}
2071
2072void RenderViewImpl::requestPointerUnlock() {
2073 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2074}
2075
2076bool RenderViewImpl::isPointerLocked() {
2077 return mouse_lock_dispatcher_->IsMouseLockedTo(
2078 webwidget_mouse_lock_target_.get());
2079}
2080
[email protected]3d9689372009-09-10 04:29:172081// WebKit::WebFrameClient -----------------------------------------------------
2082
[email protected]310ebd6302011-10-10 19:06:282083WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2084 const WebPluginParams& params) {
[email protected]0361b942012-03-14 06:42:532085 // The browser plugin is a special kind of pepper plugin
2086 // that loads asynchronously. We first create a placeholder here.
2087 // When a guest is ready to be displayed, we swap out the placeholder
2088 // with the guest.
2089 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2090 if (command_line.HasSwitch(switches::kEnableBrowserPlugin) &&
2091 UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType)
2092 return BrowserPluginPlaceholder::Create(this, frame, params);
2093
[email protected]eaacd1f2011-09-23 02:32:552094 WebPlugin* plugin = NULL;
2095 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2096 this, frame, params, &plugin)) {
2097 return plugin;
2098 }
2099
[email protected]a813c8e2011-10-08 01:34:112100 webkit::WebPluginInfo info;
2101 std::string mime_type;
2102 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2103 params.mimeType.utf8(), &info, &mime_type);
2104 if (!found)
2105 return NULL;
2106
2107 WebPluginParams params_to_use = params;
2108 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312109 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172110}
2111
[email protected]310ebd6302011-10-10 19:06:282112WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422113 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372114 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422115
[email protected]30447b62009-11-13 01:13:372116 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512117 bool exists = false;
[email protected]30447b62009-11-13 01:13:372118 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512119 ViewHostMsg_CreateWorker_Params params;
2120 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512121 params.name = name;
2122 params.document_id = document_id;
2123 params.render_view_route_id = routing_id_;
2124 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232125 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372126 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512127 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372128 if (url_mismatch) {
2129 return NULL;
2130 } else {
[email protected]f1a29a02011-10-06 23:08:442131 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492132 document_id,
[email protected]6de0bcf2010-02-17 22:00:512133 exists,
[email protected]30447b62009-11-13 01:13:372134 route_id,
2135 routing_id_);
2136 }
[email protected]9c00f002009-11-05 22:37:422137}
2138
[email protected]310ebd6302011-10-10 19:06:282139WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172140 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442141 FOR_EACH_OBSERVER(
2142 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172143
[email protected]bb6fd402011-12-09 02:45:442144 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502145 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442146 media::FilterCollection* collection = new media::FilterCollection();
2147 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372148
[email protected]9e2269d2012-01-07 00:06:212149 RenderAudioSourceProvider* audio_source_provider = NULL;
2150
[email protected]3d9689372009-09-10 04:29:172151 // Add in any custom filter factories first.
2152 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2153 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212154 // audio_source_provider is a "provider" to WebKit, and a sink
2155 // from the perspective of the audio renderer.
2156 audio_source_provider = new RenderAudioSourceProvider();
2157
2158 // Add the chrome specific audio renderer, using audio_source_provider
2159 // as the sink.
2160 AudioRendererImpl* audio_renderer =
2161 new AudioRendererImpl(audio_source_provider);
2162 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172163 }
2164
[email protected]e1d69d762011-12-13 05:12:182165 // Currently only cros/arm has any HW video decode support in
2166 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2167 // platforms. This is a startup-time optimization. When new VDA
2168 // implementations are added, relax the #if above.
[email protected]d0fb8a72012-03-10 18:54:522169#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
2170 // Note we don't actually use the result of this blind down-cast unless it's
2171 // valid (not NULL and of the right type).
[email protected]43567302012-02-16 23:21:392172 WebGraphicsContext3DCommandBufferImpl* context3d =
2173 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2174 webview()->graphicsContext3D());
[email protected]d0fb8a72012-03-10 18:54:522175 if (context_is_web_graphics_context_3d_command_buffer_impl_ && context3d) {
[email protected]84a83e192012-03-09 18:43:402176 MessageLoop* factories_loop =
2177 RenderThreadImpl::current()->compositor_thread() ?
2178 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
2179 ->message_loop() :
2180 MessageLoop::current();
[email protected]e1d69d762011-12-13 05:12:182181 GpuChannelHost* gpu_channel_host =
2182 RenderThreadImpl::current()->EstablishGpuChannelSync(
2183 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2184 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312185 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
[email protected]84a83e192012-03-09 18:43:402186 factories_loop,
[email protected]8d4359282012-01-14 00:53:312187 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402188 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182189 }
2190#endif
2191
[email protected]da952fd2012-01-13 03:49:252192 webkit_media::WebMediaPlayerImpl* media_player =
2193 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2194 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
2195 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]c4dabe452012-02-08 23:58:122196#if defined(OS_ANDROID)
2197 // TODO(qinmin): Implement for android.
2198 // http://crbug.com/113218
2199#else
[email protected]da952fd2012-01-13 03:49:252200 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562201 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252202 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]9e2269d2012-01-07 00:06:212203 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]bb6fd402011-12-09 02:45:442204 }
[email protected]c4dabe452012-02-08 23:58:122205#endif
[email protected]cec4eb82012-01-12 17:51:562206 return media_player;
[email protected]3d9689372009-09-10 04:29:172207}
2208
[email protected]310ebd6302011-10-10 19:06:282209WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212210 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232211 if (!frame || !frame->view())
2212 return NULL;
[email protected]035545f2010-04-09 13:10:212213 return new RendererWebApplicationCacheHostImpl(
2214 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442215 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212216}
2217
[email protected]310ebd6302011-10-10 19:06:282218WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382219 return &cookie_jar_;
2220}
2221
[email protected]310ebd6302011-10-10 19:06:282222void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512223 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452224}
2225
[email protected]310ebd6302011-10-10 19:06:282226void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512227 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172228}
2229
[email protected]310ebd6302011-10-10 19:06:282230void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172231 WebFrame* frame, const WebURLRequest& request,
2232 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342233 loadURLExternally(frame, request, policy, WebString());
2234}
2235
[email protected]310ebd6302011-10-10 19:06:282236void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342237 WebFrame* frame, const WebURLRequest& request,
2238 WebNavigationPolicy policy,
2239 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592240 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2241 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342242 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2243 suggested_name));
[email protected]efce17b2009-09-11 18:04:592244 } else {
[email protected]445e1042011-12-03 21:03:152245 OpenURL(frame, request.url(),
[email protected]b9fd01ba2012-02-28 01:50:402246 Referrer(referrer, GetReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592247 }
[email protected]3d9689372009-09-10 04:29:172248}
2249
[email protected]310ebd6302011-10-10 19:06:282250WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172251 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222252 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332253 Referrer referrer(
2254 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2255 GetReferrerPolicyFromRequest(request));
2256
[email protected]992db4c2011-05-12 15:37:152257 if (is_swapped_out_) {
[email protected]0639c063a2012-03-22 20:55:332258 if (request.url() != GURL(chrome::kSwappedOutURL)) {
2259 // Targeted links may try to navigate a swapped out frame. Allow the
2260 // browser process to navigate the tab instead. Note that it is also
2261 // possible for non-targeted navigations (from this view) to arrive
2262 // here just after we are swapped out. It's ok to send them to the
2263 // browser, as long as they're for the top level frame.
2264 // TODO(creis): Ensure this supports targeted form submissions when
2265 // fixing http://crbug.com/101395.
2266 if (frame->parent() == NULL) {
2267 OpenURL(frame, request.url(), referrer, default_policy);
2268 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2269 }
2270
2271 // We should otherwise ignore in-process iframe navigations, if they
2272 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552273 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332274 }
[email protected]73eb2602012-02-09 19:50:552275
[email protected]58436a12012-03-21 17:10:262276 // Allow chrome::kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152277 return default_policy;
2278 }
2279
[email protected]3d9689372009-09-10 04:29:172280 // Webkit is asking whether to navigate to a new URL.
2281 // This is fine normally, except if we're showing UI from one security
2282 // context and they're trying to navigate to a different context.
2283 const GURL& url = request.url();
2284
[email protected]d19ea342011-04-20 20:31:132285 // A content initiated navigation may have originated from a link-click,
2286 // script, drag-n-drop operation, etc.
2287 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072288 DocumentState::FromDataSource(frame->provisionalDataSource())->
2289 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132290
[email protected]a8c269a2011-10-25 20:17:222291 // Experimental:
2292 // If --enable-strict-site-isolation is enabled, send all top-level
2293 // navigations to the browser to let it swap processes when crossing site
2294 // boundaries. This is currently expected to break some script calls and
2295 // navigations, such as form submissions.
2296 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102297 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2298 !frame->parent() && (is_content_initiated || is_redirect)) {
2299 WebString origin_str = frame->document().securityOrigin().toString();
2300 GURL frame_url(origin_str.utf8().data());
2301 // TODO(cevans): revisit whether this origin check is still necessary once
2302 // crbug.com/101395 is fixed.
2303 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]313b80bd2011-11-23 03:49:102304 OpenURL(frame, url, referrer, default_policy);
2305 return WebKit::WebNavigationPolicyIgnore;
2306 }
[email protected]a8c269a2011-10-25 20:17:222307 }
2308
[email protected]3d9689372009-09-10 04:29:172309 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302310 // navigations.
[email protected]5f000f272012-01-19 05:25:082311 if (is_content_initiated) {
2312 bool browser_handles_top_level_requests =
2313 renderer_preferences_.browser_handles_top_level_requests &&
2314 IsNonLocalTopLevelNavigation(url, frame, type);
2315 if (browser_handles_top_level_requests ||
2316 renderer_preferences_.browser_handles_all_requests) {
[email protected]5f000f272012-01-19 05:25:082317 // Reset these counters as the RenderView could be reused for the next
2318 // navigation.
2319 page_id_ = -1;
2320 last_page_id_sent_to_browser_ = -1;
2321 OpenURL(frame, url, referrer, default_policy);
2322 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2323 }
[email protected]3d9689372009-09-10 04:29:172324 }
2325
[email protected]6101c342010-12-16 22:44:372326 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552327 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042328 // top-level navigations (not iframes). But we sometimes navigate to
2329 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372330 //
[email protected]744c2a22012-03-15 18:42:042331 // Note: this is known to break POST submissions when crossing process
2332 // boundaries until http://crbug.com/101395 is fixed. This is better for
2333 // security than loading a WebUI, extension or app page in the wrong process.
2334 // POST requests don't work because this mechanism does not preserve form
2335 // POST data. We will need to send the request's httpBody data up to the
2336 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572337 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2338 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222339 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042340 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372341 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042342
2343 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2344 // must be handled by the browser process so that the correct bindings and
2345 // data sources can be registered.
2346 // Similarly, navigations to view-source URLs or within ViewSource mode
2347 // must be handled by the browser process.
2348 int cumulative_bindings =
2349 RenderProcess::current()->GetEnabledBindings();
[email protected]6101c342010-12-16 22:44:372350 bool should_fork =
[email protected]744c2a22012-03-15 18:42:042351 content::GetContentClient()->HasWebUIScheme(url) ||
2352 (cumulative_bindings & content::BINDINGS_POLICY_WEB_UI) ||
2353 url.SchemeIs(chrome::kViewSourceScheme) ||
2354 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112355
[email protected]e48869a2011-04-01 19:56:032356 if (!should_fork) {
2357 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042358 // For now, we skip this for POST submissions. This is because
2359 // http://crbug.com/101395 is more likely to cause compatibility issues
2360 // with hosted apps and extensions than WebUI pages. We will remove this
2361 // check when cross-process POST submissions are supported.
2362 if (request.httpMethod() == "GET") {
2363 bool is_initial_navigation = page_id_ == -1;
2364 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2365 frame, url, is_initial_navigation, &send_referrer);
2366 }
[email protected]6101c342010-12-16 22:44:372367 }
2368
2369 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152370 OpenURL(
2371 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112372 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2373 }
[email protected]3d9689372009-09-10 04:29:172374 }
2375
[email protected]43763f982011-08-26 18:33:402376 // Use the frame's original request's URL rather than the document's URL for
2377 // this check. For a popup, the document's URL may become the opener window's
2378 // URL if the opener has called document.write. See http://crbug.com/93517.
2379 GURL old_url(frame->dataSource()->request().url());
2380
[email protected]3d9689372009-09-10 04:29:172381 // Detect when a page is "forking" a new tab that can be safely rendered in
2382 // its own process. This is done by sites like Gmail that try to open links
2383 // in new windows without script connections back to the original page. We
2384 // treat such cases as browser navigations (in which we will create a new
2385 // renderer for a cross-site navigation), rather than WebKit navigations.
2386 //
2387 // We use the following heuristic to decide whether to fork a new page in its
2388 // own process:
2389 // The parent page must open a new tab to about:blank, set the new tab's
2390 // window.opener to null, and then redirect the tab to a cross-site URL using
2391 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462392 //
2393 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2394 // (see below).
[email protected]3d9689372009-09-10 04:29:172395 bool is_fork =
2396 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582397 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172398 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522399 historyBackListCount() < 1 &&
2400 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172401 // The parent page must have set the child's window.opener to null before
2402 // redirecting to the desired URL.
2403 frame->opener() == NULL &&
2404 // Must be a top-level frame.
2405 frame->parent() == NULL &&
2406 // Must not have issued the request from this page.
2407 is_content_initiated &&
2408 // Must be targeted at the current tab.
2409 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2410 // Must be a JavaScript navigation, which appears as "other".
2411 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462412
[email protected]f92ce2b2012-03-06 18:02:592413 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172414 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152415 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172416 return WebKit::WebNavigationPolicyIgnore;
2417 }
2418
2419 return default_policy;
2420}
2421
[email protected]310ebd6302011-10-10 19:06:282422bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492423 WebFrame* frame, const WebURLRequest& request) {
2424 // We allow WebKit to think that everything can be handled even though
2425 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342426 return true;
2427}
2428
[email protected]310ebd6302011-10-10 19:06:282429WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492430 WebFrame* frame, const WebURLRequest& request) {
2431 NOTREACHED(); // Since we said we can handle all requests.
2432 return WebURLError();
2433}
2434
[email protected]310ebd6302011-10-10 19:06:282435WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492436 WebFrame* frame, const WebURLRequest& request) {
2437 WebURLError error;
2438 error.domain = WebString::fromUTF8(net::kErrorDomain);
2439 error.reason = net::ERR_ABORTED;
2440 error.unreachableURL = request.url();
2441 return error;
[email protected]7b7a7dc2009-10-19 02:23:342442}
2443
[email protected]310ebd6302011-10-10 19:06:282444void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492445 WebFrame*, const WebURLError&) {
2446 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342447}
2448
[email protected]310ebd6302011-10-10 19:06:282449void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432450 const WebKit::WebFormElement& form) {
2451 // Some login forms have onSubmit handlers that put a hash of the password
2452 // into a hidden field and then clear the password. (Issue 28910.)
2453 // This method gets called before any of those handlers run, so save away
2454 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072455 DocumentState* document_state =
2456 DocumentState::FromDataSource(frame->dataSource());
2457 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432458 PasswordFormDomManager::CreatePasswordForm(form));
2459}
2460
[email protected]310ebd6302011-10-10 19:06:282461void RenderViewImpl::willSubmitForm(WebFrame* frame,
2462 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072463 DocumentState* document_state =
2464 DocumentState::FromDataSource(frame->provisionalDataSource());
2465 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172466
[email protected]2905f742011-10-13 03:51:582467 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2468 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172469
2470 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352471 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072472 document_state->set_searchable_form_url(web_searchable_form_data.url());
2473 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212474 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432475 PasswordForm* password_form_data =
2476 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072477 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432478
[email protected]098c95cb2011-04-28 16:49:012479 // In order to save the password that the user actually typed and not one
2480 // that may have gotten transformed by the site prior to submit, recover it
2481 // from the form contents already stored by |willSendSubmitEvent| into the
2482 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2483 // which is what we're storing into now.)
2484 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072485 DocumentState* old_document_state =
2486 DocumentState::FromDataSource(frame->dataSource());
2487 if (old_document_state) {
2488 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432489 if (old_form_data && old_form_data->action == password_form_data->action)
2490 password_form_data->password_value = old_form_data->password_value;
2491 }
2492 }
[email protected]3d9689372009-09-10 04:29:172493
[email protected]2a5b1732011-04-01 23:55:552494 FOR_EACH_OBSERVER(
2495 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172496}
2497
[email protected]310ebd6302011-10-10 19:06:282498void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172499 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2500 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382501 FOR_EACH_OBSERVER(
2502 RenderViewObserver, observers_,
2503 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172504}
2505
[email protected]310ebd6302011-10-10 19:06:282506void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382507 FOR_EACH_OBSERVER(
2508 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172509}
2510
[email protected]310ebd6302011-10-10 19:06:282511void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172512 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152513 if (!frame->parent()) {
2514 WebDataSource* ds = frame->provisionalDataSource();
2515 // If there's no provisional data source, it's a reference fragment
2516 // navigation.
2517 completed_client_redirect_src_ = Referrer(
[email protected]b9fd01ba2012-02-28 01:50:402518 from, ds ? GetReferrerPolicyFromRequest(ds->request()) :
[email protected]445e1042011-12-03 21:03:152519 frame->referrerPolicy());
2520 }
[email protected]eb0bff942011-04-07 22:08:382521 FOR_EACH_OBSERVER(
2522 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172523}
2524
[email protected]310ebd6302011-10-10 19:06:282525void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072526 DocumentState* document_state = DocumentState::FromDataSource(ds);
2527 if (!document_state) {
2528 document_state = new DocumentState;
2529 ds->setExtraData(document_state);
2530 }
2531
[email protected]3d9689372009-09-10 04:29:172532 // The rest of RenderView assumes that a WebDataSource will always have a
2533 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072534 bool content_initiated = !pending_navigation_params_.get();
2535 if (content_initiated)
2536 document_state->set_navigation_state(
2537 NavigationState::CreateContentInitiated());
2538 else
2539 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512540
[email protected]007733c2011-11-17 00:34:072541 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512542 // navigating from a page that used prefetching using a link on that
2543 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072544 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512545 // this value appropriately.
2546 // TODO(gavinp): catch the important case of navigation in a new
2547 // renderer process.
2548 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302549 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522550 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512551 const GURL referrer(
2552 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2553 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072554 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512555 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:412556 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:512557 WebDataSource* old_frame_ds = old_frame->dataSource();
2558 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072559 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512560 break;
2561 }
2562 }
2563 }
2564 }
2565 }
2566
[email protected]4c1b6f0b2010-02-07 16:38:182567 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522568 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512569 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182570 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072571 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182572 break;
2573 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072574 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182575 break;
2576 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072577 document_state->set_load_type(
2578 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182579 break;
2580 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072581 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182582 break;
2583 }
2584 }
[email protected]fa7b6b542009-11-03 05:02:302585
[email protected]946a0032011-03-31 18:42:282586 FOR_EACH_OBSERVER(
2587 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172588}
2589
[email protected]007733c2011-11-17 00:34:072590void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2591 DocumentState* document_state) {
2592 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2593
2594 if (document_state->request_time().is_null())
2595 document_state->set_request_time(params.request_time);
2596
2597 // A navigation resulting from loading a javascript URL should not be treated
2598 // as a browser initiated event. Instead, we want it to look as if the page
2599 // initiated any load resulting from JS execution.
2600 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2601 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2602 params.page_id,
2603 params.pending_history_list_offset,
2604 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482605 navigation_state->set_transferred_request_child_id(
2606 params.transferred_request_child_id);
2607 navigation_state->set_transferred_request_request_id(
2608 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072609 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2610 // We're doing a load of a page that was restored from the last session.
2611 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2612 // which can result in stale data for pages that are set to expire. We
2613 // explicitly override that by setting the policy here so that as
2614 // necessary we load from the network.
2615 document_state->set_cache_policy_override(
2616 WebURLRequest::UseProtocolCachePolicy);
2617 }
2618 document_state->set_navigation_state(navigation_state);
2619 } else {
2620 document_state->set_navigation_state(
2621 NavigationState::CreateContentInitiated());
2622 }
2623
2624 if (IsReload(params))
2625 document_state->set_load_type(DocumentState::RELOAD);
2626 else if (!params.state.empty())
2627 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2628 else
2629 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2630
2631 pending_navigation_params_.reset();
2632}
2633
[email protected]310ebd6302011-10-10 19:06:282634void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172635 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072636 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172637
[email protected]3d9689372009-09-10 04:29:172638 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072639 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172640 double event_time = ds->triggeringEventTime();
2641 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072642 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172643 }
2644
[email protected]05c8e502010-08-15 15:13:522645 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072646 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522647
[email protected]3d9689372009-09-10 04:29:172648 bool is_top_most = !frame->parent();
2649 if (is_top_most) {
2650 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132651 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172652
2653 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152654 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172655 } else if (frame->parent()->isLoading()) {
2656 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002657 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072658 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582659 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172660 }
2661
[email protected]28685da92011-02-07 21:49:172662 FOR_EACH_OBSERVER(
2663 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2664
[email protected]3d9689372009-09-10 04:29:172665 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592666 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262667 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172668}
2669
[email protected]310ebd6302011-10-10 19:06:282670void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2671 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172672 if (frame->parent())
2673 return;
2674 // Received a redirect on the main frame.
2675 WebDataSource* data_source = frame->provisionalDataSource();
2676 if (!data_source) {
2677 // Should only be invoked when we have a data source.
2678 NOTREACHED();
2679 return;
2680 }
2681 std::vector<GURL> redirects;
2682 GetRedirectChain(data_source, &redirects);
2683 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512684 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592685 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172686 }
2687}
2688
[email protected]310ebd6302011-10-10 19:06:282689void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2690 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172691 // Notify the browser that we failed a provisional load with an error.
2692 //
2693 // Note: It is important this notification occur before DidStopLoading so the
2694 // SSL manager can react to the provisional load failure before being
2695 // notified the load stopped.
2696 //
2697 WebDataSource* ds = frame->provisionalDataSource();
2698 DCHECK(ds);
2699
2700 const WebURLRequest& failed_request = ds->request();
2701
[email protected]28685da92011-02-07 21:49:172702 FOR_EACH_OBSERVER(
2703 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2704
[email protected]3d9689372009-09-10 04:29:172705 bool show_repost_interstitial =
2706 (error.reason == net::ERR_CACHE_MISS &&
2707 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582708
2709 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2710 params.frame_id = frame->identifier();
2711 params.is_main_frame = !frame->parent();
2712 params.error_code = error.reason;
2713 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2714 failed_request,
2715 error,
2716 NULL,
2717 &params.error_description);
2718 params.url = error.unreachableURL;
2719 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172720 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582721 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172722
2723 // Don't display an error page if this is simply a cancelled load. Aside
2724 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2725 if (error.reason == net::ERR_ABORTED)
2726 return;
[email protected]b553edd52012-01-10 12:15:232727 // Don't display an error message if the request was handled by an
2728 // external protocol handler.
2729 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2730 return;
[email protected]3d9689372009-09-10 04:29:172731
2732 // Make sure we never show errors in view source mode.
2733 frame->enableViewSourceMode(false);
2734
[email protected]007733c2011-11-17 00:34:072735 DocumentState* document_state = DocumentState::FromDataSource(ds);
2736 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172737
2738 // If this is a failed back/forward/reload navigation, then we need to do a
2739 // 'replace' load. This is necessary to avoid messing up session history.
2740 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2741 // as session history is concerned.
2742 //
2743 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2744 // the page id.
2745 //
2746 bool replace =
2747 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582748 navigation_state->transition_type() ==
2749 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172750
2751 // If we failed on a browser initiated request, then make sure that our error
2752 // page load is regarded as the same browser initiated request.
2753 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072754 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2755 pending_navigation_params_->page_id =
2756 navigation_state->pending_page_id();
2757 pending_navigation_params_->pending_history_list_offset =
2758 navigation_state->pending_history_list_offset();
2759 pending_navigation_params_->transition =
2760 navigation_state->transition_type();
2761 pending_navigation_params_->request_time =
2762 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172763 }
2764
2765 // Provide the user with a more helpful error page?
2766 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2767 return;
2768
2769 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082770 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172771}
2772
[email protected]310ebd6302011-10-10 19:06:282773void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172774 WebFrame* frame, const char* data, size_t data_len,
2775 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072776 DocumentState* document_state =
2777 DocumentState::FromDataSource(frame->dataSource());
2778 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172779}
2780
[email protected]310ebd6302011-10-10 19:06:282781void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2782 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072783 DocumentState* document_state =
2784 DocumentState::FromDataSource(frame->dataSource());
2785 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172786
[email protected]007733c2011-11-17 00:34:072787 if (document_state->commit_load_time().is_null())
2788 document_state->set_commit_load_time(Time::Now());
2789
[email protected]3d9689372009-09-10 04:29:172790 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202791 // When we perform a new navigation, we need to update the last committed
2792 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172793 UpdateSessionHistory(frame);
2794
2795 // We bump our Page ID to correspond with the new session history entry.
2796 page_id_ = next_page_id_++;
2797
[email protected]58436a12012-03-21 17:10:262798 // Don't update history_page_ids_ (etc) for chrome::kSwappedOutURL, since
2799 // we don't want to forget the entry that was there, and since we will
2800 // never come back to chrome::kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:312801 // UpdateSessionHistory and update page_id_ even in this case, so that
2802 // the current entry gets a state update and so that we don't send a
2803 // state update to the wrong entry when we swap back in.
[email protected]58436a12012-03-21 17:10:262804 if (GetLoadingUrl(frame) != GURL(chrome::kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:312805 // Advance our offset in session history, applying the length limit.
2806 // There is now no forward history.
2807 history_list_offset_++;
2808 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2809 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
2810 history_list_length_ = history_list_offset_ + 1;
2811 history_page_ids_.resize(history_list_length_, -1);
2812 history_page_ids_[history_list_offset_] = page_id_;
2813 }
[email protected]3d9689372009-09-10 04:29:172814 } else {
2815 // Inspect the navigation_state on this frame to see if the navigation
2816 // corresponds to a session history navigation... Note: |frame| may or
2817 // may not be the toplevel frame, but for the case of capturing session
2818 // history, the first committed frame suffices. We keep track of whether
2819 // we've seen this commit before so that only capture session history once
2820 // per navigation.
2821 //
2822 // Note that we need to check if the page ID changed. In the case of a
2823 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2824 // previous URL and the current page ID, which would be wrong.
2825 if (navigation_state->pending_page_id() != -1 &&
2826 navigation_state->pending_page_id() != page_id_ &&
2827 !navigation_state->request_committed()) {
2828 // This is a successful session history navigation!
2829 UpdateSessionHistory(frame);
2830 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002831
2832 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032833
2834 // If the history list is valid, our list of page IDs should be correct.
2835 DCHECK(history_list_length_ <= 0 ||
2836 history_list_offset_ < 0 ||
2837 history_list_offset_ >= history_list_length_ ||
2838 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172839 }
2840 }
2841
[email protected]28685da92011-02-07 21:49:172842 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2843 DidCommitProvisionalLoad(frame, is_new_navigation));
2844
[email protected]3d9689372009-09-10 04:29:172845 // Remember that we've already processed this request, so we don't update
2846 // the session history again. We do this regardless of whether this is
2847 // a session history navigation, because if we attempted a session history
2848 // navigation without valid HistoryItem state, WebCore will think it is a
2849 // new navigation.
2850 navigation_state->set_request_committed(true);
2851
2852 UpdateURL(frame);
2853
2854 // If this committed load was initiated by a client redirect, we're
2855 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152856 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172857
2858 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272859 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172860}
2861
[email protected]310ebd6302011-10-10 19:06:282862void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102863 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2864 DidClearWindowObject(frame));
2865
[email protected]b6cb3a842011-06-24 18:28:412866 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212867 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252868 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2869 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272870 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172871 }
[email protected]766a7082012-02-03 23:39:152872
2873 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
2874 if (!dom_automation_controller_.get())
2875 dom_automation_controller_.reset(new DomAutomationController());
2876 dom_automation_controller_->set_message_sender(
2877 static_cast<content::RenderView*>(this));
2878 dom_automation_controller_->set_routing_id(routing_id());
2879 dom_automation_controller_->BindToJavascript(frame,
2880 "domAutomationController");
2881 }
[email protected]3d9689372009-09-10 04:29:172882}
2883
[email protected]310ebd6302011-10-10 19:06:282884void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172885 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412886 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252887 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272888 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172889 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2890 }
[email protected]e48869a2011-04-01 19:56:032891
2892 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2893 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172894}
2895
[email protected]310ebd6302011-10-10 19:06:282896void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2897 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462898 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172899
2900 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272901 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172902}
2903
[email protected]310ebd6302011-10-10 19:06:282904void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132905 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2906 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582907}
2908
[email protected]310ebd6302011-10-10 19:06:282909void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172910 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072911 DocumentState* document_state = DocumentState::FromDataSource(ds);
2912 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172913
[email protected]622474d2010-11-04 09:21:082914 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172915
[email protected]28685da92011-02-07 21:49:172916 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2917 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172918
2919 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272920 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172921}
2922
[email protected]310ebd6302011-10-10 19:06:282923void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082924 if (webview()->mainFrame() == frame) {
2925 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2926 page_id_));
2927 }
[email protected]3d9689372009-09-10 04:29:172928}
2929
[email protected]310ebd6302011-10-10 19:06:282930void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312931 WebDataSource* ds = frame->dataSource();
2932 DCHECK(ds);
2933
2934
[email protected]28685da92011-02-07 21:49:172935 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312936
2937 const WebURLRequest& failed_request = ds->request();
2938 string16 error_description;
2939 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2940 failed_request,
2941 error,
2942 NULL,
2943 &error_description);
2944 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2945 frame->identifier(),
2946 failed_request.url(),
2947 !frame->parent(),
2948 error.reason,
2949 error_description));
[email protected]3d9689372009-09-10 04:29:172950}
2951
[email protected]310ebd6302011-10-10 19:06:282952void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172953 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072954 DocumentState* document_state = DocumentState::FromDataSource(ds);
2955 if (document_state->finish_load_time().is_null())
2956 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412957
[email protected]676126f72011-01-15 00:03:512958 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172959
[email protected]1a55c5be2011-11-29 11:36:312960 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2961 frame->identifier(),
2962 ds->request().url(),
2963 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172964}
2965
[email protected]310ebd6302011-10-10 19:06:282966void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172967 WebFrame* frame, bool is_new_navigation) {
2968 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072969 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172970 // update the ExtraData on the datasource so that others who read the
2971 // ExtraData will get the new NavigationState. Similarly, if we did not
2972 // initiate this navigation, then we need to take care to reset any pre-
2973 // existing navigation state to a content-initiated navigation state.
2974 // DidCreateDataSource conveniently takes care of this for us.
2975 didCreateDataSource(frame, frame->dataSource());
2976
[email protected]007733c2011-11-17 00:34:072977 DocumentState* document_state =
2978 DocumentState::FromDataSource(frame->dataSource());
2979 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092980 new_state->set_was_within_same_page(true);
2981
[email protected]3d9689372009-09-10 04:29:172982 didCommitProvisionalLoad(frame, is_new_navigation);
2983
[email protected]750fcf872011-08-03 23:10:472984 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2985 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172986}
2987
[email protected]310ebd6302011-10-10 19:06:282988void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312989 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592990}
2991
[email protected]310ebd6302011-10-10 19:06:282992void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172993 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2994 // Ignore
2995}
2996
[email protected]310ebd6302011-10-10 19:06:282997void RenderViewImpl::willSendRequest(WebFrame* frame,
2998 unsigned identifier,
2999 WebURLRequest& request,
3000 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303001 WebFrame* top_frame = frame->top();
3002 if (!top_frame)
3003 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513004 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3005 WebDataSource* top_data_source = top_frame->dataSource();
3006 WebDataSource* data_source =
3007 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223008
[email protected]78d5cfe2011-02-04 08:43:223009 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:033010 GURL new_url;
3011 if (content::GetContentClient()->renderer()->WillSendRequest(
3012 frame, request_url, &new_url)) {
3013 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:223014 }
3015
[email protected]2905f742011-10-13 03:51:583016 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073017 DocumentState* document_state = DocumentState::FromDataSource(data_source);
3018 NavigationState* navigation_state = document_state->navigation_state();
3019 if (document_state) {
3020 if (document_state->is_cache_policy_override_set())
3021 request.setCachePolicy(document_state->cache_policy_override());
3022 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:303023 }
[email protected]8a3125a712010-08-09 18:58:513024
[email protected]91043a8232011-11-04 16:41:193025 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:063026 new RequestExtraData(frame->referrerPolicy(),
3027 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193028 frame->identifier(),
3029 frame->parent() == top_frame,
3030 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:483031 transition_type,
3032 navigation_state->transferred_request_child_id(),
3033 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573034
[email protected]007733c2011-11-17 00:34:073035 DocumentState* top_document_state =
3036 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573037 // TODO(gavinp): separate out prefetching and prerender field trials
3038 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073039 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:573040 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
3041 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:073042 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513043
[email protected]3d9689372009-09-10 04:29:173044 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133045 request.setHasUserGesture(frame->isProcessingUserGesture());
3046
[email protected]0a8db0d2011-04-13 15:15:403047 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133048 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173049}
3050
[email protected]310ebd6302011-10-10 19:06:283051void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173052 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493053
[email protected]3d9689372009-09-10 04:29:173054 // Only do this for responses that correspond to a provisional data source
3055 // of the top-most frame. If we have a provisional data source, then we
3056 // can't have any sub-resources yet, so we know that this response must
3057 // correspond to a frame load.
3058 if (!frame->provisionalDataSource() || frame->parent())
3059 return;
3060
3061 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083062 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173063 if (frame->isViewSourceModeEnabled())
3064 return;
3065
[email protected]007733c2011-11-17 00:34:073066 DocumentState* document_state =
3067 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083068 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533069
[email protected]972ebdff2010-06-10 22:59:073070 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073071 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3072 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403073 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3074 if (extra_data) {
3075 document_state->set_npn_negotiated_protocol(
3076 extra_data->npn_negotiated_protocol());
3077 }
[email protected]007733c2011-11-17 00:34:073078 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573079 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073080 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3081 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093082 // Whether or not the http status code actually corresponds to an error is
3083 // only checked when the page is done loading, if |use_error_page| is
3084 // still true.
[email protected]007733c2011-11-17 00:34:073085 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173086}
3087
[email protected]310ebd6302011-10-10 19:06:283088void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173089 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073090 DocumentState* document_state =
3091 DocumentState::FromDataSource(frame->dataSource());
3092 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173093 return;
3094
[email protected]7bfc153f2011-09-23 22:00:203095 // Do not show error page when DevTools is attached.
3096 if (devtools_agent_->IsAttached())
3097 return;
3098
[email protected]06333afe2011-02-24 14:55:093099 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073100 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083101 if (http_status_code == 404) {
3102 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413103 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173104
[email protected]b6cb3a842011-06-24 18:28:413105 const GURL& error_page_url =
3106 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093107 if (error_page_url.is_valid()) {
3108 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473109 original_error.domain = "http";
3110 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413111 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173112
[email protected]007733c2011-11-17 00:34:073113 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093114 new AltErrorPageResourceFetcher(
3115 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083116 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3117 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093118 return;
3119 }
3120 }
[email protected]3d9689372009-09-10 04:29:173121
[email protected]e6a2ce52011-10-08 01:40:133122 std::string error_domain;
3123 if (content::GetContentClient()->renderer()->HasErrorPage(
3124 http_status_code, &error_domain)) {
3125 WebURLError error;
3126 error.unreachableURL = frame->document().url();
3127 error.domain = WebString::fromUTF8(error_domain);
3128 error.reason = http_status_code;
3129
3130 LoadNavigationErrorPage(
3131 frame, frame->dataSource()->request(), error, std::string(), true);
3132 }
[email protected]3d9689372009-09-10 04:29:173133}
3134
[email protected]310ebd6302011-10-10 19:06:283135void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173136 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3137 // Ignore
3138}
3139
[email protected]310ebd6302011-10-10 19:06:283140void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173141 WebFrame* frame, const WebURLRequest& request,
3142 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003143 // The recipients of this message have no use for data: URLs: they don't
3144 // affect the page's insecure content list and are not in the disk cache. To
3145 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3146 // filter them out here.
3147 GURL url(request.url());
3148 if (url.SchemeIs("data"))
3149 return;
3150
[email protected]3d9689372009-09-10 04:29:173151 // Let the browser know we loaded a resource from the memory cache. This
3152 // message is needed to display the correct SSL indicators.
3153 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3154 routing_id_,
[email protected]84703292011-10-28 20:44:003155 url,
[email protected]70435962011-08-02 20:13:283156 response.securityInfo(),
3157 request.httpMethod().utf8(),
3158 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173159}
3160
[email protected]310ebd6302011-10-10 19:06:283161void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293162 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3163}
3164
[email protected]310ebd6302011-10-10 19:06:283165void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023166 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293167 Send(new ViewHostMsg_DidRunInsecureContent(
3168 routing_id_,
[email protected]92771112011-01-20 00:13:023169 origin.toString().utf8(),
3170 target));
[email protected]e3d60e5d2009-09-25 21:08:293171}
3172
[email protected]310ebd6302011-10-10 19:06:283173void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033174 webkit_glue::WebURLLoaderImpl* loader_impl =
3175 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3176 loader_impl->UpdateRoutingId(routing_id_);
3177}
3178
[email protected]310ebd6302011-10-10 19:06:283179void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173180 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3181}
3182
[email protected]310ebd6302011-10-10 19:06:283183void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3184 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583185 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283186 int world_id) {
[email protected]5bc10932011-09-21 21:03:303187 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583188 frame, context, extension_group, world_id);
3189}
3190
3191void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3192 v8::Handle<v8::Context> context,
3193 int world_id) {
3194 content::GetContentClient()->renderer()->DidCreateScriptContext(
3195 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283196}
3197
[email protected]310ebd6302011-10-10 19:06:283198void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3199 v8::Handle<v8::Context> context,
3200 int world_id) {
[email protected]5bc10932011-09-21 21:03:303201 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3202 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283203}
3204
[email protected]310ebd6302011-10-10 19:06:283205void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073206 // We don't always want to send the change messages over IPC, only if we've
3207 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3208 // message.
3209 if (!send_preferred_size_changes_ || !webview())
3210 return;
3211
[email protected]705243f2010-05-05 19:58:073212 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3213 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533214
3215 // In the presence of zoom, these sizes are still reported as if unzoomed,
3216 // so we need to adjust.
3217 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3218 size.set_width(static_cast<int>(size.width() * zoom_factor));
3219 size.set_height(static_cast<int>(size.height() * zoom_factor));
3220
[email protected]705243f2010-05-05 19:58:073221 if (size == preferred_size_)
3222 return;
[email protected]c27324b2009-11-19 22:44:293223
[email protected]705243f2010-05-05 19:58:073224 preferred_size_ = size;
3225 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3226 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173227}
3228
[email protected]273558fb2012-01-12 15:03:513229void RenderViewImpl::EnsureMediaStreamImpl() {
3230#if defined(ENABLE_P2P_APIS)
3231 if (!p2p_socket_dispatcher_)
3232 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3233#endif
3234
[email protected]5b87e782012-02-09 18:19:323235#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513236 if (!media_stream_dispatcher_)
3237 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3238
3239 if (!media_stream_impl_.get()) {
3240 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3241 media_stream_impl_ = new MediaStreamImpl(
3242 media_stream_dispatcher_,
3243 p2p_socket_dispatcher_,
3244 RenderThreadImpl::current()->video_capture_impl_manager(),
3245 factory);
3246 }
[email protected]5b87e782012-02-09 18:19:323247#endif
[email protected]273558fb2012-01-12 15:03:513248}
3249
[email protected]310ebd6302011-10-10 19:06:283250void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3251 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313252 if (webview()->mainFrame() != frame)
3253 return;
3254 WebView* frameView = frame->view();
3255 if (!frameView)
3256 return;
3257
3258 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3259 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3260
3261 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3262 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3263 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3264 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3265
3266 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3267 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3268 }
3269}
3270
[email protected]310ebd6302011-10-10 19:06:283271void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313272 WebSize offset = frame->scrollOffset();
3273 WebSize minimum_offset = frame->minimumScrollOffset();
3274 WebSize maximum_offset = frame->maximumScrollOffset();
3275
3276 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3277 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3278
3279 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3280 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3281 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3282 routing_id_, is_pinned_to_left, is_pinned_to_right));
3283
3284 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3285 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3286 }
3287}
3288
[email protected]310ebd6302011-10-10 19:06:283289void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493290 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313291
3292 if (webview()->mainFrame() == frame)
3293 UpdateScrollState(frame);
3294}
3295
[email protected]310ebd6302011-10-10 19:06:283296void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313297 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493298}
3299
[email protected]ea931252012-02-15 22:01:033300void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3301 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3302}
3303
[email protected]310ebd6302011-10-10 19:06:283304void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3305 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113306 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3307 if (!count)
3308 active_match_ordinal = 0;
3309
3310 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3311 routing_id_,
3312 request_id,
3313 count,
3314 gfx::Rect(),
3315 active_match_ordinal,
3316 final_update);
3317
[email protected]8922e1f2009-10-03 05:01:263318 // If we have a message that has been queued up, then we should just replace
3319 // it. The ACK from the browser will make sure it gets sent when the browser
3320 // wants it.
3321 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263322 queued_find_reply_message_.reset(msg);
3323 } else {
3324 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113325 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263326 }
3327}
3328
[email protected]310ebd6302011-10-10 19:06:283329void RenderViewImpl::reportFindInPageSelection(int request_id,
3330 int active_match_ordinal,
3331 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263332 // Send the search result over to the browser process.
3333 Send(new ViewHostMsg_Find_Reply(routing_id_,
3334 request_id,
3335 -1,
3336 selection_rect,
3337 active_match_ordinal,
3338 false));
3339}
3340
[email protected]310ebd6302011-10-10 19:06:283341void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223342 WebFrame* frame,
3343 WebFileSystem::Type type,
3344 long long size,
[email protected]d275d7a2010-11-03 01:34:493345 bool create,
[email protected]2b06a992010-08-21 05:48:223346 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083347 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223348
[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]c5a272d2010-09-27 18:37:083352 callbacks->didFail(WebKit::WebFileErrorAbort);
3353 return;
3354 }
[email protected]2b06a992010-08-21 05:48:223355
[email protected]c5a272d2010-09-27 18:37:083356 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3357 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493358 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223359}
3360
[email protected]310ebd6302011-10-10 19:06:283361void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403362 WebFrame* frame,
3363 WebStorageQuotaType type,
3364 WebStorageQuotaCallbacks* callbacks) {
3365 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413366 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563367 if (origin.isUnique()) {
3368 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403369 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3370 return;
3371 }
3372 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533373 GURL(origin.toString()),
3374 static_cast<quota::StorageType>(type),
3375 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403376}
3377
[email protected]310ebd6302011-10-10 19:06:283378void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403379 WebFrame* frame,
3380 WebStorageQuotaType type,
3381 unsigned long long requested_size,
3382 WebStorageQuotaCallbacks* callbacks) {
3383 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413384 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563385 if (origin.isUnique()) {
3386 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403387 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3388 return;
3389 }
3390 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533391 routing_id(), GURL(origin.toString()),
3392 static_cast<quota::StorageType>(type), requested_size,
3393 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403394}
3395
[email protected]8b5af492011-11-28 21:50:583396void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153397 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063398 string16 title = service.title();
3399 if (title.empty())
3400 title = webview()->mainFrame()->document().title();
3401
[email protected]8b5af492011-11-28 21:50:583402 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3403 service.action(),
3404 service.type(),
3405 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063406 title,
[email protected]8b5af492011-11-28 21:50:583407 service.disposition()));
3408}
3409
[email protected]ffc8bed2012-01-21 01:23:153410void RenderViewImpl::dispatchIntent(
3411 WebFrame* frame, const WebIntentRequest& intentRequest) {
3412 webkit_glue::WebIntentData intent_data(intentRequest.intent());
3413 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583414 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153415 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583416}
3417
[email protected]5fa3a062012-03-21 15:39:343418void RenderViewImpl::willOpenSocketStream(
3419 WebSocketStreamHandle* handle) {
3420 SocketStreamHandleData::AddToHandle(handle, routing_id_);
3421}
3422
[email protected]18d5be92011-07-25 18:00:193423// WebKit::WebPageSerializerClient implementation ------------------------------
3424
[email protected]310ebd6302011-10-10 19:06:283425void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193426 const WebURL& frame_url,
3427 const WebCString& data,
3428 WebPageSerializerClient::PageSerializationStatus status) {
3429 Send(new ViewHostMsg_SendSerializedHtmlData(
3430 routing_id(),
3431 frame_url,
3432 data.data(),
3433 static_cast<int32>(status)));
3434}
3435
[email protected]a2ef54c2011-10-10 16:20:313436// content::RenderView implementation ------------------------------------------
3437
[email protected]310ebd6302011-10-10 19:06:283438bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313439 return RenderWidget::Send(message);
3440}
3441
[email protected]82114f52012-03-20 22:53:413442int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:313443 return routing_id_;
3444}
3445
[email protected]82114f52012-03-20 22:53:413446int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:313447 return page_id_;
3448}
3449
[email protected]82114f52012-03-20 22:53:413450gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:313451 return size();
3452}
3453
[email protected]82114f52012-03-20 22:53:413454gfx::NativeViewId RenderViewImpl::GetHostWindow() const {
[email protected]a2ef54c2011-10-10 16:20:313455 return host_window();
3456}
3457
[email protected]82114f52012-03-20 22:53:413458WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313459 return webkit_preferences_;
3460}
3461
[email protected]82114f52012-03-20 22:53:413462WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313463 return webview();
3464}
3465
[email protected]82114f52012-03-20 22:53:413466WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313467 if (!webview())
3468 return WebNode();
3469 WebFrame* focused_frame = webview()->focusedFrame();
3470 if (focused_frame) {
3471 WebDocument doc = focused_frame->document();
3472 if (!doc.isNull())
3473 return doc.focusedNode();
3474 }
3475
3476 return WebNode();
3477}
3478
[email protected]82114f52012-03-20 22:53:413479WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313480 return context_menu_node_;
3481}
3482
[email protected]82114f52012-03-20 22:53:413483bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) const {
[email protected]a2ef54c2011-10-10 16:20:313484 bool is_editable_node = false;
3485 if (!node.isNull()) {
3486 if (node.isContentEditable()) {
3487 is_editable_node = true;
3488 } else if (node.isElementNode()) {
3489 is_editable_node =
3490 node.toConst<WebElement>().isTextFormControlElement();
3491 }
3492 }
3493 return is_editable_node;
3494}
3495
[email protected]310ebd6302011-10-10 19:06:283496WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313497 WebKit::WebFrame* frame,
3498 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:413499 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:313500 bool pepper_plugin_was_registered = false;
3501 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3502 pepper_delegate_.CreatePepperPluginModule(info,
3503 &pepper_plugin_was_registered));
3504 if (pepper_plugin_was_registered) {
3505 if (!pepper_module)
3506 return NULL;
3507 return new webkit::ppapi::WebPluginImpl(
3508 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3509 }
3510
[email protected]34b27e442012-01-20 20:07:413511#if defined(USE_AURA)
3512 return NULL;
3513#else
[email protected]a2ef54c2011-10-10 16:20:313514 return new webkit::npapi::WebPluginImpl(
3515 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413516#endif
[email protected]a2ef54c2011-10-10 16:20:313517}
3518
[email protected]310ebd6302011-10-10 19:06:283519void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3520 const string16& jscript,
3521 int id,
3522 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313523 v8::Handle<v8::Value> result;
3524 WebFrame* web_frame = GetChildFrame(frame_xpath);
3525 if (web_frame)
3526 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3527 if (notify_result) {
3528 ListValue list;
3529 if (!result.IsEmpty() && web_frame) {
3530 v8::HandleScope handle_scope;
3531 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3532 v8::Context::Scope context_scope(context);
3533 V8ValueConverterImpl converter;
3534 converter.set_allow_date(true);
3535 converter.set_allow_regexp(true);
3536 list.Set(0, converter.FromV8Value(result, context));
3537 } else {
3538 list.Set(0, Value::CreateNullValue());
3539 }
3540 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3541 }
3542}
3543
[email protected]310ebd6302011-10-10 19:06:283544bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313545 return (!send_preferred_size_changes_ ||
3546 (disable_scrollbars_size_limit_.width() <= width ||
3547 disable_scrollbars_size_limit_.height() <= height));
3548}
3549
[email protected]82114f52012-03-20 22:53:413550int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:313551 return enabled_bindings_;
3552}
3553
[email protected]82114f52012-03-20 22:53:413554bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:313555 return send_content_state_immediately_;
3556}
3557
[email protected]82114f52012-03-20 22:53:413558float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:313559 return filtered_time_per_frame();
3560}
3561
[email protected]310ebd6302011-10-10 19:06:283562void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
[email protected]82114f52012-03-20 22:53:413563 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313564 showContextMenu(frame, data);
3565}
3566
[email protected]82114f52012-03-20 22:53:413567WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313568 return visibilityState();
3569}
3570
[email protected]310ebd6302011-10-10 19:06:283571void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3572 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313573 return runModalAlertDialog(frame, message);
3574}
3575
[email protected]310ebd6302011-10-10 19:06:283576void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313577 WebKit::WebFrame* frame,
3578 const WebKit::WebURLRequest& request,
3579 WebKit::WebNavigationPolicy policy) {
3580 loadURLExternally(frame, request, policy);
3581}
3582
3583// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513584
[email protected]310ebd6302011-10-10 19:06:283585webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533586 const FilePath& file_path,
3587 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203588 if (!PluginChannelHost::IsListening()) {
3589 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593590 return NULL;
[email protected]94752ee2012-02-10 10:38:203591 }
[email protected]f103ab72009-09-02 17:10:593592
[email protected]00c39612010-03-06 02:53:283593 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463594 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323595#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223596 return webkit::npapi::WebPluginDelegateImpl::Create(
3597 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093598#else
[email protected]7398dcc2011-09-06 21:40:323599 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223600 NOTIMPLEMENTED();
3601 return NULL;
[email protected]7b6616f2010-01-14 18:07:553602#endif
[email protected]f103ab72009-09-02 17:10:593603 }
3604
[email protected]4e0616e2010-05-28 14:55:533605 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593606}
3607
[email protected]310ebd6302011-10-10 19:06:283608void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033609#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273610 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593611#endif
3612}
3613
[email protected]310ebd6302011-10-10 19:06:283614void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033615#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273616 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593617#endif
3618 CleanupWindowInPluginMoves(window);
3619}
3620
[email protected]310ebd6302011-10-10 19:06:283621void RenderViewImpl::DidMovePlugin(
3622 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593623 SchedulePluginMove(move);
3624}
3625
[email protected]310ebd6302011-10-10 19:06:283626void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593627 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523628 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593629}
3630
[email protected]310ebd6302011-10-10 19:06:283631void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593632 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523633 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593634}
3635
[email protected]310ebd6302011-10-10 19:06:283636WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513637 return &cookie_jar_;
3638}
3639
[email protected]a9288f52011-11-17 05:18:163640void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073641 Send(new ViewHostMsg_MediaNotification(routing_id_,
3642 reinterpret_cast<int64>(player),
3643 player->hasVideo(),
3644 player->hasAudio(),
3645 true));
3646}
3647
[email protected]a9288f52011-11-17 05:18:163648void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073649 Send(new ViewHostMsg_MediaNotification(routing_id_,
3650 reinterpret_cast<int64>(player),
3651 player->hasVideo(),
3652 player->hasAudio(),
3653 false));
3654}
3655
[email protected]a9288f52011-11-17 05:18:163656void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073657 DidPause(player);
3658}
3659
[email protected]310ebd6302011-10-10 19:06:283660void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293661 if (!webview())
3662 return;
3663
[email protected]26aa0482009-09-30 16:55:273664 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:053665 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:293666}
3667
[email protected]310ebd6302011-10-10 19:06:283668void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363669 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003670 if (!frame)
3671 return;
[email protected]b781ff282011-08-20 06:19:363672
[email protected]e99ef6f2011-10-16 01:13:003673 string16 text;
3674 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:523675 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:003676
[email protected]3c8c74c2012-03-15 07:34:523677 if (pepper_delegate_.IsPluginFocused()) {
3678 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:413679 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:523680 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:003681 } else {
[email protected]3c8c74c2012-03-15 07:34:523682 size_t location, length;
3683 if (!webview()->caretOrSelectionRange(&location, &length))
3684 return;
3685
3686 range = ui::Range(location, location + length);
3687
3688 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3689 // If current focused element is editable, we will send 100 more chars
3690 // before and after selection. It is for input method surrounding text
3691 // feature.
3692 if (location > kExtraCharsBeforeAndAfterSelection)
3693 offset = location - kExtraCharsBeforeAndAfterSelection;
3694 else
3695 offset = 0;
3696 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3697 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3698 if (!webrange.isNull())
3699 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3700 } else {
3701 offset = location;
3702 text = frame->selectionAsText();
3703 // http://crbug.com/101435
3704 // In some case, frame->selectionAsText() returned text's length is not
3705 // equal to the length returned from webview()->caretOrSelectionRange().
3706 // So we have to set the range according to text.length().
3707 range.set_end(range.start() + text.length());
3708 }
[email protected]b781ff282011-08-20 06:19:363709 }
3710
[email protected]b781ff282011-08-20 06:19:363711 // Sometimes we get repeated didChangeSelection calls from webkit when
3712 // the selection hasn't actually changed. We don't want to report these
3713 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003714 if (selection_text_offset_ != offset ||
3715 selection_range_ != range ||
3716 selection_text_ != text) {
3717 selection_text_ = text;
3718 selection_text_offset_ = offset;
3719 selection_range_ = range;
3720 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3721 }
[email protected]b781ff282011-08-20 06:19:363722}
3723
[email protected]310ebd6302011-10-10 19:06:283724GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3725 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553726 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293727 // If the URL that failed was secure, then the embedding web page was not
3728 // expecting a network attacker to be able to manipulate its contents. As
3729 // we fetch alternate error pages over HTTP, we would be allowing a network
3730 // attacker to manipulate the contents of the response if we tried to use
3731 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153732 return GURL();
initial.commit09911bf2008-07-26 23:55:293733 }
3734
3735 // Grab the base URL from the browser process.
3736 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153737 return GURL();
initial.commit09911bf2008-07-26 23:55:293738
3739 // Strip query params from the failed URL.
3740 GURL::Replacements remove_params;
3741 remove_params.ClearUsername();
3742 remove_params.ClearPassword();
3743 remove_params.ClearQuery();
3744 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553745 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503746 std::string spec_to_send = url_to_send.spec();
3747 // Notify link doctor of the url truncation by sending of "?" at the end.
3748 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:413749 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293750
3751 // Construct the query params to send to link doctor.
3752 std::string params(alternate_error_page_url_.query());
3753 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023754 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293755 params.append("&sourceid=chrome");
3756 params.append("&error=");
3757 switch (error_type) {
3758 case DNS_ERROR:
3759 params.append("dnserror");
3760 break;
3761
3762 case HTTP_404:
3763 params.append("http404");
3764 break;
3765
[email protected]5df266ac2008-10-15 19:50:133766 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333767 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133768 break;
3769
initial.commit09911bf2008-07-26 23:55:293770 default:
3771 NOTREACHED() << "unknown ErrorPageType";
3772 }
3773
3774 // OK, build the final url to return.
3775 GURL::Replacements link_doctor_params;
3776 link_doctor_params.SetQueryStr(params);
3777 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3778 return url;
3779}
3780
[email protected]310ebd6302011-10-10 19:06:283781GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593782 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3783 return GURL();
3784 else
3785 return creator_url_;
3786}
3787
[email protected]69ddf852012-02-21 23:21:313788GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
3789 WebDataSource* ds = frame->dataSource();
3790 if (ds->hasUnreachableURL())
3791 return ds->unreachableURL();
3792
3793 const WebURLRequest& request = ds->request();
3794 return request.url();
3795}
3796
[email protected]310ebd6302011-10-10 19:06:283797WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273798 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313799 web_ui_bindings_.reset(new WebUIBindings(
3800 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463801 }
[email protected]c50008512011-02-03 01:17:273802 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463803}
3804
[email protected]310ebd6302011-10-10 19:06:283805WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013806 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493807}
3808
[email protected]310ebd6302011-10-10 19:06:283809void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3810 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273811 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493812
[email protected]872542532011-06-23 00:43:163813 // Check if the plugin still exists in the document.
3814 if (main_frame->document().isPluginDocument() &&
3815 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493816 if (options.findNext) {
3817 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013818 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493819 } else {
[email protected]afdbd142010-07-10 08:01:233820 if (GetWebPluginFromPluginDocument()->startFind(
3821 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493822 } else {
[email protected]e7c58a32010-08-13 19:47:113823 // Send "no results".
3824 Send(new ViewHostMsg_Find_Reply(routing_id_,
3825 request_id,
3826 0,
3827 gfx::Rect(),
3828 0,
3829 true));
[email protected]24a7f3c2010-03-25 08:26:493830 }
3831 }
3832 return;
3833 }
3834
[email protected]b4bb2502009-10-01 22:35:273835 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273836 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293837 WebFrame* search_frame = focused_frame; // start searching focused frame.
3838
3839 bool multi_frame = (frame_after_main != main_frame);
3840
3841 // If we have multiple frames, we don't want to wrap the search within the
3842 // frame, so we check here if we only have main_frame in the chain.
3843 bool wrap_within_frame = !multi_frame;
3844
[email protected]b3f2b912009-04-09 16:18:523845 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293846 bool result = false;
3847
[email protected]7830da3e2009-11-06 16:27:263848 // If something is selected when we start searching it means we cannot just
3849 // increment the current match ordinal; we need to re-generate it.
3850 WebRange current_selection = focused_frame->selectionRange();
3851
initial.commit09911bf2008-07-26 23:55:293852 do {
[email protected]dd7daa82009-08-10 05:46:453853 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593854 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293855
3856 if (!result) {
3857 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223858 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293859
3860 // Find the next frame, but skip the invisible ones.
3861 do {
3862 // What is the next frame to search? (we might be going backwards). Note
3863 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593864 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273865 search_frame->traverseNext(true) :
3866 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453867 } while (!search_frame->hasVisibleContent() &&
3868 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293869
[email protected]884db412008-11-24 23:46:503870 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223871 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293872
3873 // If we have multiple frames and we have wrapped back around to the
3874 // focused frame, we need to search it once more allowing wrap within
3875 // the frame, otherwise it will report 'no match' if the focused frame has
3876 // reported matches, but no frames after the focused_frame contain a
3877 // match for the search word(s).
3878 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453879 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593880 request_id, search_text, options, true, // Force wrapping.
3881 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293882 }
3883 }
3884
[email protected]26aa0482009-09-30 16:55:273885 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293886 } while (!result && search_frame != focused_frame);
3887
[email protected]7830da3e2009-11-06 16:27:263888 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293889 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453890 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293891 } else {
3892 // If nothing is found, set result to "0 of 0", otherwise, set it to
3893 // "-1 of 1" to indicate that we found at least one item, but we don't know
3894 // yet what is active.
3895 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3896 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293897
[email protected]4f3dc372009-02-24 00:10:293898 // If we find no matches then this will be our last status update.
3899 // Otherwise the scoping effort will send more results.
3900 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293901
[email protected]4f3dc372009-02-24 00:10:293902 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403903 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593904 request_id,
[email protected]4f3dc372009-02-24 00:10:293905 match_count,
3906 selection_rect,
3907 ordinal,
3908 final_status_update));
initial.commit09911bf2008-07-26 23:55:293909
initial.commit09911bf2008-07-26 23:55:293910 // Scoping effort begins, starting with the mainframe.
3911 search_frame = main_frame;
3912
[email protected]dd7daa82009-08-10 05:46:453913 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293914
3915 do {
3916 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453917 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293918
3919 // We don't start another scoping effort unless at least one match has
3920 // been found.
3921 if (result) {
3922 // Start new scoping request. If the scoping function determines that it
3923 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453924 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593925 search_text,
3926 options,
initial.commit09911bf2008-07-26 23:55:293927 true); // reset the tickmarks
3928 }
3929
3930 // Iterate to the next frame. The frame will not necessarily scope, for
3931 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273932 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293933 } while (search_frame != main_frame);
3934 }
3935}
3936
[email protected]815dd9872011-11-23 18:40:303937void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493938 WebView* view = webview();
3939 if (!view)
3940 return;
3941
3942 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163943 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013944 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493945 return;
3946 }
3947
[email protected]815dd9872011-11-23 18:40:303948 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493949 if (clear_selection)
3950 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3951
3952 WebFrame* frame = view->mainFrame();
3953 while (frame) {
3954 frame->stopFinding(clear_selection);
3955 frame = frame->traverseNext(false);
3956 }
3957
[email protected]815dd9872011-11-23 18:40:303958 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493959 WebFrame* focused_frame = view->focusedFrame();
3960 if (focused_frame) {
3961 WebDocument doc = focused_frame->document();
3962 if (!doc.isNull()) {
3963 WebNode node = doc.focusedNode();
3964 if (!node.isNull())
3965 node.simulateClick();
3966 }
3967 }
3968 }
3969}
3970
[email protected]310ebd6302011-10-10 19:06:283971void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493972 // Check if there is any queued up request waiting to be sent.
3973 if (queued_find_reply_message_.get()) {
3974 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423975 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493976 }
3977}
3978
[email protected]54087fe2011-10-28 22:02:483979void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513980 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3981 return;
3982
[email protected]258d31122010-05-09 10:59:413983 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103984
[email protected]b75b8292010-10-01 07:28:253985 double old_zoom_level = webview()->zoomLevel();
3986 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483987 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253988 zoom_level = 0;
3989 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3990 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483991 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253992 } else {
3993 // Either the user hit the zoom factor limit and thus the zoom level is now
3994 // not a whole number, or a plugin changed it to a custom value. We want
3995 // to go to the next whole number so that the user can always get back to
3996 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483997 if ((old_zoom_level > 1 && zoom > 0) ||
3998 (old_zoom_level < 1 && zoom < 0)) {
3999 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254000 } else {
4001 // We're going towards 100%, so first go to the next whole number.
4002 zoom_level = static_cast<int>(old_zoom_level);
4003 }
4004 }
[email protected]b75b8292010-10-01 07:28:254005 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414006 zoomLevelChanged();
4007}
4008
4009void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
4010 int zoom_center_x, int zoom_center_y) {
4011 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4012 kScalingIncrementForGesture);
4013}
4014
4015void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
4016 int zoom_center_x,
4017 int zoom_center_y,
4018 float scaling_increment) {
4019 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4020 return;
4021
[email protected]c514d6372011-08-16 22:54:444022 double old_page_scale_factor = webview()->pageScaleFactor();
4023 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:484024 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444025 page_scale_factor = 1.0;
4026 } else {
4027 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414028 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444029 }
[email protected]47578fa02011-11-02 19:34:414030 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094031 webview()->setPageScaleFactor(page_scale_factor,
4032 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414033 }
[email protected]40bd6582009-12-04 23:49:514034}
4035
[email protected]310ebd6302011-10-10 19:06:284036void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174037 webview()->hidePopups();
4038 webview()->setZoomLevel(false, zoom_level);
4039 zoomLevelChanged();
4040}
4041
[email protected]310ebd6302011-10-10 19:06:284042void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4043 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544044 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294045}
4046
[email protected]310ebd6302011-10-10 19:06:284047void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274048 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294049}
4050
[email protected]310ebd6302011-10-10 19:06:284051void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274052 WebString no_encoding;
4053 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184054}
4055
[email protected]310ebd6302011-10-10 19:06:284056WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454057 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274058 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454059
4060 // xpath string can represent a frame deep down the tree (across multiple
4061 // frame DOMs).
4062 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4063 // should break into 2 xpaths
4064 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414065 std::vector<string16> xpaths;
4066 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454067
[email protected]26aa0482009-09-30 16:55:274068 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414069 for (std::vector<string16>::const_iterator i = xpaths.begin();
4070 frame && i != xpaths.end(); ++i) {
4071 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294072 }
4073
[email protected]dd7daa82009-08-10 05:46:454074 return frame;
initial.commit09911bf2008-07-26 23:55:294075}
4076
[email protected]310ebd6302011-10-10 19:06:284077void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4078 const string16& jscript,
4079 int id,
4080 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:534081 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294082}
4083
[email protected]310ebd6302011-10-10 19:06:284084void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4085 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414086 WebFrame* frame = GetChildFrame(frame_xpath);
4087 if (!frame)
[email protected]216813952011-05-19 22:21:264088 return;
[email protected]ae461542009-06-19 19:03:414089
[email protected]01cf589c2011-07-28 18:04:034090 frame->document().insertUserStyleSheet(
4091 WebString::fromUTF8(css),
4092 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484093}
4094
[email protected]310ebd6302011-10-10 19:06:284095void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094096 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:044097
4098 // Keep track of the total bindings accumulated in this process.
4099 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:294100}
4101
[email protected]310ebd6302011-10-10 19:06:284102void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4103 const std::string& value) {
[email protected]808bda52012-03-09 22:43:324104 if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI)
4105 GetWebUIBindings()->SetProperty(name, value);
4106 else
4107 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:294108}
4109
[email protected]310ebd6302011-10-10 19:06:284110void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4111 const gfx::Point& client_point,
4112 const gfx::Point& screen_point,
4113 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554114 WebDragOperation operation = webview()->dragTargetDragEnter(
4115 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554116 client_point,
4117 screen_point,
4118 ops);
4119
4120 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4121}
4122
[email protected]310ebd6302011-10-10 19:06:284123void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4124 const gfx::Point& screen_point,
4125 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554126 WebDragOperation operation = webview()->dragTargetDragOver(
4127 client_point,
4128 screen_point,
4129 ops);
4130
4131 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4132}
4133
[email protected]310ebd6302011-10-10 19:06:284134void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554135 webview()->dragTargetDragLeave();
4136}
4137
[email protected]310ebd6302011-10-10 19:06:284138void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
4139 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:554140 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:574141
4142 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554143}
4144
[email protected]310ebd6302011-10-10 19:06:284145void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4146 const gfx::Point& screen_point,
4147 bool ended,
4148 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034149 if (ended) {
[email protected]26aa0482009-09-30 16:55:274150 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204151 } else {
4152 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034153 }
initial.commit09911bf2008-07-26 23:55:294154}
4155
[email protected]310ebd6302011-10-10 19:06:284156void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274157 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294158}
4159
[email protected]310ebd6302011-10-10 19:06:284160void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594161 webkit_preferences_ = prefs;
4162 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294163}
4164
[email protected]310ebd6302011-10-10 19:06:284165void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294166 alternate_error_page_url_ = url;
4167}
4168
[email protected]310ebd6302011-10-10 19:06:284169void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514170 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084171 unsigned action) {
4172 if (custom_context.is_pepper_menu)
4173 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4174 else
4175 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584176 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4177 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334178}
4179
[email protected]310ebd6302011-10-10 19:06:284180void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514181 int id,
4182 const std::vector<FilePath>& paths) {
4183 if (!enumeration_completions_[id])
4184 return;
4185
4186 WebVector<WebString> ws_file_names(paths.size());
4187 for (size_t i = 0; i < paths.size(); ++i)
4188 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4189
4190 enumeration_completions_[id]->didChooseFile(ws_file_names);
4191 enumeration_completions_.erase(id);
4192}
4193
[email protected]fb11b6a42012-03-14 07:25:124194void RenderViewImpl::OnFileChooserResponse(
4195 const std::vector<content::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:364196 // This could happen if we navigated to a different page before the user
4197 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474198 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364199 return;
4200
[email protected]b5188522012-03-15 00:18:044201 // Convert Chrome's SelectedFileInfo list to WebKit's.
4202 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
4203 files.size());
4204 for (size_t i = 0; i < files.size(); ++i) {
4205 WebFileChooserCompletion::SelectedFileInfo selected_file;
4206 selected_file.path = webkit_glue::FilePathToWebString(files[i].path);
4207 selected_file.displayName = webkit_glue::FilePathStringToWebString(
4208 files[i].display_name);
4209 selected_files[i] = selected_file;
4210 }
[email protected]a1128322009-10-06 18:38:464211
[email protected]cdaf8d02010-03-30 19:52:474212 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:044213 file_chooser_completions_.front()->completion->didChooseFile(
4214 selected_files);
[email protected]cdaf8d02010-03-30 19:52:474215 file_chooser_completions_.pop_front();
4216
4217 // If there are more pending file chooser requests, schedule one now.
4218 if (!file_chooser_completions_.empty()) {
4219 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4220 file_chooser_completions_.front()->params));
4221 }
initial.commit09911bf2008-07-26 23:55:294222}
4223
[email protected]244ac1892011-12-02 17:04:474224void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4225 const gfx::Size& max_size) {
4226 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4227 if (!webview())
4228 return;
[email protected]61e2b3cc2012-03-02 16:13:344229 webview()->enableAutoResizeMode(min_size, max_size);
4230}
4231
4232void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
4233 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4234 if (!webview())
4235 return;
4236 webview()->disableAutoResizeMode();
4237
4238 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:474239}
4240
[email protected]2bf834f2011-11-17 20:02:214241void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244242 if (send_preferred_size_changes_)
4243 return;
[email protected]9fb325e2010-05-06 18:23:244244 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394245
[email protected]d812fd12011-05-27 23:05:074246 // Start off with an initial preferred size notification (in case
4247 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594248 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084249}
4250
[email protected]310ebd6302011-10-10 19:06:284251void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104252 const gfx::Size& disable_scrollbar_size_limit) {
4253 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4254}
4255
[email protected]310ebd6302011-10-10 19:06:284256void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314257 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504258 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514259 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374260 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134261#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414262 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4263 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464264 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:514265 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344266 renderer_prefs.thumb_inactive_color,
4267 renderer_prefs.thumb_active_color,
4268 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554269#endif
[email protected]93623c5d2009-12-10 21:40:324270
[email protected]d299d972012-03-23 02:26:554271#if defined(USE_ASH) || defined(TOOLKIT_USES_GTK)
[email protected]644d77e2010-01-27 01:03:104272 if (webview()) {
[email protected]d299d972012-03-23 02:26:554273#if defined(TOOLKIT_USES_GTK)
[email protected]93623c5d2009-12-10 21:40:324274 webview()->setScrollbarColors(
4275 renderer_prefs.thumb_inactive_color,
4276 renderer_prefs.thumb_active_color,
4277 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554278#endif
[email protected]644d77e2010-01-27 01:03:104279 webview()->setSelectionColors(
4280 renderer_prefs.active_selection_bg_color,
4281 renderer_prefs.active_selection_fg_color,
4282 renderer_prefs.inactive_selection_bg_color,
4283 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464284 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104285 }
[email protected]7a74e102009-09-03 00:16:564286#endif
[email protected]d299d972012-03-23 02:26:554287
[email protected]d051d9a2011-12-10 02:02:504288 // If the zoom level for this page matches the old zoom default, and this
4289 // is not a plugin, update the zoom level to match the new default.
4290 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4291 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4292 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4293 zoomLevelChanged();
4294 }
[email protected]80d96fa2009-06-10 22:34:514295}
4296
[email protected]310ebd6302011-10-10 19:06:284297void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4298 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284299 if (webview())
4300 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564301}
4302
[email protected]81375e872012-01-11 21:40:364303void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4304 const WebPluginAction& action) {
4305 if (webview())
4306 webview()->performPluginAction(action, location);
4307}
4308
[email protected]310ebd6302011-10-10 19:06:284309void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194310 const GURL& page_url) {
4311 // Prepare list to storage all savable resource links.
4312 std::vector<GURL> resources_list;
4313 std::vector<GURL> referrers_list;
4314 std::vector<GURL> frames_list;
4315 webkit_glue::SavableResourcesResult result(&resources_list,
4316 &referrers_list,
4317 &frames_list);
4318
[email protected]445e1042011-12-03 21:03:154319 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4320 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194321 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4322 webview(),
4323 page_url,
4324 &result,
[email protected]0a35efc2012-03-13 17:28:134325 content::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194326 // If something is wrong when collecting all savable resource links,
4327 // send empty list to embedder(browser) to tell it failed.
4328 referrers_list.clear();
4329 resources_list.clear();
4330 frames_list.clear();
4331 }
4332
4333 // Send result of all savable resource links to embedder.
4334 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4335 resources_list,
4336 referrers_list,
4337 frames_list));
4338}
4339
[email protected]310ebd6302011-10-10 19:06:284340void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194341 const std::vector<GURL>& links,
4342 const std::vector<FilePath>& local_paths,
4343 const FilePath& local_directory_name) {
4344
4345 // Convert std::vector of GURLs to WebVector<WebURL>
4346 WebVector<WebURL> weburl_links(links);
4347
4348 // Convert std::vector of std::strings to WebVector<WebString>
4349 WebVector<WebString> webstring_paths(local_paths.size());
4350 for (size_t i = 0; i < local_paths.size(); i++)
4351 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4352
4353 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4354 webstring_paths,
4355 webkit_glue::FilePathToWebString(
4356 local_directory_name));
4357}
4358
[email protected]310ebd6302011-10-10 19:06:284359void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:124360 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:274361 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:124362 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
4363 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
4364 before_unload_start_time,
4365 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:294366}
4367
[email protected]310ebd6302011-10-10 19:06:284368void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:314369 // Ensure that no other in-progress navigation continues.
4370 OnStop();
4371
[email protected]73eb2602012-02-09 19:50:554372 // Only run unload if we're not swapped out yet, but send the ack either way.
4373 if (!is_swapped_out_) {
4374 // Swap this RenderView out so the tab can navigate to a page rendered by a
4375 // different process. This involves running the unload handler and clearing
4376 // the page. Once WasSwappedOut is called, we also allow this process to
4377 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154378
[email protected]73eb2602012-02-09 19:50:554379 // Send an UpdateState message before we get swapped out.
4380 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154381
[email protected]73eb2602012-02-09 19:50:554382 // Synchronously run the unload handler before sending the ACK.
4383 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154384
[email protected]73eb2602012-02-09 19:50:554385 // Swap out and stop sending any IPC messages that are not ACKs.
4386 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154387
[email protected]73eb2602012-02-09 19:50:554388 // Replace the page with a blank dummy URL. The unload handler will not be
4389 // run a second time, thanks to a check in FrameLoader::stopLoading.
[email protected]69ddf852012-02-21 23:21:314390 // We use loadRequest instead of loadHTMLString because the former commits
4391 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]58436a12012-03-21 17:10:264392 // to chrome::kSwappedOutURL. If that happens to be to the page we had been
[email protected]69ddf852012-02-21 23:21:314393 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]73eb2602012-02-09 19:50:554394 // TODO(creis): Need to add a better way to do this that avoids running the
4395 // beforeunload handler. For now, we just run it a second time silently.
[email protected]58436a12012-03-21 17:10:264396 GURL swappedOutURL(chrome::kSwappedOutURL);
4397 WebURLRequest request(swappedOutURL);
[email protected]69ddf852012-02-21 23:21:314398 webview()->mainFrame()->loadRequest(request);
[email protected]73eb2602012-02-09 19:50:554399 }
[email protected]992db4c2011-05-12 15:37:154400
4401 // Just echo back the params in the ACK.
4402 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4403}
4404
[email protected]310ebd6302011-10-10 19:06:284405void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374406 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294407 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4408 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4409 // in the onunload handler from appearing. For now, we're bypassing that and
4410 // calling the FrameLoader's CloseURL method directly. This should be
4411 // revisited to avoid having two ways to close a page. Having a single way
4412 // to close that can run onunload is also useful for fixing
4413 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274414 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294415
[email protected]992db4c2011-05-12 15:37:154416 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294417}
4418
[email protected]310ebd6302011-10-10 19:06:284419void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024420#if defined(USE_AURA)
4421 // Aura doesn't care if we switch themes.
4422#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164423 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464424 if (webview())
4425 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574426#else // defined(OS_WIN)
4427 // TODO(port): we don't support theming on non-Windows platforms yet
4428 NOTIMPLEMENTED();
4429#endif
initial.commit09911bf2008-07-26 23:55:294430}
4431
[email protected]310ebd6302011-10-10 19:06:284432void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084433 if (decrement_shared_popup_at_destruction_)
4434 shared_popup_counter_->data--;
4435 shared_popup_counter_ = new SharedRenderViewCounter(0);
4436 decrement_shared_popup_at_destruction_ = false;
4437}
4438
[email protected]310ebd6302011-10-10 19:06:284439bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4440 const WebURLError& error,
4441 bool replace) {
[email protected]15d79e12009-08-02 19:23:454442 // We only show alternate error pages in the main frame. They are
4443 // intended to assist the user when navigating, so there is not much
4444 // value in showing them for failed subframes. Ideally, we would be
4445 // able to use the TYPED transition type for this, but that flag is
4446 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454447 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454448 return false;
4449
4450 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374451 // connection failure.
[email protected]15d79e12009-08-02 19:23:454452 int ec = error.reason;
4453 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4454 ec != net::ERR_CONNECTION_FAILED &&
4455 ec != net::ERR_CONNECTION_REFUSED &&
4456 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:414457 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:454458 return false;
[email protected]82114f52012-03-20 22:53:414459 }
[email protected]15d79e12009-08-02 19:23:454460
4461 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554462 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454463 if (!error_page_url.is_valid())
4464 return false;
4465
4466 // Load an empty page first so there is an immediate response to the error,
4467 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454468 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364469 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454470 error.unreachableURL,
4471 replace);
4472
4473 // Now, create a fetcher for the error page and associate it with the data
4474 // source we just created via the LoadHTMLString call. That way if another
4475 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074476 DocumentState* document_state =
4477 DocumentState::FromDataSource(frame->provisionalDataSource());
4478 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454479 new AltErrorPageResourceFetcher(
4480 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084481 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4482 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454483 return true;
4484}
4485
[email protected]310ebd6302011-10-10 19:06:284486void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4487 const WebURLError& original_error,
4488 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454489 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094490 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554491 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094492 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454493}
4494
[email protected]310ebd6302011-10-10 19:06:284495void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004496 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474497 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004498}
4499
[email protected]310ebd6302011-10-10 19:06:284500void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094501 const gfx::Rect& resizer_rect,
4502 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104503 if (webview()) {
[email protected]7ddea9802012-02-22 23:08:054504 // This setting has no effect if fixed layout is not enabled.
[email protected]43d9d782012-03-01 15:40:094505 if (webkit_preferences_.default_device_scale_factor)
[email protected]7ddea9802012-02-22 23:08:054506 webview()->settings()->setLayoutFallbackWidth(
[email protected]43d9d782012-03-01 15:40:094507 new_size.width() / webkit_preferences_.default_device_scale_factor);
[email protected]a72a1fa2010-05-03 22:18:474508 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104509 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204510 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314511 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104512 }
[email protected]dd6afca2011-08-13 03:44:314513 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104514 }
4515
[email protected]ee41e7d22011-10-14 19:34:094516 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004517}
[email protected]0aa477bd2009-03-23 22:21:434518
[email protected]29ed96a2012-02-04 18:12:164519void RenderViewImpl::WillInitiatePaint() {
4520 // Notify the pepper plugins that we're about to paint.
4521 pepper_delegate_.ViewWillInitiatePaint();
4522}
4523
[email protected]310ebd6302011-10-10 19:06:284524void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164525 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014526 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284527}
4528
[email protected]310ebd6302011-10-10 19:06:284529void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284530 // Notify any pepper plugins that we painted. This will call into the plugin,
4531 // and we it may ask to close itself as a result. This will, in turn, modify
4532 // our set, possibly invalidating the iterator. So we iterate on a copy that
4533 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014534 pepper_delegate_.ViewFlushedPaint();
4535
[email protected]5b1dec8c2012-02-07 04:35:384536 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4537 // See crbug.com/112921.
4538 if (!webview())
4539 return;
4540
[email protected]00c39612010-03-06 02:53:284541 WebFrame* main_frame = webview()->mainFrame();
4542
4543 // If we have a provisional frame we are between the start and commit stages
4544 // of loading and we don't want to save stats.
4545 if (!main_frame->provisionalDataSource()) {
4546 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074547 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284548
[email protected]05c8e502010-08-15 15:13:524549 // TODO(jar): The following code should all be inside a method, probably in
4550 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284551 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074552 if (document_state->first_paint_time().is_null()) {
4553 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284554 }
[email protected]007733c2011-11-17 00:34:074555 if (document_state->first_paint_after_load_time().is_null() &&
4556 !document_state->finish_load_time().is_null()) {
4557 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284558 }
4559 }
4560}
4561
[email protected]310ebd6302011-10-10 19:06:284562void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084563 RenderWidget::OnSwapBuffersPosted();
4564}
4565
[email protected]310ebd6302011-10-10 19:06:284566void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244567 RenderWidget::OnSwapBuffersComplete();
4568}
4569
[email protected]310ebd6302011-10-10 19:06:284570void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244571 RenderWidget::OnSwapBuffersAborted();
4572}
4573
[email protected]310ebd6302011-10-10 19:06:284574webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154575 const gfx::Rect& paint_bounds,
4576 TransportDIB** dib,
4577 gfx::Rect* location,
4578 gfx::Rect* clip) {
4579 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4580 paint_bounds, dib, location, clip);
4581}
4582
[email protected]310ebd6302011-10-10 19:06:284583gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074584 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434585 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524586}
4587
[email protected]310ebd6302011-10-10 19:06:284588void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164589 if (webview())
[email protected]26aa0482009-09-30 16:55:274590 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164591}
4592
[email protected]310ebd6302011-10-10 19:06:284593void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144594 if (webview())
[email protected]b4bb2502009-10-01 22:35:274595 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144596
4597 SetBackground(background);
4598}
4599
[email protected]310ebd6302011-10-10 19:06:284600void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344601 if (webview())
[email protected]b4bb2502009-10-01 22:35:274602 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264603
4604#if defined(OS_MACOSX)
4605 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4606 for (plugin_it = plugin_delegates_.begin();
4607 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4608 (*plugin_it)->SetWindowFocus(active);
4609 }
4610#endif
[email protected]8c66c5a2009-07-22 17:26:344611}
4612
[email protected]7a17bac02012-03-07 21:58:124613void RenderViewImpl::OnSetNavigationStartTime(
4614 const base::TimeTicks& browser_navigation_start) {
4615 if (!webview())
4616 return;
4617
4618 // Only the initial navigation can be a cross-renderer navigation. If we've
4619 // already navigated away from that page, we can ignore this message.
4620 if (page_id_ != -1)
4621 return;
4622
4623 // browser_navigation_start is likely before this process existed, so we can't
4624 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
4625 // ensure we don't report a bogus value in the future.
4626 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
4627 browser_navigation_start);
4628 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
4629 (navigation_start - base::TimeTicks()).InSecondsF());
4630}
4631
[email protected]6ce7abc52010-02-02 18:40:144632#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284633void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144634 // Inform plugins that their container has changed visibility.
4635 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4636 for (plugin_it = plugin_delegates_.begin();
4637 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4638 (*plugin_it)->SetContainerVisibility(visible);
4639 }
4640}
[email protected]1e6e3c992010-02-08 15:52:134641
[email protected]310ebd6302011-10-10 19:06:284642void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4643 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134644 // Inform plugins that their window's frame has changed.
4645 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4646 for (plugin_it = plugin_delegates_.begin();
4647 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4648 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4649 }
4650}
[email protected]935d63d2010-10-15 23:31:554651
[email protected]310ebd6302011-10-10 19:06:284652void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4653 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134654 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554655 // applies to it or not, so inform all the delegates.
4656 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4657 for (plugin_it = plugin_delegates_.begin();
4658 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134659 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554660 }
4661}
[email protected]6ce7abc52010-02-02 18:40:144662#endif // OS_MACOSX
4663
[email protected]310ebd6302011-10-10 19:06:284664void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484665 const EditCommands& edit_commands) {
4666 edit_commands_ = edit_commands;
4667}
4668
[email protected]310ebd6302011-10-10 19:06:284669void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594670 // We need to grab a pointer to the doomed WebView before we destroy it.
4671 WebView* doomed = webview();
4672 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494673 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594674}
4675
[email protected]310ebd6302011-10-10 19:06:284676void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484677 edit_commands_.clear();
4678}
4679
[email protected]310ebd6302011-10-10 19:06:284680bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:114681 pepper_delegate_.WillHandleMouseEvent();
4682
4683 // If the mouse is locked, only the current owner of the mouse lock can
4684 // process mouse events.
4685 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374686}
4687
[email protected]310ebd6302011-10-10 19:06:284688void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514689 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064690}
4691
[email protected]310ebd6302011-10-10 19:06:284692void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244693 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4694}
4695
[email protected]310ebd6302011-10-10 19:06:284696void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434697 RenderWidget::OnWasHidden();
4698
[email protected]a6939ca42011-02-18 17:58:074699 if (webview()) {
4700 webview()->settings()->setMinimumTimerInterval(
4701 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444702 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074703 }
4704
[email protected]204f1df2012-01-04 20:21:134705 // Inform PPAPI plugins that their page is no longer visible.
4706 pepper_delegate_.PageVisibilityChanged(false);
4707
[email protected]a6939ca42011-02-18 17:58:074708#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134709 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434710 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4711 for (plugin_it = plugin_delegates_.begin();
4712 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4713 (*plugin_it)->SetContainerVisibility(false);
4714 }
[email protected]a6939ca42011-02-18 17:58:074715#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434716}
4717
[email protected]310ebd6302011-10-10 19:06:284718void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434719 RenderWidget::OnWasRestored(needs_repainting);
4720
[email protected]a6939ca42011-02-18 17:58:074721 if (webview()) {
4722 webview()->settings()->setMinimumTimerInterval(
4723 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444724 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074725 }
4726
[email protected]204f1df2012-01-04 20:21:134727 // Inform PPAPI plugins that their page is visible.
4728 pepper_delegate_.PageVisibilityChanged(true);
4729
[email protected]a6939ca42011-02-18 17:58:074730#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134731 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434732 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4733 for (plugin_it = plugin_delegates_.begin();
4734 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4735 (*plugin_it)->SetContainerVisibility(true);
4736 }
[email protected]784ea1ab2010-09-18 00:02:344737#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074738}
[email protected]1e6e3c992010-02-08 15:52:134739
[email protected]310ebd6302011-10-10 19:06:284740bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384741 if (WebWidgetHandlesCompositorScheduling())
4742 return false;
4743
[email protected]05a980d7a2012-02-07 22:16:424744 if (queried_for_swapbuffers_complete_callback_)
4745 return context_has_swapbuffers_complete_callback_;
4746
4747 queried_for_swapbuffers_complete_callback_ = true;
4748
[email protected]65225772011-05-12 21:10:244749 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:424750 if (context && context->makeContextCurrent()) {
4751 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4752 context_has_swapbuffers_complete_callback_ =
4753 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
4754 != std::string::npos;
4755 }
4756
4757 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:244758}
4759
[email protected]310ebd6302011-10-10 19:06:284760void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134761 RenderWidget::OnSetFocus(enable);
4762
[email protected]7d3c02c2010-05-05 23:10:314763 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074764 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134765 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4766 for (plugin_it = plugin_delegates_.begin();
4767 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344768#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314769 // RenderWidget's call to setFocus can cause the underlying webview's
4770 // activation state to change just like a call to setIsActive.
4771 if (enable)
4772 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344773#endif
[email protected]7d3c02c2010-05-05 23:10:314774 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134775 }
[email protected]589621b2010-09-23 22:01:074776
4777 // Notify all Pepper plugins.
4778 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134779 }
4780}
[email protected]941e4552010-02-01 21:23:434781
[email protected]310ebd6302011-10-10 19:06:284782void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004783 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504784 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574785}
4786
[email protected]73bf95812011-10-12 11:38:324787void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004788 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324789}
4790
[email protected]3f783362011-10-21 22:40:504791void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4792 UpdateSelectionBounds();
4793}
4794
[email protected]b25b3ee2012-01-13 05:19:544795bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4796 if (!pepper_delegate_.IsPluginFocused())
4797 return false;
4798 *rect = pepper_delegate_.GetCaretBounds();
4799 return true;
4800}
4801
[email protected]73bf95812011-10-12 11:38:324802void RenderViewImpl::PpapiPluginCancelComposition() {
4803 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4804 ui::Range range(ui::Range::InvalidRange());
4805 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4806}
4807
[email protected]3c8c74c2012-03-15 07:34:524808void RenderViewImpl::PpapiPluginSelectionChanged() {
4809 SyncSelectionIfRequired();
4810}
4811
[email protected]310ebd6302011-10-10 19:06:284812void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574813 const string16& text,
4814 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4815 int selection_start,
4816 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324817 if (pepper_delegate_.IsPluginFocused()) {
4818 // When a PPAPI plugin has focus, we bypass WebKit.
4819 pepper_delegate_.OnImeSetComposition(text,
4820 underlines,
4821 selection_start,
4822 selection_end);
4823 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234824#if defined(OS_WIN)
4825 // When a plug-in has focus, we create platform-specific IME data used by
4826 // our IME emulator and send it directly to the focused plug-in, i.e. we
4827 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4828 // instance ID is the same one as the specified ID.)
4829 if (focused_plugin_id_ >= 0) {
4830 std::vector<int> clauses;
4831 std::vector<int> target;
4832 for (size_t i = 0; i < underlines.size(); ++i) {
4833 clauses.push_back(underlines[i].startOffset);
4834 clauses.push_back(underlines[i].endOffset);
4835 if (underlines[i].thick) {
4836 target.clear();
4837 target.push_back(underlines[i].startOffset);
4838 target.push_back(underlines[i].endOffset);
4839 }
4840 }
4841 std::set<WebPluginDelegateProxy*>::iterator it;
4842 for (it = plugin_delegates_.begin();
4843 it != plugin_delegates_.end(); ++it) {
4844 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4845 focused_plugin_id_);
4846 }
4847 return;
4848 }
4849#endif
[email protected]56ea1a62011-05-30 07:05:574850 RenderWidget::OnImeSetComposition(text,
4851 underlines,
4852 selection_start,
4853 selection_end);
4854 }
4855}
4856
[email protected]4de6d1692011-10-12 08:45:444857void RenderViewImpl::OnImeConfirmComposition(
4858 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574859 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324860 // When a PPAPI plugin has focus, we bypass WebKit.
4861 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574862 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234863#if defined(OS_WIN)
4864 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4865 // plug-ins. When we send IME text directly to plug-ins, we should not send
4866 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444867 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234868 if (focused_plugin_id_ >= 0) {
4869 std::set<WebPluginDelegateProxy*>::iterator it;
4870 for (it = plugin_delegates_.begin();
4871 it != plugin_delegates_.end(); ++it) {
4872 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4873 }
4874 return;
4875 }
4876#endif
[email protected]ebd28ac2011-10-13 18:49:054877 if (replacement_range.IsValid() && webview()) {
4878 // Select the text in |replacement_range|, it will then be replaced by
4879 // text added by the call to RenderWidget::OnImeConfirmComposition().
4880 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164881 WebRange webrange = WebRange::fromDocumentRange(
4882 frame, replacement_range.start(), replacement_range.length());
4883 if (!webrange.isNull())
4884 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054885 }
4886 }
[email protected]4de6d1692011-10-12 08:45:444887 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574888 }
4889}
4890
[email protected]310ebd6302011-10-10 19:06:284891ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324892 return pepper_delegate_.IsPluginFocused() ?
4893 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4894}
4895
[email protected]3f783362011-10-21 22:40:504896void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4897 if (pepper_delegate_.IsPluginFocused()) {
4898 // TODO(kinaba) http://crbug.com/101101
4899 // Current Pepper IME API does not handle selection bounds. So we simply
4900 // use the caret position as an empty range for now. It will be updated
4901 // after Pepper API equips features related to surrounding text retrieval.
4902 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4903 *start = caret;
4904 *end = caret;
4905 return;
4906 }
4907 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454908}
4909
[email protected]310ebd6302011-10-10 19:06:284910bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324911 return pepper_delegate_.IsPluginFocused() ?
4912 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574913}
4914
[email protected]e6ae0f6c2011-10-04 10:39:234915#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284916void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234917 if (focused)
4918 focused_plugin_id_ = plugin_id;
4919 else
4920 focused_plugin_id_ = -1;
4921}
4922#endif
4923
[email protected]43f28f832010-02-03 02:28:484924#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284925void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:414926 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:134927}
4928
[email protected]310ebd6302011-10-10 19:06:284929void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134930 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554931 // This message can be sent during event-handling, and needs to be delivered
4932 // within that context.
4933 msg->set_unblock(true);
4934 Send(msg);
4935}
4936
[email protected]310ebd6302011-10-10 19:06:284937gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234938 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484939 gfx::PluginWindowHandle window = NULL;
4940 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234941 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114942 if (window) {
4943 fake_plugin_window_handles_.insert(window);
4944 }
[email protected]43f28f832010-02-03 02:28:484945 return window;
4946}
4947
[email protected]310ebd6302011-10-10 19:06:284948void RenderViewImpl::DestroyFakePluginWindowHandle(
4949 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114950 if (window && fake_plugin_window_handles_.find(window) !=
4951 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484952 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114953 fake_plugin_window_handles_.erase(window);
4954 }
[email protected]43f28f832010-02-03 02:28:484955}
4956
[email protected]310ebd6302011-10-10 19:06:284957void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4958 gfx::PluginWindowHandle window,
4959 int32 width,
4960 int32 height,
4961 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334962 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484963 routing_id(), window, width, height, io_surface_identifier));
4964}
4965
[email protected]310ebd6302011-10-10 19:06:284966void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334967 gfx::PluginWindowHandle window,
4968 int32 width,
4969 int32 height,
4970 TransportDIB::Handle transport_dib) {
4971 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074972 routing_id(), window, width, height, transport_dib));
4973}
4974
[email protected]310ebd6302011-10-10 19:06:284975TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334976 size_t size) {
[email protected]1aef98132010-02-23 18:00:074977 TransportDIB::Handle dib_handle;
4978 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384979 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074980 return dib_handle;
4981 // Return an invalid handle if Send() fails.
4982 return TransportDIB::DefaultHandleValue();
4983}
4984
[email protected]310ebd6302011-10-10 19:06:284985void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4986 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074987 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4988}
4989
[email protected]310ebd6302011-10-10 19:06:284990void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:324991 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:144992 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:324993 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:484994}
[email protected]82114f52012-03-20 22:53:414995#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:284996
[email protected]310ebd6302011-10-10 19:06:284997bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234998 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474999 WebFileChooserCompletion* completion) {
5000 static const size_t kMaximumPendingFileChooseRequests = 4;
5001 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5002 // This sanity check prevents too many file choose requests from getting
5003 // queued which could DoS the user. Getting these is most likely a
5004 // programming error (there are many ways to DoS the user so it's not
5005 // considered a "real" security check), either in JS requesting many file
5006 // choosers to pop up, or in a plugin.
5007 //
5008 // TODO(brettw) we might possibly want to require a user gesture to open
5009 // a file picker, which will address this issue in a better way.
5010 return false;
5011 }
5012
5013 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5014 new PendingFileChooser(params, completion)));
5015 if (file_chooser_completions_.size() == 1) {
5016 // Actually show the browse dialog when this is the first request.
5017 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5018 }
5019 return true;
5020}
5021
[email protected]310ebd6302011-10-10 19:06:285022WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515023 if (!geolocation_dispatcher_)
5024 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5025 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255026}
[email protected]61c9f032010-03-31 23:04:195027
[email protected]310ebd6302011-10-10 19:06:285028WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:115029 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:225030#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:025031 if (!input_tag_speech_dispatcher_)
5032 input_tag_speech_dispatcher_ =
5033 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:225034#endif
[email protected]c52b2892012-03-07 11:01:025035 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:115036}
5037
[email protected]310ebd6302011-10-10 19:06:285038WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515039 if (!device_orientation_dispatcher_)
5040 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5041 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535042}
5043
[email protected]310ebd6302011-10-10 19:06:285044void RenderViewImpl::zoomLimitsChanged(double minimum_level,
5045 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:255046 // For now, don't remember plugin zoom values. We don't want to mix them with
5047 // normal web content (i.e. a fixed layout plugin would usually want them
5048 // different).
5049 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5050
[email protected]b75b8292010-10-01 07:28:255051 int minimum_percent = static_cast<int>(
5052 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5053 int maximum_percent = static_cast<int>(
5054 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255055
5056 Send(new ViewHostMsg_UpdateZoomLimits(
5057 routing_id_, minimum_percent, maximum_percent, remember));
5058}
5059
[email protected]310ebd6302011-10-10 19:06:285060void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:255061 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:085062 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:255063 // Tell the browser which url got zoomed so it can update the menu and the
5064 // saved values if necessary
5065 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:085066 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:415067 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:255068}
5069
[email protected]310ebd6302011-10-10 19:06:285070void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
5071 const WebString& base_url,
5072 const WebString& url,
5073 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:485074 GURL base(base_url);
5075 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
5076 if (base.GetOrigin() != absolute_url.GetOrigin()) {
5077 return;
5078 }
[email protected]f1a29a02011-10-06 23:08:445079 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
5080 UTF16ToUTF8(scheme),
5081 absolute_url,
5082 title));
[email protected]a6d36cc2011-02-23 00:39:485083}
5084
[email protected]310ebd6302011-10-10 19:06:285085WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:445086 WebKit::WebPageVisibilityState current_state = is_hidden() ?
5087 WebKit::WebPageVisibilityStateHidden :
5088 WebKit::WebPageVisibilityStateVisible;
5089 WebKit::WebPageVisibilityState override_state = current_state;
5090 if (content::GetContentClient()->renderer()->
5091 ShouldOverridePageVisibilityState(this,
5092 &override_state))
5093 return override_state;
5094 return current_state;
[email protected]94dec932011-05-26 20:04:215095}
5096
[email protected]273558fb2012-01-12 15:03:515097WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
5098 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
5099 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
5100 return NULL;
5101 EnsureMediaStreamImpl();
5102 return media_stream_impl_;
5103}
5104
[email protected]310ebd6302011-10-10 19:06:285105bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195106 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455107 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195108 if (frame->parent() != NULL)
5109 return false;
5110
[email protected]f0a3d0b2010-08-06 22:51:535111 // Navigations initiated within Webkit are not sent out to the external host
5112 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275113 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:135114 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535115 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:135116 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:335117 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:535118 return false;
5119
[email protected]2fc22d12010-12-02 23:08:165120 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325121 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015122 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165123 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015124 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325125 // The opener relationship between the new window and the parent allows the
5126 // new window to script the parent and vice versa. This is not allowed if
5127 // the origins of the two domains are different. This can be treated as a
5128 // top level navigation and routed back to the host.
5129 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275130 if (!opener) {
[email protected]86965362011-04-21 18:42:515131 return true;
[email protected]d19ea342011-04-20 20:31:135132 } else {
[email protected]b6cb3a842011-06-24 18:28:415133 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:325134 return true;
5135 }
5136 }
[email protected]61c9f032010-03-31 23:04:195137 return false;
5138}
[email protected]2b06a992010-08-21 05:48:225139
[email protected]310ebd6302011-10-10 19:06:285140void RenderViewImpl::OnAsyncFileOpened(
5141 base::PlatformFileError error_code,
5142 IPC::PlatformFileForTransit file_for_transit,
5143 int message_id) {
[email protected]27a9ef32010-09-10 04:06:245144 pepper_delegate_.OnAsyncFileOpened(
5145 error_code,
5146 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5147 message_id);
5148}
[email protected]caf706f2010-10-26 17:54:085149
[email protected]310ebd6302011-10-10 19:06:285150void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:475151 int request_id,
5152 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:435153 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:475154 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
5155 broker_process_handle,
5156 handle);
[email protected]eb415bf0e2011-04-14 02:45:425157}
5158
[email protected]caf706f2010-10-26 17:54:085159#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285160void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155161 if (external_popup_menu_ == NULL) {
5162 // Crash reports from the field indicate that we can be notified with a
5163 // NULL external popup menu (we probably get notified twice).
5164 // If you hit this please file a bug against jcivelli and include the page
5165 // and steps to repro.
5166 NOTREACHED();
5167 return;
5168 }
[email protected]caf706f2010-10-26 17:54:085169 external_popup_menu_->DidSelectItem(selected_index);
5170 external_popup_menu_.reset();
5171}
5172#endif
[email protected]bb461532010-11-26 21:50:235173
[email protected]1b4209f2011-01-07 00:25:405174#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:285175void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:405176 int request_id,
5177 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:495178 const PP_NetAddress_Private& local_addr,
5179 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:405180 pepper_delegate_.OnConnectTcpACK(
5181 request_id,
5182 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5183 local_addr,
5184 remote_addr);
5185}
5186#endif
[email protected]a6097f42011-01-10 08:50:515187
[email protected]310ebd6302011-10-10 19:06:285188void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515189 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085190 if (custom_context.is_pepper_menu)
5191 pepper_delegate_.OnContextMenuClosed(custom_context);
5192 else
5193 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105194}
[email protected]5a7b15a2011-08-22 22:48:185195
[email protected]310ebd6302011-10-10 19:06:285196void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185197 if (!webview())
5198 return;
5199 WebFrame* main_frame = webview()->mainFrame();
5200 if (!main_frame)
5201 return;
5202 main_frame->enableViewSourceMode(true);
5203}
[email protected]67bfb83f2011-09-22 03:36:375204
[email protected]310ebd6302011-10-10 19:06:285205bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085206 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405207}
[email protected]7f3c7af2011-10-20 22:52:515208
[email protected]64d0e192011-12-09 14:44:205209void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:515210 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:185211#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:205212 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:185213#endif
[email protected]7f3c7af2011-10-20 22:52:515214}