blob: 3882d2fe6d08327d59c49f38ed5586f9c2f9a6f8 [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]7900bfdb2012-05-24 19:31:2429#include "content/common/browser_plugin_messages.h"
[email protected]14392a52012-05-02 20:28:4430#include "content/common/child_thread.h"
[email protected]127dd582011-03-16 21:32:1031#include "content/common/clipboard_messages.h"
[email protected]37666cf2011-03-13 21:51:4232#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5533#include "content/common/drag_messages.h"
[email protected]16dd6e22012-03-01 19:08:2034#include "content/common/fileapi/file_system_dispatcher.h"
35#include "content/common/fileapi/webfilesystem_callback_dispatcher.h"
[email protected]c26ad882012-02-07 06:41:2036#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]a2ef54c2011-10-10 16:20:3137#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5138#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1039#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0040#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4041#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0542#include "content/common/request_extra_data.h"
[email protected]5fa3a062012-03-21 15:39:3443#include "content/common/socket_stream_handle_data.h"
[email protected]778574e2011-03-21 22:03:5044#include "content/common/view_messages.h"
[email protected]4e1eb3392012-05-18 00:08:0545#include "content/common/webmessageportchannel_impl.h"
[email protected]e091df82011-10-11 18:13:2146#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0447#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4848#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2949#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5150#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2351#include "content/public/common/file_chooser_params.h"
[email protected]fb11b6a42012-03-14 07:25:1252#include "content/public/common/selected_file_info.h"
[email protected]a1d29162011-10-14 17:14:0353#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3454#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0755#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3256#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4457#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3658#include "content/public/renderer/render_view_visitor.h"
[email protected]be2510c02012-05-28 14:52:1459#include "content/renderer/browser_plugin/browser_plugin.h"
[email protected]7900bfdb2012-05-24 19:31:2460#include "content/renderer/browser_plugin/browser_plugin_channel_manager.h"
[email protected]be2510c02012-05-28 14:52:1461#include "content/renderer/browser_plugin/browser_plugin_constants.h"
[email protected]468e4902012-05-23 01:49:3162#include "content/renderer/browser_plugin/guest_to_embedder_channel.h"
[email protected]230b7ef2011-03-16 22:30:1963#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0264#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1565#include "content/renderer/dom_automation_controller.h"
[email protected]1910fe82012-05-10 00:04:1066#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]55722152011-03-22 01:33:5367#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1968#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4069#include "content/renderer/gpu/compositor_thread.h"
[email protected]1784b2f2011-11-24 10:53:4870#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0271#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4272#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0273#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0874#include "content/renderer/media/audio_message_filter.h"
[email protected]273558fb2012-01-12 15:03:5175#include "content/renderer/media/media_stream_dependency_factory.h"
76#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4077#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4878#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4079#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4880#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]4a19be92011-09-22 14:25:0281#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1982#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3783#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3584#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0585#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4486#include "content/renderer/render_thread_impl.h"
[email protected]89054502012-06-03 10:29:2487#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:4488#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3289#include "content/renderer/renderer_accessibility.h"
[email protected]2a84f9d2012-06-05 21:50:4390#include "content/renderer/renderer_accessibility_complete.h"
91#include "content/renderer/renderer_accessibility_focus_only.h"
[email protected]663bd9e2011-03-21 01:07:0192#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:2093#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]64d09222012-05-25 10:10:3494#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3295#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1996#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:1397#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:0198#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3599#include "content/renderer/webplugin_delegate_proxy.h"
100#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:49101#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41102#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:50103#include "media/base/message_loop_factory.h"
[email protected]37136d162012-04-09 23:39:19104#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:18105#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:29106#include "net/base/escape.h"
107#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04108#include "net/http/http_util.h"
[email protected]8bd0fe62011-01-17 06:44:37109#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]f546640b2012-05-15 00:03:49110#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
111#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
[email protected]be2510c02012-05-28 14:52:14112#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
113#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37114#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
115#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37121#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37122#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57123#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58124#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44125#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58126#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14127#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]4e1eb3392012-05-18 00:08:05128#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h"
[email protected]8bd0fe62011-01-17 06:44:37129#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19130#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37131#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36132#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37133#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37136#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37137#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17140#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37141#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]10e5cf12011-04-13 04:10:40142#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51143#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08144#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]50da23d02012-04-13 17:47:48150#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
[email protected]273558fb2012-01-12 15:03:51152#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08154#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
155#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]f546640b2012-05-15 00:03:49156#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
[email protected]9c4bf232011-12-15 02:25:08157#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34158#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37159#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
160#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
161#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
162#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
163#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
164#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26165#include "third_party/skia/include/core/SkBitmap.h"
[email protected]08397d52011-02-05 01:53:38166#include "ui/gfx/native_widget_types.h"
167#include "ui/gfx/point.h"
168#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55169#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04170#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]b928936b2012-04-13 01:16:16171#include "webkit/dom_storage/dom_storage_types.h"
[email protected]9c4bf232011-12-15 02:25:08172#include "webkit/forms/form_data.h"
173#include "webkit/forms/form_field.h"
174#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43175#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19176#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24177#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29178#include "webkit/glue/webdropdata.h"
[email protected]3a3b75a2012-06-01 08:38:36179#include "webkit/glue/web_intent_service_data.h"
[email protected]a6939ca42011-02-18 17:58:07180#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29181#include "webkit/glue/webkit_glue.h"
[email protected]b9fd01ba2012-02-28 01:50:40182#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51183#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16184#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50185#include "webkit/plugins/npapi/plugin_list.h"
186#include "webkit/plugins/npapi/webplugin_delegate.h"
187#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
188#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52189#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29190
[email protected]25fb9b32012-04-27 03:21:55191#if defined(OS_ANDROID)
192#include "webkit/media/android/webmediaplayer_android.h"
[email protected]2d7b82c2012-06-01 05:57:50193#include "webkit/media/android/webmediaplayer_manager_android.h"
[email protected]25fb9b32012-04-27 03:21:55194#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57195// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57196// * theming
[email protected]f78452f2012-05-15 02:07:52197#include "ui/base/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03198#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37199#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]f78452f2012-05-15 02:07:52200#include "ui/base/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33201#elif defined(OS_MACOSX)
202#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57203#endif
204
[email protected]9892b472010-09-16 00:23:42205using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08206using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21207using WebKit::WebApplicationCacheHost;
208using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26209using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41210using WebKit::WebColor;
211using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59212using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44213using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51214using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55215using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28216using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00217using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49218using WebKit::WebDOMEvent;
219using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58220using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25221using WebKit::WebDragOperation;
222using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51223using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51224using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08225using WebKit::WebExternalPopupMenu;
226using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47227using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22228using WebKit::WebFileSystem;
229using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49230using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59231using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48232using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45233using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51234using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17235using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13236using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41237using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50238using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15239using WebKit::WebIntentRequest;
240using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17241using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28242using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17243using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26244using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28245using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28246using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51247using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19248using WebKit::WebPageSerializer;
249using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48250using WebKit::WebPeerConnection00Handler;
251using WebKit::WebPeerConnection00HandlerClient;
252using WebKit::WebPeerConnectionHandler;
253using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17254using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36255using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40256using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49257using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09258using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52259using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59260using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51261using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52262using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15263using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40264using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35265using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29266using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17267using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49268using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59269using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42270using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02271using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34272using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34273using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40274using WebKit::WebStorageQuotaCallbacks;
275using WebKit::WebStorageQuotaError;
276using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28277using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51278using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52279using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24280using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28281using WebKit::WebURL;
282using WebKit::WebURLError;
283using WebKit::WebURLRequest;
284using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28285using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03286using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28287using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26288using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26289using appcache::WebApplicationCacheHostImpl;
290using base::Time;
291using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07292using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32293using content::NavigationState;
[email protected]2a84f9d2012-06-05 21:50:43294using content::Referrer;
[email protected]380244092011-10-07 17:26:27295using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44296using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36297using content::RenderViewVisitor;
[email protected]2a84f9d2012-06-05 21:50:43298using content::RendererAccessibilityComplete;
299using content::RendererAccessibilityFocusOnly;
[email protected]8d86f13d2011-10-04 17:01:19300using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08301using webkit::forms::FormField;
302using webkit::forms::PasswordForm;
303using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26304using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23305using webkit_glue::ResourceFetcher;
[email protected]6717bf272012-05-11 23:31:25306using webkit_glue::WebPreferences;
[email protected]b9fd01ba2012-02-28 01:50:40307using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33308
initial.commit09911bf2008-07-26 23:55:29309//-----------------------------------------------------------------------------
310
[email protected]310ebd6302011-10-10 19:06:28311typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49312static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02313
[email protected]882daa92009-11-05 16:31:31314// Time, in seconds, we delay before sending content state changes (such as form
315// state and scroll position) to the browser. We delay sending changes to avoid
316// spamming the browser.
317// To avoid having tab/session restore require sending a message to get the
318// current content state during tab closing we use a shorter timeout for the
319// foreground renderer. This means there is a small window of time from which
320// content state is modified and not sent to session restore, but this is
321// better than having to wake up all renderers during shutdown.
322static const int kDelaySecondsForContentStateSyncHidden = 5;
323static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29324
[email protected]e99ef6f2011-10-16 01:13:00325static const size_t kExtraCharsBeforeAndAfterSelection = 100;
326
[email protected]0aa55312008-10-17 21:53:08327// The maximum number of popups that can be spawned from one page.
328static const int kMaximumNumberOfUnacknowledgedPopups = 25;
329
[email protected]c514d6372011-08-16 22:54:44330static const float kScalingIncrement = 0.1f;
331
[email protected]47578fa02011-11-02 19:34:41332static const float kScalingIncrementForGesture = 0.01f;
333
[email protected]f546640b2012-05-15 00:03:49334static RenderViewImpl* FromRoutingID(int32 routing_id) {
335 return static_cast<RenderViewImpl*>(
336 ChildThread::current()->ResolveRoute(routing_id));
337}
338
[email protected]726985e22009-06-18 21:09:28339static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
340 WebVector<WebURL> urls;
341 ds->redirectChain(urls);
342 result->reserve(urls.size());
343 for (size_t i = 0; i < urls.size(); ++i)
344 result->push_back(urls[i]);
345}
346
[email protected]007733c2011-11-17 00:34:07347// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44348// the AltErrorPageResourceFetcher is reset.
349static void StopAltErrorPageFetcher(WebDataSource* data_source) {
350 if (data_source) {
[email protected]007733c2011-11-17 00:34:07351 DocumentState* document_state = DocumentState::FromDataSource(data_source);
352 if (document_state)
353 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44354 }
355}
356
[email protected]007733c2011-11-17 00:34:07357static bool IsReload(const ViewMsg_Navigate_Params& params) {
358 return
359 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
360 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
361}
362
[email protected]b9fd01ba2012-02-28 01:50:40363static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59364 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15365 const WebURLRequest& request) {
366 return request.extraData() ?
367 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59368 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15369}
370
[email protected]b9fd01ba2012-02-28 01:50:40371static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
372 const WebURLResponse& response) {
373 return static_cast<WebURLResponseExtraDataImpl*>(
374 response.extraData());
375}
376
[email protected]2149cc622012-02-14 01:12:12377NOINLINE static void CrashIntentionally() {
378 // NOTE(shess): Crash directly rather than using NOTREACHED() so
379 // that the signature is easier to triage in crash reports.
380 volatile int* zero = NULL;
381 *zero = 0;
382}
383
[email protected]8bf1048012012-02-08 01:22:18384static void MaybeHandleDebugURL(const GURL& url) {
385 if (!url.SchemeIs(chrome::kChromeUIScheme))
386 return;
387 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12388 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18389 } else if (url == GURL(chrome::kChromeUIKillURL)) {
390 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
391 } else if (url == GURL(chrome::kChromeUIHangURL)) {
392 for (;;) {
393 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
394 }
395 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
396 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
397 }
398}
399
[email protected]fd3238af2012-05-22 18:55:30400// Returns false unless this is a top-level navigation.
401static bool IsTopLevelNavigation(WebFrame* frame) {
402 return frame->parent() == NULL;
403}
404
405// Returns false unless this is a top-level navigation that crosses origins.
406static bool IsNonLocalTopLevelNavigation(const GURL& url,
407 WebFrame* frame,
408 WebNavigationType type) {
409 if (!IsTopLevelNavigation(frame))
410 return false;
411
412 // Navigations initiated within Webkit are not sent out to the external host
413 // in the following cases.
414 // 1. The url scheme is not http/https
415 // 2. The origin of the url and the opener is the same in which case the
416 // opener relationship is maintained.
417 // 3. Reloads/form submits/back forward navigations
418 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
419 return false;
420
421 // Not interested in reloads/form submits/resubmits/back forward navigations.
422 if (type != WebKit::WebNavigationTypeReload &&
423 type != WebKit::WebNavigationTypeFormSubmitted &&
424 type != WebKit::WebNavigationTypeFormResubmitted &&
425 type != WebKit::WebNavigationTypeBackForward) {
426 // The opener relationship between the new window and the parent allows the
427 // new window to script the parent and vice versa. This is not allowed if
428 // the origins of the two domains are different. This can be treated as a
429 // top level navigation and routed back to the host.
430 WebKit::WebFrame* opener = frame->opener();
431 if (!opener) {
432 return true;
433 }
434
435 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
436 return true;
437 }
438 return false;
439}
440
initial.commit09911bf2008-07-26 23:55:29441///////////////////////////////////////////////////////////////////////////////
442
[email protected]310ebd6302011-10-10 19:06:28443struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23444 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47445 WebFileChooserCompletion* c)
446 : params(p),
447 completion(c) {
448 }
[email protected]8caadeb2011-11-22 02:45:23449 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47450 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
451};
452
[email protected]217690d2012-01-27 07:33:11453namespace {
454
455class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
456 public:
[email protected]82114f52012-03-20 22:53:41457 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11458 : webwidget_(webwidget) {}
459
460 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
461 if (succeeded)
462 webwidget_->didAcquirePointerLock();
463 else
464 webwidget_->didNotAcquirePointerLock();
465 }
466
467 virtual void OnMouseLockLost() OVERRIDE {
468 webwidget_->didLosePointerLock();
469 }
470
471 virtual bool HandleMouseLockedInputEvent(
472 const WebKit::WebMouseEvent &event) OVERRIDE {
473 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
474 return false;
475 }
476
477 private:
478 WebKit::WebWidget* webwidget_;
479};
480
[email protected]86cd9472012-02-03 19:51:05481int64 ExtractPostId(const WebHistoryItem& item) {
482 if (item.isNull())
483 return -1;
484
485 if (item.httpBody().isNull())
486 return -1;
487
488 return item.httpBody().identifier();
489}
490
[email protected]217690d2012-01-27 07:33:11491} // namespace
492
[email protected]daf82f82011-10-31 22:35:31493RenderViewImpl::RenderViewImpl(
494 gfx::NativeViewId parent_hwnd,
495 int32 opener_id,
496 const content::RendererPreferences& renderer_prefs,
497 const WebPreferences& webkit_prefs,
498 SharedRenderViewCounter* counter,
499 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56500 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31501 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46502 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44503 bool is_renderer_created,
504 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41505 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04506 const WebKit::WebScreenInfo& screen_info,
[email protected]468e4902012-05-23 01:49:31507 content::GuestToEmbedderChannel* guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29508 AccessibilityMode accessibility_mode)
[email protected]842f10652012-06-06 01:54:04509 : RenderWidget(WebKit::WebPopupTypeNone, screen_info, swapped_out),
[email protected]676126f72011-01-15 00:03:51510 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02511 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09512 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02513 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24514 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21515 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02516 opened_by_user_gesture_(true),
517 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24518 page_id_(-1),
519 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46520 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00521 history_list_offset_(-1),
522 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02523 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55524 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31525 cached_is_main_frame_pinned_to_left_(false),
526 cached_is_main_frame_pinned_to_right_(false),
527 cached_has_main_frame_horizontal_scrollbar_(false),
528 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]05a980d7a2012-02-07 22:16:42529 context_has_swapbuffers_complete_callback_(false),
530 queried_for_swapbuffers_complete_callback_(false),
[email protected]d0fb8a72012-03-10 18:54:52531 context_is_web_graphics_context_3d_command_buffer_impl_(false),
[email protected]3354d3e2010-06-10 19:53:02532 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51533 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02534 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34535 speech_recognition_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51536 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51537 media_stream_dispatcher_(NULL),
[email protected]1bc65a42012-04-23 09:31:25538 media_stream_impl_(NULL),
[email protected]cae8c8492011-03-03 11:12:18539 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41540 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43541 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32542 renderer_accessibility_(NULL),
[email protected]7e9c5bb02012-05-14 13:58:31543 java_bridge_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11544 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08545 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18546 handling_select_range_(false),
547#if defined(OS_WIN)
548 focused_plugin_id_(-1),
549#endif
[email protected]468e4902012-05-23 01:49:31550 guest_to_embedder_channel_(guest_to_embedder_channel),
551 guest_pp_instance_(0),
552 guest_uninitialized_context_(NULL),
[email protected]ef5e98e2011-12-06 09:49:18553 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51554 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56555 surface_id_ = surface_id;
[email protected]14392a52012-05-02 20:28:44556 if (opener_id != MSG_ROUTING_NONE && is_renderer_created)
[email protected]676126f72011-01-15 00:03:51557 opener_id_ = opener_id;
558
[email protected]74ce1ad2011-12-16 21:51:46559 // Ensure we start with a valid next_page_id_ from the browser.
560 DCHECK_GE(next_page_id_, 0);
561
[email protected]21b3a6ae2011-11-30 00:45:29562#if defined(ENABLE_NOTIFICATIONS)
563 notification_provider_ = new NotificationProvider(this);
564#else
565 notification_provider_ = NULL;
566#endif
567
[email protected]11fee2332011-03-29 20:36:35568 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11569 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35570
[email protected]676126f72011-01-15 00:03:51571 if (counter) {
572 shared_popup_counter_ = counter;
[email protected]14392a52012-05-02 20:28:44573 // Only count this if it isn't swapped out upon creation.
574 if (!swapped_out)
575 shared_popup_counter_->data++;
[email protected]676126f72011-01-15 00:03:51576 decrement_shared_popup_at_destruction_ = true;
577 } else {
578 shared_popup_counter_ = new SharedRenderViewCounter(0);
579 decrement_shared_popup_at_destruction_ = false;
580 }
581
[email protected]380244092011-10-07 17:26:27582 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51583 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47584 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51585 AddRef();
586
587 // If this is a popup, we must wait for the CreatingNew_ACK message before
588 // completing initialization. Otherwise, we can finish it now.
[email protected]468e4902012-05-23 01:49:31589 if (!guest_to_embedder_channel && opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51590 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55591 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51592 }
593
[email protected]34c61bd52011-05-02 19:38:33594 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]60051ec2012-06-08 22:40:57595 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]34c61bd52011-05-02 19:38:33596 webkit_preferences_.Apply(webview());
597 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35598 if (!frame_name.empty())
599 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33600 webview()->settings()->setMinimumTimerInterval(
601 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
602 webkit_glue::kForegroundTabTimerInterval);
603
604 OnSetRendererPrefs(renderer_prefs);
605
[email protected]676126f72011-01-15 00:03:51606 host_window_ = parent_hwnd;
607
[email protected]4fb0f202012-05-30 22:44:53608#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:51609 if (!p2p_socket_dispatcher_)
610 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]735873d2012-01-25 23:31:02611 if (!media_stream_dispatcher_)
612 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32613#endif
[email protected]735873d2012-01-25 23:31:02614
[email protected]8f6a3b852011-07-19 16:48:56615 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32616#if defined(OS_MACOSX)
617 new TextInputClientObserver(this);
618#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56619
[email protected]2d7b82c2012-06-01 05:57:50620#if defined(OS_ANDROID)
621 media_player_manager_.reset(
622 new webkit_media::WebMediaPlayerManagerAndroid());
623#endif
624
[email protected]217690d2012-01-27 07:33:11625 // The next group of objects all implement RenderViewObserver, so are deleted
626 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41627 devtools_agent_ = new DevToolsAgent(this);
[email protected]89054502012-06-03 10:29:24628 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40629 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32630
[email protected]2a84f9d2012-06-05 21:50:43631 // Create renderer_accessibility_ if needed.
632 OnSetAccessibilityMode(accessibility_mode);
633
[email protected]1784b2f2011-11-24 10:53:48634 new IdleUserDetector(this);
635
[email protected]766a7082012-02-03 23:39:15636 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
637 if (command_line.HasSwitch(switches::kDomAutomationController))
638 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
639
[email protected]5b52cd2f712012-03-28 02:12:48640 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05641
[email protected]e48869a2011-04-01 19:56:03642 content::GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44643
644 // If we have an opener_id but we weren't created by a renderer, then
645 // it's the browser asking us to set our opener to another RenderView.
646 // TODO(creis): This doesn't yet handle openers that are subframes.
647 if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) {
[email protected]f546640b2012-05-15 00:03:49648 RenderViewImpl* opener_view = FromRoutingID(opener_id);
649 if (opener_view)
650 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44651 }
652
653 // If we are initially swapped out, navigate to kSwappedOutURL.
654 // This ensures we are in a unique origin that others cannot script.
655 if (is_swapped_out_)
656 NavigateToSwappedOutURL();
initial.commit09911bf2008-07-26 23:55:29657}
658
[email protected]310ebd6302011-10-10 19:06:28659RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03660 history_page_ids_.clear();
661
[email protected]0aa55312008-10-17 21:53:08662 if (decrement_shared_popup_at_destruction_)
663 shared_popup_counter_->data--;
664
[email protected]a1128322009-10-06 18:38:46665 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47666 while (!file_chooser_completions_.empty()) {
667 if (file_chooser_completions_.front()->completion) {
668 file_chooser_completions_.front()->completion->didChooseFile(
669 WebVector<WebString>());
670 }
671 file_chooser_completions_.pop_front();
672 }
[email protected]a1128322009-10-06 18:38:46673
[email protected]83dde542009-09-11 20:59:55674#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11675 // Destroy all fake plugin window handles on the browser side.
676 while (!fake_plugin_window_handles_.empty()) {
677 // Make sure no NULL plugin window handles were inserted into this list.
678 DCHECK(*fake_plugin_window_handles_.begin());
679 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
680 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
681 }
[email protected]83dde542009-09-11 20:59:55682#endif
[email protected]98324892009-09-09 21:16:05683
[email protected]60c42a8c72009-10-09 04:08:59684#ifndef NDEBUG
685 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49686 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59687 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
688 DCHECK_NE(this, it->second) << "Failed to call Close?";
689#endif
[email protected]676126f72011-01-15 00:03:51690
[email protected]310ebd6302011-10-10 19:06:28691 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51692 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59693}
694
695/*static*/
[email protected]310ebd6302011-10-10 19:06:28696RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31697 ViewMap* views = g_view_map.Pointer();
698 ViewMap::iterator it = views->find(webview);
699 return it == views->end() ? NULL : it->second;
700}
701
702/*static*/
703content::RenderView*
704 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28705 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31706}
707
708/*static*/
709void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49710 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59711 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
712 if (!visitor->Visit(it->second))
713 return;
714 }
715}
716
717/*static*/
[email protected]310ebd6302011-10-10 19:06:28718RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15719 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08720 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31721 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08722 const WebPreferences& webkit_prefs,
723 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34724 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56725 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26726 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46727 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44728 bool is_renderer_created,
729 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41730 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04731 const WebKit::WebScreenInfo& screen_info,
[email protected]468e4902012-05-23 01:49:31732 content::GuestToEmbedderChannel* guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29733 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29734 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28735 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51736 parent_hwnd,
737 opener_id,
738 renderer_prefs,
739 webkit_prefs,
740 counter,
741 routing_id,
[email protected]9f4f3322012-01-18 22:29:56742 surface_id,
[email protected]676126f72011-01-15 00:03:51743 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46744 frame_name,
[email protected]14392a52012-05-02 20:28:44745 is_renderer_created,
746 swapped_out,
[email protected]6fd35b72012-03-01 19:46:41747 next_page_id,
[email protected]842f10652012-06-06 01:54:04748 screen_info,
[email protected]468e4902012-05-23 01:49:31749 guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29750 accessibility_mode);
initial.commit09911bf2008-07-26 23:55:29751}
752
[email protected]50da23d02012-04-13 17:47:48753WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
754 WebPeerConnectionHandlerClient* client) {
[email protected]273558fb2012-01-12 15:03:51755 EnsureMediaStreamImpl();
[email protected]1bc65a42012-04-23 09:31:25756 if (!media_stream_impl_)
[email protected]5b87e782012-02-09 18:19:32757 return NULL;
[email protected]273558fb2012-01-12 15:03:51758 return media_stream_impl_->CreatePeerConnectionHandler(client);
759}
760
[email protected]50da23d02012-04-13 17:47:48761WebPeerConnection00Handler* RenderViewImpl::CreatePeerConnectionHandlerJsep(
762 WebPeerConnection00HandlerClient* client) {
763 EnsureMediaStreamImpl();
[email protected]1bc65a42012-04-23 09:31:25764 if (!media_stream_impl_)
[email protected]50da23d02012-04-13 17:47:48765 return NULL;
766 return media_stream_impl_->CreatePeerConnectionHandlerJsep(client);
767}
768
[email protected]310ebd6302011-10-10 19:06:28769void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51770 observers_.AddObserver(observer);
771}
772
[email protected]310ebd6302011-10-10 19:06:28773void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
774 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51775 observers_.RemoveObserver(observer);
776}
777
[email protected]310ebd6302011-10-10 19:06:28778WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26779 return static_cast<WebKit::WebView*>(webwidget());
780}
781
[email protected]310ebd6302011-10-10 19:06:28782void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40783 if (!enabled) {
784 load_progress_tracker_.reset(NULL);
785 return;
786 }
787 if (load_progress_tracker_ == NULL)
788 load_progress_tracker_.reset(new LoadProgressTracker(this));
789}
790
[email protected]7900bfdb2012-05-24 19:31:24791content::GuestToEmbedderChannel*
792 RenderViewImpl::GetGuestToEmbedderChannel() const {
793 return guest_to_embedder_channel_;
794}
795
796void RenderViewImpl::SetGuestToEmbedderChannel(
797 content::GuestToEmbedderChannel* channel) {
798 guest_to_embedder_channel_ = channel;
799}
800
[email protected]310ebd6302011-10-10 19:06:28801void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51802 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29803}
804
[email protected]310ebd6302011-10-10 19:06:28805void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26806 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30807 // If the renderer is visible, set initial visibility and focus state.
808 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34809#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30810 delegate->SetContainerVisibility(true);
811 if (webview() && webview()->isActive())
812 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34813#endif
[email protected]49232292010-09-03 19:07:30814 }
[email protected]784ea1ab2010-09-18 00:02:34815 // Plugins start assuming the content has focus (so that they work in
816 // environments where RenderView isn't hosting them), so we always have to
817 // set the initial state. See webplugin_delegate_impl.h for details.
818 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26819}
820
[email protected]310ebd6302011-10-10 19:06:28821void RenderViewImpl::UnregisterPluginDelegate(
822 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26823 plugin_delegates_.erase(delegate);
824}
[email protected]d8fd6fa2010-02-01 15:54:26825
[email protected]310ebd6302011-10-10 19:06:28826bool RenderViewImpl::GetPluginInfo(const GURL& url,
827 const GURL& page_url,
828 const std::string& mime_type,
829 webkit::WebPluginInfo* plugin_info,
830 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08831 bool found = false;
832 Send(new ViewHostMsg_GetPluginInfo(
833 routing_id_, url, page_url, mime_type, &found, plugin_info,
834 actual_mime_type));
835 return found;
836}
837
[email protected]7a1ec28a2012-03-28 21:10:24838void RenderViewImpl::TransferActiveWheelFlingAnimation(
839 const WebKit::WebActiveWheelFlingParameters& params) {
840 if (webview())
841 webview()->transferActiveWheelFlingAnimation(params);
842}
843
[email protected]8fe8f742012-06-14 00:36:08844bool RenderViewImpl::HasIMETextFocus() {
845 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
846}
847
[email protected]310ebd6302011-10-10 19:06:28848bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27849 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27850 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41851 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26852
[email protected]676126f72011-01-15 00:03:51853 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
854 RenderViewObserver* observer;
855 while ((observer = it.GetNext()) != NULL)
856 if (observer->OnMessageReceived(message))
857 return true;
[email protected]b2abac72009-02-26 12:39:28858
[email protected]a95986a82010-12-24 06:19:28859 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40860 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28861 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29862 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
863 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56864 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29865 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
866 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
867 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
868 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27869#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35870 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27871#endif
initial.commit09911bf2008-07-26 23:55:29872 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15873 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29874 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
875 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
876 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08877 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29878 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15879 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29880 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49881 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
882 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17883 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17884 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41885 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54886 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
887 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29888 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18889 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
890 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29891 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:49892 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:48893 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55894 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
895 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
896 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
897 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
898 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
899 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
900 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45901 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40902 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29903 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19904 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
905 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29906 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
907 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
908 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51909 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
910 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29911 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04912 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15913 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29914 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
915 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08916 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
917 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00918 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16919 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14920 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25921 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
922 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47923 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34924 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10925 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
926 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51927 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56928 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:17929 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
930 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:36931 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34932 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:12933 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
934 OnSetNavigationStartTime)
[email protected]6ce7abc52010-02-02 18:40:14935#if defined(OS_MACOSX)
936 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13937 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13938 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
939 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14940#endif
[email protected]446705872009-09-10 07:22:48941 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33942 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33943 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
944 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24945 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42946 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
947 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19948 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
949 OnGetAllSavableResourceLinksForCurrentPage)
950 IPC_MESSAGE_HANDLER(
951 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
952 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08953#if defined(OS_MACOSX)
954 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
[email protected]24d2b172012-05-26 00:54:12955#elif defined(OS_ANDROID)
956 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
[email protected]caf706f2010-10-26 17:54:08957#endif
[email protected]521b2482011-01-15 00:10:10958 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51959 // TODO(viettrungluu): Move to a separate message filter.
[email protected]54ca3ca892011-06-07 21:14:54960#if defined(OS_MACOSX)
961 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
962#endif
[email protected]9e1ad4b2011-08-14 16:49:19963 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
964 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18965 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51966 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]2a84f9d2012-06-05 21:50:43967 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]9e1ad4b2011-08-14 16:49:19968
initial.commit09911bf2008-07-26 23:55:29969 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28970 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29971 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40972
973 if (!msg_is_ok) {
974 // The message had a handler, but its deserialization failed.
975 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28976 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40977 }
978
[email protected]a95986a82010-12-24 06:19:28979 return handled;
initial.commit09911bf2008-07-26 23:55:29980}
981
[email protected]310ebd6302011-10-10 19:06:28982void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]7900bfdb2012-05-24 19:31:24983 // If we don't have guest-to-embedder channel associated with this RenderView
984 // but we need one, grab one now.
985 if (!params.embedder_channel_name.empty() && !GetGuestToEmbedderChannel()) {
986 content::GuestToEmbedderChannel* embedder_channel =
987 RenderThreadImpl::current()->browser_plugin_channel_manager()->
988 GetChannelByName(params.embedder_channel_name);
989 DCHECK(embedder_channel);
990 SetGuestToEmbedderChannel(embedder_channel);
991 host_window_set_ = false;
992 // TODO(fsamuel): This is test code. Need to find a better way to tell
993 // a WebView to drop its context. This needs to change in
994 // GuestToEmbedderChannel::OnContextLost.
995 GetWebView()->loseCompositorContext(1);
996 RenderThreadImpl::current()->browser_plugin_channel_manager()->
997 ReportChannelToEmbedder(this,
998 embedder_channel->embedder_channel_handle(),
999 params.embedder_channel_name,
1000 params.embedder_container_id);
1001 }
[email protected]8bf1048012012-02-08 01:22:181002 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291003 if (!webview())
1004 return;
1005
[email protected]440a0e52011-09-13 17:38:581006 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1007
[email protected]007733c2011-11-17 00:34:071008 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031009
1010 // If this is a stale back/forward (due to a recent navigation the browser
1011 // didn't know about), ignore it.
1012 if (IsBackForwardToStaleEntry(params, is_reload))
1013 return;
1014
[email protected]992db4c2011-05-12 15:37:151015 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281016 if (is_swapped_out_) {
1017 // We marked the view as hidden when swapping the view out, so be sure to
1018 // reset the visibility state before navigating to the new URL.
1019 webview()->setVisibilityState(visibilityState(), false);
[email protected]992db4c2011-05-12 15:37:151020 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281021 }
[email protected]992db4c2011-05-12 15:37:151022
[email protected]3cc72b12010-03-18 23:03:001023 history_list_offset_ = params.current_history_list_offset;
1024 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031025 if (history_list_length_ >= 0)
1026 history_page_ids_.resize(history_list_length_, -1);
1027 if (params.pending_history_list_offset >= 0 &&
1028 params.pending_history_list_offset < history_list_length_)
1029 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001030
[email protected]38b592902011-04-16 02:08:421031 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291032
[email protected]26aa0482009-09-30 16:55:271033 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451034 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291035 // We cannot reload if we do not have any history state. This happens, for
1036 // example, when recovering from a crash. Our workaround here is a bit of
1037 // a hack since it means that reload after a crashed tab does not cause an
1038 // end-to-end cache validation.
1039 is_reload = false;
1040 }
1041
[email protected]007733c2011-11-17 00:34:071042 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
1043 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:501044
[email protected]04d3c6e2009-05-22 17:00:131045 // If we are reloading, then WebKit will use the history state of the current
1046 // page, so we should just ignore any given history state. Otherwise, if we
1047 // have history state, then we need to navigate to it, which corresponds to a
1048 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551049 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:291050 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021051 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:291052 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551053 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131054 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581055 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:451056 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171057 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131058 } else {
1059 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281060 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291061
[email protected]e6f546c32009-07-01 17:12:551062 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231063 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131064
[email protected]dd7daa82009-08-10 05:46:451065 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551066 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131067
[email protected]445e1042011-12-03 21:03:151068 if (params.referrer.url.is_valid()) {
1069 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1070 params.referrer.policy,
1071 params.url,
1072 WebString::fromUTF8(params.referrer.url.spec()));
1073 if (!referrer.isEmpty())
1074 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281075 }
[email protected]04d3c6e2009-05-22 17:00:131076
[email protected]52c68652010-12-07 17:47:041077 if (!params.extra_headers.empty()) {
1078 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1079 params.extra_headers.end(), "\n");
1080 i.GetNext(); ) {
1081 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1082 WebString::fromUTF8(i.values()));
1083 }
1084 }
[email protected]dd7daa82009-08-10 05:46:451085 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501086 }
1087
[email protected]77f17a82009-05-21 04:42:541088 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071089 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291090}
1091
[email protected]310ebd6302011-10-10 19:06:281092bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031093 const ViewMsg_Navigate_Params& params,
1094 bool is_reload) {
1095 // Make sure this isn't a back/forward to an entry we have already cropped
1096 // or replaced from our history, before the browser knew about it. If so,
1097 // a new navigation has committed in the mean time, and we can ignore this.
1098 bool is_back_forward = !is_reload && !params.state.empty();
1099
1100 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1101 // restoring from a previous session. We'll update our state in OnNavigate.
1102 if (!is_back_forward || history_list_length_ <= 0)
1103 return false;
1104
1105 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1106
1107 // Check for whether the forward history has been cropped due to a recent
1108 // navigation the browser didn't know about.
1109 if (params.pending_history_list_offset >= history_list_length_)
1110 return true;
1111
1112 // Check for whether this entry has been replaced with a new one.
1113 int expected_page_id =
1114 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441115 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1116 if (params.page_id < expected_page_id)
1117 return true;
1118
1119 // Otherwise we've removed an earlier entry and should have shifted all
1120 // entries left. For now, it's ok to lazily update the list.
1121 // TODO(creis): Notify all live renderers when we remove entries from
1122 // the front of the list, so that we don't hit this case.
1123 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1124 }
[email protected]d466b8a2011-07-15 21:48:031125
1126 return false;
1127}
1128
initial.commit09911bf2008-07-26 23:55:291129// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281130void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441131 if (webview()) {
1132 WebFrame* main_frame = webview()->mainFrame();
1133 // Stop the alt error page fetcher. If we let it continue it may complete
1134 // and cause RenderViewHostManager to swap to this RenderView, even though
1135 // it may no longer be active.
1136 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1137 StopAltErrorPageFetcher(main_frame->dataSource());
1138 main_frame->stopLoading();
1139 }
initial.commit09911bf2008-07-26 23:55:291140}
1141
[email protected]ecbf10d2010-02-18 13:03:291142// Reload current focused frame.
1143// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281144void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291145 if (webview() && webview()->focusedFrame()) {
1146 // We always obey the cache (ignore_cache=false) here.
1147 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1148 // a cache-ignoring reload of the frame.
1149 webview()->focusedFrame()->reload(false);
1150 }
[email protected]1dda4022010-01-28 18:24:561151}
1152
[email protected]310ebd6302011-10-10 19:06:281153void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271154 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291155}
1156
[email protected]310ebd6302011-10-10 19:06:281157void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251158 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271159 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251160 return;
1161
[email protected]26aa0482009-09-30 16:55:271162 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451163 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251164}
1165
[email protected]310ebd6302011-10-10 19:06:281166void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291167 // Check if there is a targeturl waiting to be sent.
1168 if (target_url_status_ == TARGET_PENDING) {
1169 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1170 pending_target_url_));
1171 }
1172
1173 target_url_status_ = TARGET_NONE;
1174}
1175
[email protected]310ebd6302011-10-10 19:06:281176void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291177 if (!webview())
1178 return;
1179
[email protected]26aa0482009-09-30 16:55:271180 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291181}
1182
[email protected]310ebd6302011-10-10 19:06:281183void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291184 if (!webview())
1185 return;
1186
[email protected]26aa0482009-09-30 16:55:271187 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291188}
1189
[email protected]310ebd6302011-10-10 19:06:281190void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291191 if (!webview())
1192 return;
1193
[email protected]26aa0482009-09-30 16:55:271194 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291195}
1196
[email protected]310ebd6302011-10-10 19:06:281197void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291198 if (!webview())
1199 return;
1200
[email protected]f6b1856b2011-06-29 22:02:531201 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1202 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291203}
1204
[email protected]c0cc3092009-09-12 08:27:271205#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281206void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351207 if (!webview())
1208 return;
1209
1210 // Since the find pasteboard supports only plain text, this can be simpler
1211 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271212 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351213 if (frame->hasSelection()) {
1214 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271215 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171216 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351217 }
[email protected]a954bf72009-09-12 07:30:351218}
[email protected]c0cc3092009-09-12 08:27:271219#endif
[email protected]a954bf72009-09-12 07:30:351220
[email protected]310ebd6302011-10-10 19:06:281221void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291222 if (!webview())
1223 return;
1224
[email protected]26aa0482009-09-30 16:55:271225 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291226}
1227
[email protected]44bf7002011-10-16 02:46:151228void RenderViewImpl::OnPasteAndMatchStyle() {
1229 if (!webview())
1230 return;
1231
1232 webview()->focusedFrame()->executeCommand(
1233 WebString::fromUTF8("PasteAndMatchStyle"));
1234}
1235
[email protected]310ebd6302011-10-10 19:06:281236void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291237 if (!webview())
1238 return;
1239
[email protected]1ff7a032010-02-03 02:46:031240 WebFrame* frame = webview()->focusedFrame();
1241 if (!frame->hasSelection())
1242 frame->selectWordAroundCaret();
1243 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291244}
1245
[email protected]310ebd6302011-10-10 19:06:281246void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291247 if (!webview())
1248 return;
1249
[email protected]26aa0482009-09-30 16:55:271250 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291251}
1252
[email protected]310ebd6302011-10-10 19:06:281253void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291254 if (!webview())
1255 return;
1256
[email protected]26aa0482009-09-30 16:55:271257 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221258 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291259}
1260
[email protected]310ebd6302011-10-10 19:06:281261void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1262 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081263 if (!webview())
1264 return;
1265
1266 handling_select_range_ = true;
1267 webview()->focusedFrame()->selectRange(start, end);
1268 handling_select_range_ = false;
1269}
1270
[email protected]310ebd6302011-10-10 19:06:281271void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1272 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191273 DCHECK(history_length >= 0);
1274 DCHECK(history_list_offset_ == history_list_length_ - 1);
1275 DCHECK(minimum_page_id >= -1);
1276
1277 // Generate the new list.
1278 std::vector<int32> new_history_page_ids(history_length, -1);
1279 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1280 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1281 continue;
1282 new_history_page_ids.push_back(history_page_ids_[i]);
1283 }
1284 new_history_page_ids.swap(history_page_ids_);
1285
1286 // Update indexes.
1287 history_list_length_ = history_page_ids_.size();
1288 history_list_offset_ = history_list_length_ - 1;
1289}
1290
1291
[email protected]310ebd6302011-10-10 19:06:281292void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291293 if (!webview())
1294 return;
[email protected]26aa0482009-09-30 16:55:271295 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291296}
1297
[email protected]54ca3ca892011-06-07 21:14:541298#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281299void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331300 if (!webview())
1301 return;
1302 if (in_live_resize)
1303 webview()->willStartLiveResize();
1304 else
1305 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541306}
1307#endif
1308
[email protected]310ebd6302011-10-10 19:06:281309void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1310 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091311 WebKit::WebNode node = GetFocusedNode();
1312 if (!node.isNull()) {
1313 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191314 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511315 }
1316}
1317
initial.commit09911bf2008-07-26 23:55:291318///////////////////////////////////////////////////////////////////////////////
1319
1320// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281321void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451322 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291323 DCHECK(ds);
1324
[email protected]726985e22009-06-18 21:09:281325 const WebURLRequest& request = ds->request();
1326 const WebURLRequest& original_request = ds->originalRequest();
1327 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291328
[email protected]007733c2011-11-17 00:34:071329 DocumentState* document_state = DocumentState::FromDataSource(ds);
1330 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291331
1332 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281333 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291334 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051335 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291336 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071337 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191338 params.socket_address.set_host(response.remoteIPAddress().utf8());
1339 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031340 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091341 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071342 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291343 // SSL state specified in the request takes precedence over the one in the
1344 // response.
1345 // So far this is only intended for error pages that are not expected to be
1346 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281347 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071348 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291349 } else {
[email protected]726985e22009-06-18 21:09:281350 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291351 }
1352
1353 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311354 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291355
[email protected]5f9b8712011-11-23 08:55:571356 if (frame->document().baseURL() != params.url)
1357 params.base_url = frame->document().baseURL();
1358
[email protected]726985e22009-06-18 21:09:281359 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241360 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041361 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291362
[email protected]007733c2011-11-17 00:34:071363 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351364 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071365 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291366
1367 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071368 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291369 if (password_form_data)
1370 params.password_form = *password_form_data;
1371
1372 params.gesture = navigation_gesture_;
1373 navigation_gesture_ = NavigationGestureUnknown;
1374
[email protected]0f38dc4552011-02-25 11:24:001375 // Make navigation state a part of the FrameNavigate message so that commited
1376 // entry had it at all times.
1377 const WebHistoryItem& item = frame->currentHistoryItem();
1378 if (!item.isNull()) {
1379 params.content_state = webkit_glue::HistoryItemToString(item);
1380 } else {
1381 params.content_state =
1382 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1383 }
1384
[email protected]dd7daa82009-08-10 05:46:451385 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291386 // Top-level navigation.
1387
[email protected]b75b8292010-10-01 07:28:251388 // Set zoom level, but don't do it for full-page plugin since they don't use
1389 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011390 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541391 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251392 if (webview()->mainFrame()->document().isPluginDocument()) {
1393 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251394 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251395 } else {
1396 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251397 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251398 }
1399
[email protected]f85f0702010-01-30 09:31:011400 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511401 // This zoom level was merely recorded transiently for this load. We can
1402 // erase it now. If at some point we reload this page, the browser will
1403 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011404 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511405 }
1406
[email protected]b75b8292010-10-01 07:28:251407 // Reset the zoom limits in case a plugin had changed them previously. This
1408 // will also call us back which will cause us to send a message to
[email protected]770005b2012-04-16 15:58:131409 // update WebContentsImpl.
[email protected]b75b8292010-10-01 07:28:251410 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011411 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1412 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251413
initial.commit09911bf2008-07-26 23:55:291414 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551415 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291416
[email protected]daa8c58e2009-06-15 17:21:101417 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581418 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291419 // If the main frame does a load, it should not be reported as a subframe
1420 // navigation. This can occur in the following case:
1421 // 1. You're on a site with frames.
1422 // 2. You do a subframe navigation. This is stored with transition type
1423 // MANUAL_SUBFRAME.
1424 // 3. You navigate to some non-frame site, say, google.com.
1425 // 4. You navigate back to the page from step 2. Since it was initially
1426 // MANUAL_SUBFRAME, it will be that same transition type here.
1427 // We don't want that, because any navigation that changes the toplevel
1428 // frame should be tracked as a toplevel navigation (this allows us to
1429 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581430 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291431 }
1432
initial.commit09911bf2008-07-26 23:55:291433 // If we have a valid consumed client redirect source,
1434 // the page contained a client redirect (meta refresh, document.loc...),
1435 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151436 if (completed_client_redirect_src_.url.is_valid()) {
1437 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291438 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581439 params.transition = static_cast<content::PageTransition>(
1440 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291441 } else {
1442 // Bug 654101: the referrer will be empty on https->http transitions. It
1443 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151444 params.referrer = Referrer(GURL(
1445 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:591446 GetReferrerPolicyFromRequest(frame, original_request));
initial.commit09911bf2008-07-26 23:55:291447 }
1448
[email protected]726985e22009-06-18 21:09:281449 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051450 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291451 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051452 params.post_id = ExtractPostId(item);
1453 }
initial.commit09911bf2008-07-26 23:55:291454
[email protected]c2a797d2009-09-21 16:46:321455 // Save some histogram data so we can compute the average memory used per
1456 // page load of the glyphs.
1457 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1458 webkit_glue::GetGlyphPageCount());
1459
[email protected]15cf526b2010-02-12 06:33:491460 // This message needs to be sent before any of allowScripts(),
1461 // allowImages(), allowPlugins() is called for the new page, so that when
1462 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1463 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291464 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1465 } else {
1466 // Subframe navigation: the type depends on whether this navigation
1467 // generated a new session history entry. When they do generate a session
1468 // history entry, it means the user initiated the navigation and we should
1469 // mark it as such. This test checks if this is the first time UpdateURL
1470 // has been called since WillNavigateToURL was called to initiate the load.
1471 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581472 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291473 else
[email protected]2905f742011-10-13 03:51:581474 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291475
initial.commit09911bf2008-07-26 23:55:291476 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1477 }
1478
1479 last_page_id_sent_to_browser_ =
1480 std::max(last_page_id_sent_to_browser_, page_id_);
1481
1482 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101483 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581484 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291485}
1486
1487// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281488void RenderViewImpl::UpdateTitle(WebFrame* frame,
1489 const string16& title,
1490 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461491 // Ignore all but top level navigations.
1492 if (frame->parent())
1493 return;
1494
1495 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1496 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1497 title_direction));
initial.commit09911bf2008-07-26 23:55:291498}
1499
[email protected]310ebd6302011-10-10 19:06:281500void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1501 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291502 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271503 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291504 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301505 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291506 last_encoding_name_ = encoding_name;
1507
[email protected]e38f40152008-09-12 23:08:301508 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291509 }
1510}
1511
[email protected]e15f680732010-11-23 22:30:201512// Sends the last committed session history state to the browser so it will be
1513// saved before we navigate to a new page. This must be called *before* the
1514// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281515void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291516 // If we have a valid page ID at this point, then it corresponds to the page
1517 // we are navigating away from. Otherwise, this is the first navigation, so
1518 // there is no past session history to record.
1519 if (page_id_ == -1)
1520 return;
1521
[email protected]ca948a22009-06-25 19:36:171522 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271523 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051524 SendUpdateState(item);
1525}
1526
1527void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171528 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291529 return;
[email protected]ca948a22009-06-25 19:36:171530
[email protected]285f4bb82012-04-17 15:57:281531 // Don't send state updates for content::kSwappedOutURL.
1532 if (item.urlString() == WebString::fromUTF8(content::kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051533 return;
1534
[email protected]ca948a22009-06-25 19:36:171535 Send(new ViewHostMsg_UpdateState(
1536 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291537}
1538
[email protected]310ebd6302011-10-10 19:06:281539void RenderViewImpl::OpenURL(WebFrame* frame,
1540 const GURL& url,
[email protected]445e1042011-12-03 21:03:151541 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281542 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171543 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581544 routing_id_,
1545 url,
1546 referrer,
1547 NavigationPolicyToDisposition(policy),
1548 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171549}
1550
[email protected]79dbc662009-09-04 05:42:511551// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291552
[email protected]310ebd6302011-10-10 19:06:281553void RenderViewImpl::LoadNavigationErrorPage(
1554 WebFrame* frame,
1555 const WebURLRequest& failed_request,
1556 const WebURLError& error,
1557 const std::string& html,
1558 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581559 std::string alt_html;
1560 const std::string* error_html;
1561
1562 if (!html.empty()) {
1563 error_html = &html;
1564 } else {
1565 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1566 failed_request, error, &alt_html, NULL);
1567 error_html = &alt_html;
1568 }
1569
1570 frame->loadHTMLString(*error_html,
[email protected]285f4bb82012-04-17 15:57:281571 GURL(content::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251572 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551573 replace);
initial.commit09911bf2008-07-26 23:55:291574}
1575
[email protected]be2510c02012-05-28 14:52:141576bool RenderViewImpl::RunJavaScriptMessage(content::JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281577 const string16& message,
1578 const string16& default_value,
1579 const GURL& frame_url,
1580 string16* result) {
initial.commit09911bf2008-07-26 23:55:291581 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411582 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291583 if (!result)
1584 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291585
[email protected]12636df2009-09-28 22:32:211586 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1587 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291588 return success;
1589}
1590
[email protected]310ebd6302011-10-10 19:06:281591bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571592 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1593 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1594 // it is particularly important that we do not call willEnterModalLoop as
1595 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441596 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1597 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571598
1599 message->EnableMessagePumping(); // Runs a nested message loop.
1600 return Send(message);
1601}
1602
[email protected]48c9cf2d2009-09-16 16:47:521603// WebKit::WebViewClient ------------------------------------------------------
1604
[email protected]916dfb62012-03-05 03:39:371605WebView* RenderViewImpl::createView(
1606 WebFrame* creator,
1607 const WebURLRequest& request,
1608 const WebWindowFeatures& features,
1609 const WebString& frame_name,
1610 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521611 // Check to make sure we aren't overloading on popups.
1612 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1613 return NULL;
1614
[email protected]8ab04652010-06-12 02:47:261615 ViewHostMsg_CreateWindow_Params params;
1616 params.opener_id = routing_id_;
1617 params.user_gesture = creator->isProcessingUserGesture();
1618 params.window_container_type = WindowFeaturesToContainerType(features);
1619 params.session_storage_namespace_id = session_storage_namespace_id_;
1620 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111621 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411622 params.opener_url = creator->document().url();
1623 params.opener_security_origin =
1624 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591625 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1626 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111627 if (!request.isNull())
1628 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261629
[email protected]48c9cf2d2009-09-16 16:47:521630 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561631 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341632 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521633
[email protected]380244092011-10-07 17:26:271634 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261635 new ViewHostMsg_CreateWindow(params,
1636 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561637 &surface_id,
[email protected]8ab04652010-06-12 02:47:261638 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211639 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521640 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521641
[email protected]8cca3da2012-03-20 08:26:341642 // TODO(fsamuel): The host renderer needs to be able to control whether
1643 // the guest renderer is allowed to do this or not. This current
1644 // behavior is not well defined.
[email protected]310ebd6302011-10-10 19:06:281645 RenderViewImpl* view = RenderViewImpl::Create(
1646 0,
1647 routing_id_,
1648 renderer_preferences_,
1649 webkit_preferences_,
1650 shared_popup_counter_,
1651 routing_id,
[email protected]9f4f3322012-01-18 22:29:561652 surface_id,
[email protected]310ebd6302011-10-10 19:06:281653 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461654 frame_name,
[email protected]14392a52012-05-02 20:28:441655 true,
1656 false,
[email protected]6fd35b72012-03-01 19:46:411657 1,
[email protected]842f10652012-06-06 01:54:041658 screen_info_,
[email protected]468e4902012-05-23 01:49:311659 guest_to_embedder_channel_,
[email protected]3e3c4522012-04-13 21:16:291660 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261661 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521662
[email protected]007a848b2009-10-26 15:55:461663 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591664 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461665
[email protected]48c9cf2d2009-09-16 16:47:521666 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411667 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521668 if (!creator_url.is_valid() || !creator_url.IsStandard())
1669 creator_url = GURL();
1670 view->creator_url_ = creator_url;
1671
1672 // Copy over the alternate error page URL so we can have alt error pages in
1673 // the new render view (we don't need the browser to send the URL back down).
1674 view->alternate_error_page_url_ = alternate_error_page_url_;
1675
1676 return view->webview();
1677}
1678
[email protected]310ebd6302011-10-10 19:06:281679WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411680 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:041681 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521682 return widget->webwidget();
1683}
1684
[email protected]310ebd6302011-10-10 19:06:281685WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081686 const WebPopupMenuInfo& popup_menu_info,
1687 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:271688 // An IPC message is sent to the browser to build and display the actual
1689 // popup. The user could have time to click a different select by the time
1690 // the popup is shown. In that case external_popup_menu_ is non NULL.
1691 // By returning NULL in that case, we instruct WebKit to cancel that new
1692 // popup. So from the user perspective, only the first one will show, and
1693 // will have to close the first one before another one can be shown.
1694 if (external_popup_menu_.get())
1695 return NULL;
[email protected]caf706f2010-10-26 17:54:081696 external_popup_menu_.reset(
1697 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1698 return external_popup_menu_.get();
1699}
1700
[email protected]310ebd6302011-10-10 19:06:281701RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521702 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531703 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421704 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411705 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531706 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271707 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391708 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561709 return widget;
[email protected]79c7bed2010-09-14 22:28:391710}
1711
[email protected]310ebd6302011-10-10 19:06:281712WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1713 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:161714 CHECK(session_storage_namespace_id_ !=
1715 dom_storage::kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101716 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341717}
1718
[email protected]7e8b4d12012-01-20 23:39:511719WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]40ec0c12012-03-08 12:34:401720 const WebGraphicsContext3D::Attributes& attributes) {
[email protected]7e8b4d12012-01-20 23:39:511721 if (!webview())
1722 return NULL;
[email protected]468e4902012-05-23 01:49:311723
[email protected]7900bfdb2012-05-24 19:31:241724 if (GetGuestToEmbedderChannel()) {
[email protected]468e4902012-05-23 01:49:311725 WebGraphicsContext3DCommandBufferImpl* context =
[email protected]7900bfdb2012-05-24 19:31:241726 GetGuestToEmbedderChannel()->CreateWebGraphicsContext3D(
[email protected]468e4902012-05-23 01:49:311727 this, attributes, false);
1728 if (!guest_pp_instance()) {
1729 guest_uninitialized_context_ = context;
1730 guest_attributes_ = attributes;
1731 }
1732 return context;
1733 }
1734
[email protected]7e8b4d12012-01-20 23:39:511735 // The WebGraphicsContext3DInProcessImpl code path is used for
1736 // layout tests (though not through this code) as well as for
1737 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511738 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571739 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
[email protected]29dea0e2012-03-16 01:46:581740 attributes, true);
[email protected]7e8b4d12012-01-20 23:39:511741 } else {
[email protected]b3e83de2012-02-07 03:33:281742 GURL url;
1743 if (webview()->mainFrame())
1744 url = GURL(webview()->mainFrame()->document().url());
1745
[email protected]b3e83de2012-02-07 03:33:281746 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1747 new WebGraphicsContext3DCommandBufferImpl(
[email protected]8c9e0a02012-04-02 05:13:191748 surface_id(),
1749 url,
1750 RenderThreadImpl::current(),
1751 AsWeakPtr()));
[email protected]b3e83de2012-02-07 03:33:281752
[email protected]8c9e0a02012-04-02 05:13:191753 if (!context->Initialize(
1754 attributes,
1755 false /* bind generates resources */,
1756 content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
[email protected]56200f012012-02-03 23:13:571757 return NULL;
[email protected]d0fb8a72012-03-10 18:54:521758 context_is_web_graphics_context_3d_command_buffer_impl_ = true;
[email protected]56200f012012-02-03 23:13:571759 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511760 }
[email protected]7e8b4d12012-01-20 23:39:511761}
1762
[email protected]310ebd6302011-10-10 19:06:281763void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521764 const WebConsoleMessage& message, const WebString& source_name,
1765 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081766 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511767 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081768 case WebConsoleMessage::LevelTip:
1769 log_severity = logging::LOG_VERBOSE;
1770 break;
1771 case WebConsoleMessage::LevelLog:
1772 log_severity = logging::LOG_INFO;
1773 break;
1774 case WebConsoleMessage::LevelWarning:
1775 log_severity = logging::LOG_WARNING;
1776 break;
1777 case WebConsoleMessage::LevelError:
1778 log_severity = logging::LOG_ERROR;
1779 break;
1780 default:
1781 NOTREACHED();
1782 }
1783
[email protected]48c9cf2d2009-09-16 16:47:521784 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081785 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311786 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521787 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311788 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521789}
1790
[email protected]310ebd6302011-10-10 19:06:281791void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421792 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521793}
1794
[email protected]310ebd6302011-10-10 19:06:281795WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511796 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021797}
1798
[email protected]310ebd6302011-10-10 19:06:281799bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121800 const WebString& path,
1801 WebFileChooserCompletion* chooser_completion) {
1802 int id = enumeration_completion_id_++;
1803 enumeration_completions_[id] = chooser_completion;
1804 return Send(new ViewHostMsg_EnumerateDirectory(
1805 routing_id_,
1806 id,
1807 webkit_glue::WebStringToFilePath(path)));
1808}
1809
[email protected]310ebd6302011-10-10 19:06:281810void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521811 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141812 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521813 return;
1814 }
1815
1816 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521817
1818 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311819
1820 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521821}
1822
[email protected]310ebd6302011-10-10 19:06:281823void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521824 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141825 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521826 return;
1827 }
1828
1829 is_loading_ = false;
1830
1831 // NOTE: For now we're doing the safest thing, and sending out notification
1832 // when done loading. This currently isn't an issue as the favicon is only
1833 // displayed when done loading. Ideally we would send notification when
1834 // finished parsing the head, but webkit doesn't support that yet.
1835 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521836 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1837
[email protected]90109412010-12-15 17:14:241838 if (load_progress_tracker_ != NULL)
1839 load_progress_tracker_->DidStopLoading();
1840
[email protected]93b9d692011-04-13 00:44:311841 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521842}
1843
[email protected]310ebd6302011-10-10 19:06:281844void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1845 double load_progress) {
[email protected]90109412010-12-15 17:14:241846 if (load_progress_tracker_ != NULL)
1847 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1848}
1849
[email protected]310ebd6302011-10-10 19:06:281850bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061851#if defined(OS_MACOSX)
1852 return true;
1853#else
1854 return false;
1855#endif
1856}
1857
[email protected]310ebd6302011-10-10 19:06:281858bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031859#if defined(OS_WIN)
1860 return true;
1861#else
1862 return false;
1863#endif
1864}
1865
[email protected]310ebd6302011-10-10 19:06:281866void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081867 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031868 return;
[email protected]4fb60142011-08-09 02:22:081869 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011870
[email protected]fca52022012-04-03 17:00:501871 if (is_empty_selection)
1872 selection_text_.clear();
1873
[email protected]b781ff282011-08-20 06:19:361874 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031875}
1876
[email protected]310ebd6302011-10-10 19:06:281877void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121878 const std::string& name = UTF16ToUTF8(command_name);
1879 if (StartsWithASCII(name, "Move", true) ||
1880 StartsWithASCII(name, "Insert", true) ||
1881 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031882 return;
[email protected]f1a29a02011-10-06 23:08:441883 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031884}
1885
[email protected]310ebd6302011-10-10 19:06:281886bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101887 if (edit_commands_.empty())
1888 return false;
1889
[email protected]26aa0482009-09-30 16:55:271890 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101891 if (!frame)
1892 return false;
1893
1894 EditCommands::iterator it = edit_commands_.begin();
1895 EditCommands::iterator end = edit_commands_.end();
1896
[email protected]507b33ea2009-09-29 03:56:511897 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101898 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331899 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1900 // key (but it's the exception). Once one edit command is not executed, it
1901 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101902 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1903 WebString::fromUTF8(it->value)))
1904 break;
[email protected]507b33ea2009-09-29 03:56:511905 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101906 }
1907
[email protected]507b33ea2009-09-29 03:56:511908 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101909}
1910
[email protected]da8543762012-03-20 08:52:201911WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
1912 WebKit::WebColorChooserClient* client,
1913 const WebKit::WebColor& initial_color) {
1914 RendererWebColorChooserImpl* color_chooser =
1915 new RendererWebColorChooserImpl(this, client);
1916 color_chooser->Open(static_cast<SkColor>(initial_color));
1917 return color_chooser;
1918}
1919
[email protected]310ebd6302011-10-10 19:06:281920bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351921 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471922 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351923 // Do not open the file dialog in a hidden RenderView.
1924 if (is_hidden())
1925 return false;
[email protected]8caadeb2011-11-22 02:45:231926 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261927 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231928 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261929 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231930 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501931 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231932 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261933 else
[email protected]8caadeb2011-11-22 02:45:231934 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471935 ipc_params.title = params.title;
1936 ipc_params.default_file_name =
1937 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:321938 ipc_params.accept_types.reserve(params.acceptTypes.size());
1939 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
1940 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471941
1942 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461943}
1944
[email protected]269f86d2011-12-07 02:43:471945void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1946 const WebString& message) {
[email protected]be2510c02012-05-28 14:52:141947 RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411948 message,
1949 string16(),
[email protected]b6cb3a842011-06-24 18:28:411950 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521951 NULL);
1952}
1953
[email protected]269f86d2011-12-07 02:43:471954bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1955 const WebString& message) {
[email protected]be2510c02012-05-28 14:52:141956 return RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411957 message,
1958 string16(),
[email protected]b6cb3a842011-06-24 18:28:411959 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521960 NULL);
1961}
1962
[email protected]269f86d2011-12-07 02:43:471963bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1964 const WebString& message,
1965 const WebString& default_value,
1966 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411967 string16 result;
[email protected]be2510c02012-05-28 14:52:141968 bool ok = RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411969 message,
1970 default_value,
[email protected]b6cb3a842011-06-24 18:28:411971 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521972 &result);
1973 if (ok)
[email protected]4f5ce842011-05-27 19:34:411974 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521975 return ok;
1976}
1977
[email protected]310ebd6302011-10-10 19:06:281978bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521979 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151980 // If we are swapping out, we have already run the beforeunload handler.
1981 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1982 // at all, to avoid running it twice.
1983 if (is_swapped_out_)
1984 return true;
1985
[email protected]3b3301f62012-02-29 04:32:321986 bool is_reload = false;
1987 WebDataSource* ds = frame->provisionalDataSource();
1988 if (ds)
1989 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
1990
[email protected]48c9cf2d2009-09-16 16:47:521991 bool success = false;
1992 // This is an ignored return value, but is included so we can accept the same
1993 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411994 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211995 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:321996 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:411997 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521998 return success;
1999}
2000
[email protected]310ebd6302011-10-10 19:06:282001void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442002 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:512003 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:372004
2005 // frame is NULL if invoked by BlockedPlugin.
2006 if (frame)
2007 params.frame_id = frame->identifier();
2008
[email protected]db803aae2011-03-05 02:00:422009 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272010 // it. We replace it with an empty GURL so the appropriate items are disabled
2011 // in the context menu.
2012 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2013 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:422014 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272015 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102016 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:292017 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442018}
2019
[email protected]310ebd6302011-10-10 19:06:282020void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522021}
2022
[email protected]310ebd6302011-10-10 19:06:282023void RenderViewImpl::UpdateTargetURL(const GURL& url,
2024 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582025 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522026 if (latest_url == target_url_)
2027 return;
[email protected]163f8242009-10-30 20:19:552028
[email protected]48c9cf2d2009-09-16 16:47:522029 // Tell the browser to display a destination link.
2030 if (target_url_status_ == TARGET_INFLIGHT ||
2031 target_url_status_ == TARGET_PENDING) {
2032 // If we have a request in-flight, save the URL to be sent when we
2033 // receive an ACK to the in-flight request. We can happily overwrite
2034 // any existing pending sends.
2035 pending_target_url_ = latest_url;
2036 target_url_status_ = TARGET_PENDING;
2037 } else {
[email protected]c85f0212011-11-04 16:54:412038 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
2039 // see |ParamTraits<GURL>|.
2040 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
2041 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522042 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2043 target_url_ = latest_url;
2044 target_url_status_ = TARGET_INFLIGHT;
2045 }
2046}
2047
[email protected]310ebd6302011-10-10 19:06:282048void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:312049 int delay;
2050 if (send_content_state_immediately_)
2051 delay = 0;
2052 else if (is_hidden())
2053 delay = kDelaySecondsForContentStateSyncHidden;
2054 else
2055 delay = kDelaySecondsForContentStateSync;
2056
2057 if (nav_state_sync_timer_.IsRunning()) {
2058 // The timer is already running. If the delay of the timer maches the amount
2059 // we want to delay by, then return. Otherwise stop the timer so that it
2060 // gets started with the right delay.
2061 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2062 return;
2063 nav_state_sync_timer_.Stop();
2064 }
2065
[email protected]d323a172011-09-02 18:23:022066 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282067 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312068}
2069
[email protected]310ebd6302011-10-10 19:06:282070void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552071 mouse_over_url_ = GURL(url);
2072 UpdateTargetURL(mouse_over_url_, focus_url_);
2073}
2074
[email protected]310ebd6302011-10-10 19:06:282075void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552076 focus_url_ = GURL(url);
2077 UpdateTargetURL(focus_url_, mouse_over_url_);
2078}
2079
[email protected]0407e422012-05-18 19:51:252080void RenderViewImpl::startDragging(WebFrame* frame,
2081 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282082 WebDragOperationsMask mask,
2083 const WebImage& image,
2084 const WebPoint& imageOffset) {
[email protected]b67151d2012-05-25 23:23:242085 WebDropData drop_data(data);
2086 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]59f4f2fa2011-03-23 01:00:552087 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242088 drop_data,
[email protected]c27ae592010-03-18 15:24:412089 mask,
[email protected]976127072012-05-10 20:08:112090 image.getSkBitmap(),
[email protected]c27ae592010-03-18 15:24:412091 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522092}
2093
[email protected]310ebd6302011-10-10 19:06:282094bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452095 return renderer_preferences_.can_accept_load_drops;
2096}
2097
[email protected]310ebd6302011-10-10 19:06:282098void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522099 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2100}
2101
[email protected]310ebd6302011-10-10 19:06:282102void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522103 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2104}
2105
[email protected]310ebd6302011-10-10 19:06:282106void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512107 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072108
[email protected]38b592902011-04-16 02:08:422109 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492110}
2111
[email protected]169d4282011-11-30 19:33:592112void RenderViewImpl::didUpdateLayout() {
2113 // We don't always want to set up a timer, only if we've been put in that
2114 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2115 // message.
2116 if (!send_preferred_size_changes_ || !webview())
2117 return;
2118
2119 if (check_preferred_size_timer_.IsRunning())
2120 return;
2121 check_preferred_size_timer_.Start(FROM_HERE,
2122 TimeDelta::FromMilliseconds(0), this,
2123 &RenderViewImpl::CheckPreferredSize);
2124}
2125
[email protected]310ebd6302011-10-10 19:06:282126void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522127 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2128}
2129
[email protected]310ebd6302011-10-10 19:06:282130int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002131 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522132}
2133
[email protected]310ebd6302011-10-10 19:06:282134int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002135 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522136}
2137
[email protected]310ebd6302011-10-10 19:06:282138void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322139 const WebAccessibilityObject& obj,
2140 WebAccessibilityNotification notification) {
[email protected]2a84f9d2012-06-05 21:50:432141 if (renderer_accessibility_) {
2142 renderer_accessibility_->HandleWebAccessibilityNotification(
2143 obj, notification);
2144 }
[email protected]063afcb2011-09-29 07:54:322145}
2146
[email protected]310ebd6302011-10-10 19:06:282147void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142148 const WebString& value) {
2149 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2150 key.utf8(),
2151 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262152}
2153
[email protected]79dbc662009-09-04 05:42:512154// WebKit::WebWidgetClient ----------------------------------------------------
2155
[email protected]310ebd6302011-10-10 19:06:282156void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122157 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2158 // we won't have to test for user gesture anymore and we can
2159 // move that code back to render_widget.cc
2160 if (webview() && webview()->mainFrame() &&
2161 webview()->mainFrame()->isProcessingUserGesture()) {
2162 Send(new ViewHostMsg_Focus(routing_id_));
2163 }
2164}
2165
[email protected]310ebd6302011-10-10 19:06:282166void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122167 // TODO(jcivelli): see TODO above in didFocus().
2168 if (webview() && webview()->mainFrame() &&
2169 webview()->mainFrame()->isProcessingUserGesture()) {
2170 Send(new ViewHostMsg_Blur(routing_id_));
2171 }
2172}
2173
initial.commit09911bf2008-07-26 23:55:292174// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282175// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292176// point to dispatch the ShowView message.
2177//
2178// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282179// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292180//
[email protected]310ebd6302011-10-10 19:06:282181void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292182 DCHECK(!did_show_) << "received extraneous Show call";
2183 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2184
2185 if (did_show_)
2186 return;
2187 did_show_ = true;
2188
[email protected]6779aa12011-03-29 17:32:242189 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042190 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042191
[email protected]28295ec2009-10-16 05:34:332192 // Force new windows to a popup if they were not opened with a user gesture.
2193 if (!opened_by_user_gesture_) {
2194 // We exempt background tabs for compat with older versions of Chrome.
2195 // TODO(darin): This seems bogus. These should have a user gesture, so
2196 // we probably don't need this check.
2197 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2198 policy = WebKit::WebNavigationPolicyNewPopup;
2199 }
2200
initial.commit09911bf2008-07-26 23:55:292201 // NOTE: initial_pos_ may still have its default values at this point, but
2202 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2203 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282204 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2205 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292206 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242207 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292208}
2209
[email protected]310ebd6302011-10-10 19:06:282210void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292211 DCHECK(did_show_) << "should already have shown the view";
2212
[email protected]c1f50aa2010-02-18 03:46:572213 // We must keep WebKit's shared timer running in this case in order to allow
2214 // showModalDialog to function properly.
2215 //
2216 // TODO(darin): WebKit should really be smarter about suppressing events and
2217 // timers so that we do not need to manage the shared timer in such a heavy
2218 // handed manner.
2219 //
[email protected]f1a29a02011-10-06 23:08:442220 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2221 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572222
[email protected]08a1c8102012-05-11 23:14:262223 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2224 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292225}
2226
[email protected]2b624c562011-10-27 22:58:262227bool RenderViewImpl::enterFullScreen() {
2228 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2229 return true;
2230}
2231
2232void RenderViewImpl::exitFullScreen() {
2233 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2234}
2235
[email protected]217690d2012-01-27 07:33:112236bool RenderViewImpl::requestPointerLock() {
2237 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2238}
2239
2240void RenderViewImpl::requestPointerUnlock() {
2241 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2242}
2243
2244bool RenderViewImpl::isPointerLocked() {
2245 return mouse_lock_dispatcher_->IsMouseLockedTo(
2246 webwidget_mouse_lock_target_.get());
2247}
2248
[email protected]7a1ec28a2012-03-28 21:10:242249void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2250 CompositorThread* compositor_thread =
2251 RenderThreadImpl::current()->compositor_thread();
2252 if (compositor_thread)
2253 compositor_thread->AddInputHandler(
2254 routing_id_, input_handler_identifier, AsWeakPtr());
2255
2256 RenderWidget::didActivateCompositor(input_handler_identifier);
2257}
2258
[email protected]3d9689372009-09-10 04:29:172259// WebKit::WebFrameClient -----------------------------------------------------
2260
[email protected]310ebd6302011-10-10 19:06:282261WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2262 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552263 WebPlugin* plugin = NULL;
2264 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2265 this, frame, params, &plugin)) {
2266 return plugin;
2267 }
2268
[email protected]b1c4de4c2012-06-08 00:04:562269 std::string browser_plugin_switch = CommandLine::ForCurrentProcess()->
2270 GetSwitchValueASCII(switches::kBrowserPlugin);
2271 // Check only that the browser plugin isn't disabled. The client layer
2272 // may have provided additional selective enabling of the plugin, and
2273 // so we can't assume that 'enabled' is the only state where it should
2274 // be activated. If it isn't, then the client layer should have caught
2275 // this in OverrideCreatePlugin already.
2276 if (!browser_plugin_switch.empty() &&
2277 UTF16ToASCII(params.mimeType) == content::kBrowserPluginMimeType)
2278 return BrowserPlugin::Create(this, frame, params);
2279
[email protected]a813c8e2011-10-08 01:34:112280 webkit::WebPluginInfo info;
2281 std::string mime_type;
2282 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2283 params.mimeType.utf8(), &info, &mime_type);
2284 if (!found)
2285 return NULL;
2286
2287 WebPluginParams params_to_use = params;
2288 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312289 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172290}
2291
[email protected]6ac77cb2012-05-01 14:49:012292WebPlugin* RenderViewImpl::createPluginReplacement(
2293 WebFrame* frame,
2294 const WebPluginParams& params) {
2295 webkit::WebPluginInfo info;
2296 std::string mime_type;
2297 GetPluginInfo(params.url, frame->top()->document().url(),
2298 params.mimeType.utf8(), &info, &mime_type);
2299 return content::GetContentClient()->renderer()->CreatePluginReplacement(
2300 this, info.path);
2301}
2302
[email protected]310ebd6302011-10-10 19:06:282303WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422304 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372305 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422306
[email protected]30447b62009-11-13 01:13:372307 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512308 bool exists = false;
[email protected]30447b62009-11-13 01:13:372309 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512310 ViewHostMsg_CreateWorker_Params params;
2311 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512312 params.name = name;
2313 params.document_id = document_id;
2314 params.render_view_route_id = routing_id_;
2315 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232316 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372317 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512318 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372319 if (url_mismatch) {
2320 return NULL;
2321 } else {
[email protected]f1a29a02011-10-06 23:08:442322 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492323 document_id,
[email protected]6de0bcf2010-02-17 22:00:512324 exists,
[email protected]30447b62009-11-13 01:13:372325 route_id,
2326 routing_id_);
2327 }
[email protected]9c00f002009-11-05 22:37:422328}
2329
[email protected]310ebd6302011-10-10 19:06:282330WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172331 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442332 FOR_EACH_OBSERVER(
2333 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172334
[email protected]25fb9b32012-04-27 03:21:552335#if defined(OS_ANDROID)
[email protected]2d7b82c2012-06-01 05:57:502336 // TODO(qinmin): upstream the implementation of StreamTextureFactoryImpl
2337 // to replace the NULL param here.
[email protected]25fb9b32012-04-27 03:21:552338 return new webkit_media::WebMediaPlayerAndroid(
[email protected]2d7b82c2012-06-01 05:57:502339 frame, client, cookieJar(frame), media_player_manager_.get(), NULL);
[email protected]25fb9b32012-04-27 03:21:552340#endif
2341
[email protected]bb6fd402011-12-09 02:45:442342 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502343 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442344 media::FilterCollection* collection = new media::FilterCollection();
2345 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372346
[email protected]9e2269d2012-01-07 00:06:212347 RenderAudioSourceProvider* audio_source_provider = NULL;
2348
[email protected]3d9689372009-09-10 04:29:172349 // Add in any custom filter factories first.
2350 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2351 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212352 // audio_source_provider is a "provider" to WebKit, and a sink
2353 // from the perspective of the audio renderer.
2354 audio_source_provider = new RenderAudioSourceProvider();
2355
2356 // Add the chrome specific audio renderer, using audio_source_provider
2357 // as the sink.
[email protected]37136d162012-04-09 23:39:192358 media::AudioRendererImpl* audio_renderer =
2359 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212360 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172361 }
2362
[email protected]95970422012-05-22 04:00:202363 // Currently only cros/arm has any HW video decode support in
[email protected]e1d69d762011-12-13 05:12:182364 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2365 // platforms. This is a startup-time optimization. When new VDA
[email protected]95970422012-05-22 04:00:202366 // implementations are added, relax the #if above.
2367#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
[email protected]d0fb8a72012-03-10 18:54:522368 // Note we don't actually use the result of this blind down-cast unless it's
2369 // valid (not NULL and of the right type).
[email protected]43567302012-02-16 23:21:392370 WebGraphicsContext3DCommandBufferImpl* context3d =
2371 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2372 webview()->graphicsContext3D());
[email protected]d0fb8a72012-03-10 18:54:522373 if (context_is_web_graphics_context_3d_command_buffer_impl_ && context3d) {
[email protected]84a83e192012-03-09 18:43:402374 MessageLoop* factories_loop =
2375 RenderThreadImpl::current()->compositor_thread() ?
2376 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
2377 ->message_loop() :
2378 MessageLoop::current();
[email protected]e1d69d762011-12-13 05:12:182379 GpuChannelHost* gpu_channel_host =
2380 RenderThreadImpl::current()->EstablishGpuChannelSync(
2381 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2382 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312383 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
[email protected]84a83e192012-03-09 18:43:402384 factories_loop,
[email protected]8d4359282012-01-14 00:53:312385 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402386 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182387 }
2388#endif
2389
[email protected]5d65fe92012-06-02 00:48:552390 WebMediaPlayer* media_player =
[email protected]da952fd2012-01-13 03:49:252391 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2392 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1bc65a42012-04-23 09:31:252393 message_loop_factory, media_stream_impl_, render_media_log);
[email protected]da952fd2012-01-13 03:49:252394 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562395 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252396 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1bc65a42012-04-23 09:31:252397 message_loop_factory, media_stream_impl_, render_media_log);
[email protected]bb6fd402011-12-09 02:45:442398 }
[email protected]cec4eb82012-01-12 17:51:562399 return media_player;
[email protected]3d9689372009-09-10 04:29:172400}
2401
[email protected]310ebd6302011-10-10 19:06:282402WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212403 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232404 if (!frame || !frame->view())
2405 return NULL;
[email protected]035545f2010-04-09 13:10:212406 return new RendererWebApplicationCacheHostImpl(
2407 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442408 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212409}
2410
[email protected]310ebd6302011-10-10 19:06:282411WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382412 return &cookie_jar_;
2413}
2414
[email protected]310ebd6302011-10-10 19:06:282415void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512416 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452417}
2418
[email protected]310ebd6302011-10-10 19:06:282419void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512420 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172421}
2422
[email protected]310ebd6302011-10-10 19:06:282423void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172424 WebFrame* frame, const WebURLRequest& request,
2425 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342426 loadURLExternally(frame, request, policy, WebString());
2427}
2428
[email protected]310ebd6302011-10-10 19:06:282429void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342430 WebFrame* frame, const WebURLRequest& request,
2431 WebNavigationPolicy policy,
2432 const WebString& suggested_name) {
[email protected]56505542012-05-12 00:25:372433 Referrer referrer(
2434 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2435 GetReferrerPolicyFromRequest(frame, request));
[email protected]efce17b2009-09-11 18:04:592436 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342437 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2438 suggested_name));
[email protected]efce17b2009-09-11 18:04:592439 } else {
[email protected]56505542012-05-12 00:25:372440 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:592441 }
[email protected]3d9689372009-09-10 04:29:172442}
2443
[email protected]310ebd6302011-10-10 19:06:282444WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172445 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222446 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332447 Referrer referrer(
2448 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:592449 GetReferrerPolicyFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:332450
[email protected]992db4c2011-05-12 15:37:152451 if (is_swapped_out_) {
[email protected]285f4bb82012-04-17 15:57:282452 if (request.url() != GURL(content::kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332453 // Targeted links may try to navigate a swapped out frame. Allow the
2454 // browser process to navigate the tab instead. Note that it is also
2455 // possible for non-targeted navigations (from this view) to arrive
2456 // here just after we are swapped out. It's ok to send them to the
2457 // browser, as long as they're for the top level frame.
2458 // TODO(creis): Ensure this supports targeted form submissions when
2459 // fixing http://crbug.com/101395.
2460 if (frame->parent() == NULL) {
2461 OpenURL(frame, request.url(), referrer, default_policy);
2462 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2463 }
2464
2465 // We should otherwise ignore in-process iframe navigations, if they
2466 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552467 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332468 }
[email protected]73eb2602012-02-09 19:50:552469
[email protected]285f4bb82012-04-17 15:57:282470 // Allow content::kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152471 return default_policy;
2472 }
2473
[email protected]3d9689372009-09-10 04:29:172474 // Webkit is asking whether to navigate to a new URL.
2475 // This is fine normally, except if we're showing UI from one security
2476 // context and they're trying to navigate to a different context.
2477 const GURL& url = request.url();
2478
[email protected]d19ea342011-04-20 20:31:132479 // A content initiated navigation may have originated from a link-click,
2480 // script, drag-n-drop operation, etc.
2481 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072482 DocumentState::FromDataSource(frame->provisionalDataSource())->
2483 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132484
[email protected]a8c269a2011-10-25 20:17:222485 // Experimental:
2486 // If --enable-strict-site-isolation is enabled, send all top-level
2487 // navigations to the browser to let it swap processes when crossing site
2488 // boundaries. This is currently expected to break some script calls and
2489 // navigations, such as form submissions.
2490 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102491 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2492 !frame->parent() && (is_content_initiated || is_redirect)) {
2493 WebString origin_str = frame->document().securityOrigin().toString();
2494 GURL frame_url(origin_str.utf8().data());
2495 // TODO(cevans): revisit whether this origin check is still necessary once
2496 // crbug.com/101395 is fixed.
2497 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]313b80bd2011-11-23 03:49:102498 OpenURL(frame, url, referrer, default_policy);
2499 return WebKit::WebNavigationPolicyIgnore;
2500 }
[email protected]a8c269a2011-10-25 20:17:222501 }
2502
[email protected]fd3238af2012-05-22 18:55:302503 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:082504 if (is_content_initiated) {
[email protected]fd3238af2012-05-22 18:55:302505 bool browser_handles_request =
2506 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]5f000f272012-01-19 05:25:082507 IsNonLocalTopLevelNavigation(url, frame, type);
[email protected]fd3238af2012-05-22 18:55:302508 if (!browser_handles_request) {
2509 browser_handles_request =
2510 renderer_preferences_.browser_handles_all_top_level_requests &&
2511 IsTopLevelNavigation(frame);
2512 }
2513
2514 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:082515 // Reset these counters as the RenderView could be reused for the next
2516 // navigation.
2517 page_id_ = -1;
2518 last_page_id_sent_to_browser_ = -1;
2519 OpenURL(frame, url, referrer, default_policy);
2520 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2521 }
[email protected]3d9689372009-09-10 04:29:172522 }
2523
[email protected]dc67e1c32012-06-08 00:10:402524 // Use the frame's original request's URL rather than the document's URL for
2525 // subsequent checks. For a popup, the document's URL may become the opener
2526 // window's URL if the opener has called document.write().
2527 // See http://crbug.com/93517.
2528 GURL old_url(frame->dataSource()->request().url());
2529
[email protected]6101c342010-12-16 22:44:372530 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552531 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042532 // top-level navigations (not iframes). But we sometimes navigate to
2533 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372534 //
[email protected]744c2a22012-03-15 18:42:042535 // Note: this is known to break POST submissions when crossing process
2536 // boundaries until http://crbug.com/101395 is fixed. This is better for
2537 // security than loading a WebUI, extension or app page in the wrong process.
2538 // POST requests don't work because this mechanism does not preserve form
2539 // POST data. We will need to send the request's httpBody data up to the
2540 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572541 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2542 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222543 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042544 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372545 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042546
2547 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2548 // must be handled by the browser process so that the correct bindings and
2549 // data sources can be registered.
2550 // Similarly, navigations to view-source URLs or within ViewSource mode
2551 // must be handled by the browser process.
[email protected]dc67e1c32012-06-08 00:10:402552 // Lastly, access to file:// URLs from non-file:// URL pages must be
2553 // handled by the browser so that ordinary renderer processes don't get
2554 // blessed with file permissions.
2555 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
2556 bool is_initial_navigation = page_id_ == -1;
[email protected]6101c342010-12-16 22:44:372557 bool should_fork =
[email protected]744c2a22012-03-15 18:42:042558 content::GetContentClient()->HasWebUIScheme(url) ||
2559 (cumulative_bindings & content::BINDINGS_POLICY_WEB_UI) ||
2560 url.SchemeIs(chrome::kViewSourceScheme) ||
2561 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112562
[email protected]dc67e1c32012-06-08 00:10:402563 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
2564 // Fork non-file to file opens. Check the opener URL if this is the
2565 // initial navigation in a newly opened window.
2566 GURL source_url(old_url);
2567 if (is_initial_navigation && source_url.is_empty() && frame->opener())
2568 source_url = frame->opener()->top()->document().url();
2569 DCHECK(!source_url.is_empty());
2570 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
2571 }
2572
[email protected]e48869a2011-04-01 19:56:032573 if (!should_fork) {
2574 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042575 // For now, we skip this for POST submissions. This is because
2576 // http://crbug.com/101395 is more likely to cause compatibility issues
2577 // with hosted apps and extensions than WebUI pages. We will remove this
2578 // check when cross-process POST submissions are supported.
2579 if (request.httpMethod() == "GET") {
[email protected]744c2a22012-03-15 18:42:042580 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2581 frame, url, is_initial_navigation, &send_referrer);
2582 }
[email protected]6101c342010-12-16 22:44:372583 }
2584
2585 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152586 OpenURL(
2587 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112588 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2589 }
[email protected]3d9689372009-09-10 04:29:172590 }
2591
2592 // Detect when a page is "forking" a new tab that can be safely rendered in
2593 // its own process. This is done by sites like Gmail that try to open links
2594 // in new windows without script connections back to the original page. We
2595 // treat such cases as browser navigations (in which we will create a new
2596 // renderer for a cross-site navigation), rather than WebKit navigations.
2597 //
2598 // We use the following heuristic to decide whether to fork a new page in its
2599 // own process:
2600 // The parent page must open a new tab to about:blank, set the new tab's
2601 // window.opener to null, and then redirect the tab to a cross-site URL using
2602 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462603 //
2604 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2605 // (see below).
[email protected]3d9689372009-09-10 04:29:172606 bool is_fork =
2607 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582608 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172609 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522610 historyBackListCount() < 1 &&
2611 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172612 // The parent page must have set the child's window.opener to null before
2613 // redirecting to the desired URL.
2614 frame->opener() == NULL &&
2615 // Must be a top-level frame.
2616 frame->parent() == NULL &&
2617 // Must not have issued the request from this page.
2618 is_content_initiated &&
2619 // Must be targeted at the current tab.
2620 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2621 // Must be a JavaScript navigation, which appears as "other".
2622 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462623
[email protected]f92ce2b2012-03-06 18:02:592624 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172625 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152626 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172627 return WebKit::WebNavigationPolicyIgnore;
2628 }
2629
2630 return default_policy;
2631}
2632
[email protected]310ebd6302011-10-10 19:06:282633bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492634 WebFrame* frame, const WebURLRequest& request) {
2635 // We allow WebKit to think that everything can be handled even though
2636 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342637 return true;
2638}
2639
[email protected]310ebd6302011-10-10 19:06:282640WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492641 WebFrame* frame, const WebURLRequest& request) {
2642 NOTREACHED(); // Since we said we can handle all requests.
2643 return WebURLError();
2644}
2645
[email protected]310ebd6302011-10-10 19:06:282646WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492647 WebFrame* frame, const WebURLRequest& request) {
2648 WebURLError error;
2649 error.domain = WebString::fromUTF8(net::kErrorDomain);
2650 error.reason = net::ERR_ABORTED;
2651 error.unreachableURL = request.url();
2652 return error;
[email protected]7b7a7dc2009-10-19 02:23:342653}
2654
[email protected]310ebd6302011-10-10 19:06:282655void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492656 WebFrame*, const WebURLError&) {
2657 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342658}
2659
[email protected]310ebd6302011-10-10 19:06:282660void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432661 const WebKit::WebFormElement& form) {
2662 // Some login forms have onSubmit handlers that put a hash of the password
2663 // into a hidden field and then clear the password. (Issue 28910.)
2664 // This method gets called before any of those handlers run, so save away
2665 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072666 DocumentState* document_state =
2667 DocumentState::FromDataSource(frame->dataSource());
2668 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432669 PasswordFormDomManager::CreatePasswordForm(form));
2670}
2671
[email protected]310ebd6302011-10-10 19:06:282672void RenderViewImpl::willSubmitForm(WebFrame* frame,
2673 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072674 DocumentState* document_state =
2675 DocumentState::FromDataSource(frame->provisionalDataSource());
2676 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172677
[email protected]2905f742011-10-13 03:51:582678 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2679 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172680
2681 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352682 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072683 document_state->set_searchable_form_url(web_searchable_form_data.url());
2684 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212685 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432686 PasswordForm* password_form_data =
2687 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072688 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432689
[email protected]098c95cb2011-04-28 16:49:012690 // In order to save the password that the user actually typed and not one
2691 // that may have gotten transformed by the site prior to submit, recover it
2692 // from the form contents already stored by |willSendSubmitEvent| into the
2693 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2694 // which is what we're storing into now.)
2695 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072696 DocumentState* old_document_state =
2697 DocumentState::FromDataSource(frame->dataSource());
2698 if (old_document_state) {
2699 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432700 if (old_form_data && old_form_data->action == password_form_data->action)
2701 password_form_data->password_value = old_form_data->password_value;
2702 }
2703 }
[email protected]3d9689372009-09-10 04:29:172704
[email protected]2a5b1732011-04-01 23:55:552705 FOR_EACH_OBSERVER(
2706 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172707}
2708
[email protected]310ebd6302011-10-10 19:06:282709void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172710 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2711 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382712 FOR_EACH_OBSERVER(
2713 RenderViewObserver, observers_,
2714 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172715}
2716
[email protected]310ebd6302011-10-10 19:06:282717void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382718 FOR_EACH_OBSERVER(
2719 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172720}
2721
[email protected]310ebd6302011-10-10 19:06:282722void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172723 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152724 if (!frame->parent()) {
2725 WebDataSource* ds = frame->provisionalDataSource();
2726 // If there's no provisional data source, it's a reference fragment
2727 // navigation.
2728 completed_client_redirect_src_ = Referrer(
[email protected]ca662822012-05-11 17:53:592729 from, ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:042730 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:152731 }
[email protected]eb0bff942011-04-07 22:08:382732 FOR_EACH_OBSERVER(
2733 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172734}
2735
[email protected]310ebd6302011-10-10 19:06:282736void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572737 bool content_initiated = !pending_navigation_params_.get();
2738
[email protected]007733c2011-11-17 00:34:072739 DocumentState* document_state = DocumentState::FromDataSource(ds);
2740 if (!document_state) {
2741 document_state = new DocumentState;
2742 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572743 if (!content_initiated)
2744 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072745 }
2746
[email protected]3d9689372009-09-10 04:29:172747 // The rest of RenderView assumes that a WebDataSource will always have a
2748 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072749 if (content_initiated)
2750 document_state->set_navigation_state(
2751 NavigationState::CreateContentInitiated());
[email protected]45d83a12012-04-06 22:57:572752 else {
2753 document_state->set_navigation_state(CreateNavigationStateFromPending());
2754 pending_navigation_params_.reset();
2755 }
[email protected]8a3125a712010-08-09 18:58:512756
[email protected]007733c2011-11-17 00:34:072757 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512758 // navigating from a page that used prefetching using a link on that
2759 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072760 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512761 // this value appropriately.
2762 // TODO(gavinp): catch the important case of navigation in a new
2763 // renderer process.
2764 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302765 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522766 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512767 const GURL referrer(
2768 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2769 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072770 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512771 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:412772 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:512773 WebDataSource* old_frame_ds = old_frame->dataSource();
2774 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072775 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512776 break;
2777 }
2778 }
2779 }
2780 }
2781 }
2782
[email protected]4c1b6f0b2010-02-07 16:38:182783 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522784 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512785 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182786 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072787 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182788 break;
2789 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072790 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182791 break;
2792 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072793 document_state->set_load_type(
2794 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182795 break;
2796 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072797 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182798 break;
2799 }
2800 }
[email protected]fa7b6b542009-11-03 05:02:302801
[email protected]946a0032011-03-31 18:42:282802 FOR_EACH_OBSERVER(
2803 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172804}
2805
[email protected]45d83a12012-04-06 22:57:572806void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:072807 DocumentState* document_state) {
2808 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:572809 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:072810
[email protected]45d83a12012-04-06 22:57:572811 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
2812 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2813 // We're doing a load of a page that was restored from the last session. By
2814 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
2815 // can result in stale data for pages that are set to expire. We explicitly
2816 // override that by setting the policy here so that as necessary we load
2817 // from the network.
2818 document_state->set_cache_policy_override(
2819 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:072820 }
2821
2822 if (IsReload(params))
2823 document_state->set_load_type(DocumentState::RELOAD);
2824 else if (!params.state.empty())
2825 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2826 else
2827 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:592828
2829 document_state->set_referrer_policy(params.referrer.policy);
[email protected]45d83a12012-04-06 22:57:572830}
[email protected]007733c2011-11-17 00:34:072831
[email protected]45d83a12012-04-06 22:57:572832NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
2833 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2834 NavigationState* navigation_state = NULL;
2835
2836 // A navigation resulting from loading a javascript URL should not be treated
2837 // as a browser initiated event. Instead, we want it to look as if the page
2838 // initiated any load resulting from JS execution.
2839 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2840 navigation_state = NavigationState::CreateBrowserInitiated(
2841 params.page_id,
2842 params.pending_history_list_offset,
2843 params.transition);
2844 navigation_state->set_transferred_request_child_id(
2845 params.transferred_request_child_id);
2846 navigation_state->set_transferred_request_request_id(
2847 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:002848 navigation_state->set_allow_download(params.allow_download);
[email protected]45d83a12012-04-06 22:57:572849 } else {
2850 navigation_state = NavigationState::CreateContentInitiated();
2851 }
2852 return navigation_state;
[email protected]007733c2011-11-17 00:34:072853}
2854
[email protected]5b52cd2f712012-03-28 02:12:482855void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
2856 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:102857 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:482858 bool enable_fixed_layout =
2859 command_line.HasSwitch(switches::kEnableFixedLayout);
[email protected]4ef6104a2012-06-06 18:15:322860 bool enable_pinch = enable_viewport ||
2861 command_line.HasSwitch(switches::kEnablePinch);
[email protected]5b52cd2f712012-03-28 02:12:482862
2863 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
2864 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
[email protected]4ef6104a2012-06-06 18:15:322865 if (!enable_pinch &&
[email protected]60051ec2012-06-08 22:40:572866 webview()->isAcceleratedCompositingActive() &&
[email protected]4ef6104a2012-06-06 18:15:322867 webkit_preferences_.apply_default_device_scale_factor_in_compositor &&
[email protected]60051ec2012-06-08 22:40:572868 device_scale_factor_ != 1) {
[email protected]4ef6104a2012-06-06 18:15:322869 // Page scaling is disabled by default when applying a scale factor in the
2870 // compositor since they are currently incompatible.
2871 webview()->setPageScaleFactorLimits(1, 1);
2872 }
[email protected]5b52cd2f712012-03-28 02:12:482873
2874 if (enable_viewport) {
2875 webview()->settings()->setViewportEnabled(true);
2876 } else if (enable_fixed_layout) {
2877 std::string str =
2878 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
2879 std::vector<std::string> tokens;
2880 base::SplitString(str, ',', &tokens);
2881 if (tokens.size() == 2) {
2882 int width, height;
2883 if (base::StringToInt(tokens[0], &width) &&
2884 base::StringToInt(tokens[1], &height))
2885 webview()->setFixedLayoutSize(WebSize(width,height));
2886 }
2887 }
2888}
2889
[email protected]310ebd6302011-10-10 19:06:282890void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172891 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072892 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172893
[email protected]3d9689372009-09-10 04:29:172894 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072895 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172896 double event_time = ds->triggeringEventTime();
2897 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072898 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172899 }
2900
[email protected]05c8e502010-08-15 15:13:522901 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072902 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522903
[email protected]3d9689372009-09-10 04:29:172904 bool is_top_most = !frame->parent();
2905 if (is_top_most) {
2906 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132907 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172908
2909 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152910 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172911 } else if (frame->parent()->isLoading()) {
2912 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002913 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072914 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582915 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172916 }
2917
[email protected]28685da92011-02-07 21:49:172918 FOR_EACH_OBSERVER(
2919 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2920
[email protected]3d9689372009-09-10 04:29:172921 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592922 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262923 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172924}
2925
[email protected]400992b2012-06-14 00:03:542926void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2927 WebFrame* frame) {
2928 if (frame->parent())
2929 return;
2930 // Received a redirect on the main frame.
2931 WebDataSource* data_source = frame->provisionalDataSource();
2932 if (!data_source) {
2933 // Should only be invoked when we have a data source.
2934 NOTREACHED();
2935 return;
2936 }
2937 std::vector<GURL> redirects;
2938 GetRedirectChain(data_source, &redirects);
2939 if (redirects.size() >= 2) {
2940 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2941 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
2942 }
2943}
2944
[email protected]310ebd6302011-10-10 19:06:282945void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2946 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172947 // Notify the browser that we failed a provisional load with an error.
2948 //
2949 // Note: It is important this notification occur before DidStopLoading so the
2950 // SSL manager can react to the provisional load failure before being
2951 // notified the load stopped.
2952 //
2953 WebDataSource* ds = frame->provisionalDataSource();
2954 DCHECK(ds);
2955
2956 const WebURLRequest& failed_request = ds->request();
2957
[email protected]28685da92011-02-07 21:49:172958 FOR_EACH_OBSERVER(
2959 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2960
[email protected]3d9689372009-09-10 04:29:172961 bool show_repost_interstitial =
2962 (error.reason == net::ERR_CACHE_MISS &&
2963 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582964
2965 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2966 params.frame_id = frame->identifier();
2967 params.is_main_frame = !frame->parent();
2968 params.error_code = error.reason;
2969 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2970 failed_request,
2971 error,
2972 NULL,
2973 &params.error_description);
2974 params.url = error.unreachableURL;
2975 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172976 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582977 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172978
2979 // Don't display an error page if this is simply a cancelled load. Aside
2980 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2981 if (error.reason == net::ERR_ABORTED)
2982 return;
[email protected]b553edd52012-01-10 12:15:232983 // Don't display an error message if the request was handled by an
2984 // external protocol handler.
2985 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2986 return;
[email protected]3d9689372009-09-10 04:29:172987
2988 // Make sure we never show errors in view source mode.
2989 frame->enableViewSourceMode(false);
2990
[email protected]007733c2011-11-17 00:34:072991 DocumentState* document_state = DocumentState::FromDataSource(ds);
2992 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172993
2994 // If this is a failed back/forward/reload navigation, then we need to do a
2995 // 'replace' load. This is necessary to avoid messing up session history.
2996 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2997 // as session history is concerned.
2998 //
2999 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3000 // the page id.
3001 //
3002 bool replace =
3003 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:583004 navigation_state->transition_type() ==
3005 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:173006
3007 // If we failed on a browser initiated request, then make sure that our error
3008 // page load is regarded as the same browser initiated request.
3009 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073010 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3011 pending_navigation_params_->page_id =
3012 navigation_state->pending_page_id();
3013 pending_navigation_params_->pending_history_list_offset =
3014 navigation_state->pending_history_list_offset();
3015 pending_navigation_params_->transition =
3016 navigation_state->transition_type();
3017 pending_navigation_params_->request_time =
3018 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173019 }
3020
3021 // Provide the user with a more helpful error page?
3022 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3023 return;
3024
3025 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083026 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173027}
3028
[email protected]310ebd6302011-10-10 19:06:283029void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:173030 WebFrame* frame, const char* data, size_t data_len,
3031 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:073032 DocumentState* document_state =
3033 DocumentState::FromDataSource(frame->dataSource());
3034 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173035}
3036
[email protected]310ebd6302011-10-10 19:06:283037void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3038 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073039 DocumentState* document_state =
3040 DocumentState::FromDataSource(frame->dataSource());
3041 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173042
[email protected]007733c2011-11-17 00:34:073043 if (document_state->commit_load_time().is_null())
3044 document_state->set_commit_load_time(Time::Now());
3045
[email protected]3d9689372009-09-10 04:29:173046 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203047 // When we perform a new navigation, we need to update the last committed
3048 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173049 UpdateSessionHistory(frame);
3050
3051 // We bump our Page ID to correspond with the new session history entry.
3052 page_id_ = next_page_id_++;
3053
[email protected]285f4bb82012-04-17 15:57:283054 // Don't update history_page_ids_ (etc) for content::kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263055 // we don't want to forget the entry that was there, and since we will
[email protected]285f4bb82012-04-17 15:57:283056 // never come back to content::kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313057 // UpdateSessionHistory and update page_id_ even in this case, so that
3058 // the current entry gets a state update and so that we don't send a
3059 // state update to the wrong entry when we swap back in.
[email protected]285f4bb82012-04-17 15:57:283060 if (GetLoadingUrl(frame) != GURL(content::kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313061 // Advance our offset in session history, applying the length limit.
3062 // There is now no forward history.
3063 history_list_offset_++;
3064 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
3065 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
3066 history_list_length_ = history_list_offset_ + 1;
3067 history_page_ids_.resize(history_list_length_, -1);
3068 history_page_ids_[history_list_offset_] = page_id_;
3069 }
[email protected]3d9689372009-09-10 04:29:173070 } else {
3071 // Inspect the navigation_state on this frame to see if the navigation
3072 // corresponds to a session history navigation... Note: |frame| may or
3073 // may not be the toplevel frame, but for the case of capturing session
3074 // history, the first committed frame suffices. We keep track of whether
3075 // we've seen this commit before so that only capture session history once
3076 // per navigation.
3077 //
3078 // Note that we need to check if the page ID changed. In the case of a
3079 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3080 // previous URL and the current page ID, which would be wrong.
3081 if (navigation_state->pending_page_id() != -1 &&
3082 navigation_state->pending_page_id() != page_id_ &&
3083 !navigation_state->request_committed()) {
3084 // This is a successful session history navigation!
3085 UpdateSessionHistory(frame);
3086 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003087
3088 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033089
3090 // If the history list is valid, our list of page IDs should be correct.
3091 DCHECK(history_list_length_ <= 0 ||
3092 history_list_offset_ < 0 ||
3093 history_list_offset_ >= history_list_length_ ||
3094 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173095 }
3096 }
3097
[email protected]28685da92011-02-07 21:49:173098 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3099 DidCommitProvisionalLoad(frame, is_new_navigation));
3100
[email protected]3d9689372009-09-10 04:29:173101 // Remember that we've already processed this request, so we don't update
3102 // the session history again. We do this regardless of whether this is
3103 // a session history navigation, because if we attempted a session history
3104 // navigation without valid HistoryItem state, WebCore will think it is a
3105 // new navigation.
3106 navigation_state->set_request_committed(true);
3107
3108 UpdateURL(frame);
3109
3110 // If this committed load was initiated by a client redirect, we're
3111 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153112 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173113
3114 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273115 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173116}
3117
[email protected]310ebd6302011-10-10 19:06:283118void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103119 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3120 DidClearWindowObject(frame));
3121
[email protected]b6cb3a842011-06-24 18:28:413122 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:213123 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:253124 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3125 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273126 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173127 }
[email protected]766a7082012-02-03 23:39:153128
3129 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
3130 if (!dom_automation_controller_.get())
3131 dom_automation_controller_.reset(new DomAutomationController());
3132 dom_automation_controller_->set_message_sender(
3133 static_cast<content::RenderView*>(this));
3134 dom_automation_controller_->set_routing_id(routing_id());
3135 dom_automation_controller_->BindToJavascript(frame,
3136 "domAutomationController");
3137 }
[email protected]3d9689372009-09-10 04:29:173138}
3139
[email protected]310ebd6302011-10-10 19:06:283140void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173141 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:413142 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:253143 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:433144 if (frame == webview()->mainFrame())
3145 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173146 }
[email protected]e48869a2011-04-01 19:56:033147
3148 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3149 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173150}
3151
[email protected]310ebd6302011-10-10 19:06:283152void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3153 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463154 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173155
3156 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273157 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173158}
3159
[email protected]310ebd6302011-10-10 19:06:283160void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:133161 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3162 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:583163}
3164
[email protected]310ebd6302011-10-10 19:06:283165void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173166 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073167 DocumentState* document_state = DocumentState::FromDataSource(ds);
3168 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173169
[email protected]622474d2010-11-04 09:21:083170 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173171
[email protected]28685da92011-02-07 21:49:173172 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3173 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173174
3175 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273176 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173177}
3178
[email protected]310ebd6302011-10-10 19:06:283179void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083180 if (webview()->mainFrame() == frame) {
3181 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3182 page_id_));
3183 }
[email protected]3d9689372009-09-10 04:29:173184}
3185
[email protected]310ebd6302011-10-10 19:06:283186void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313187 WebDataSource* ds = frame->dataSource();
3188 DCHECK(ds);
3189
3190
[email protected]28685da92011-02-07 21:49:173191 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313192
3193 const WebURLRequest& failed_request = ds->request();
3194 string16 error_description;
3195 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
3196 failed_request,
3197 error,
3198 NULL,
3199 &error_description);
3200 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3201 frame->identifier(),
3202 failed_request.url(),
3203 !frame->parent(),
3204 error.reason,
3205 error_description));
[email protected]3d9689372009-09-10 04:29:173206}
3207
[email protected]310ebd6302011-10-10 19:06:283208void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173209 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073210 DocumentState* document_state = DocumentState::FromDataSource(ds);
3211 if (document_state->finish_load_time().is_null())
3212 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413213
[email protected]676126f72011-01-15 00:03:513214 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173215
[email protected]1a55c5be2011-11-29 11:36:313216 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3217 frame->identifier(),
3218 ds->request().url(),
3219 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173220}
3221
[email protected]310ebd6302011-10-10 19:06:283222void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173223 WebFrame* frame, bool is_new_navigation) {
3224 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073225 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173226 // update the ExtraData on the datasource so that others who read the
3227 // ExtraData will get the new NavigationState. Similarly, if we did not
3228 // initiate this navigation, then we need to take care to reset any pre-
3229 // existing navigation state to a content-initiated navigation state.
3230 // DidCreateDataSource conveniently takes care of this for us.
3231 didCreateDataSource(frame, frame->dataSource());
3232
[email protected]007733c2011-11-17 00:34:073233 DocumentState* document_state =
3234 DocumentState::FromDataSource(frame->dataSource());
3235 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093236 new_state->set_was_within_same_page(true);
3237
[email protected]3d9689372009-09-10 04:29:173238 didCommitProvisionalLoad(frame, is_new_navigation);
3239
[email protected]750fcf872011-08-03 23:10:473240 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3241 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173242}
3243
[email protected]310ebd6302011-10-10 19:06:283244void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313245 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593246}
3247
[email protected]310ebd6302011-10-10 19:06:283248void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173249 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3250 // Ignore
3251}
3252
[email protected]310ebd6302011-10-10 19:06:283253void RenderViewImpl::willSendRequest(WebFrame* frame,
3254 unsigned identifier,
3255 WebURLRequest& request,
3256 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303257 WebFrame* top_frame = frame->top();
3258 if (!top_frame)
3259 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513260 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3261 WebDataSource* top_data_source = top_frame->dataSource();
3262 WebDataSource* data_source =
3263 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223264
[email protected]78d5cfe2011-02-04 08:43:223265 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:033266 GURL new_url;
3267 if (content::GetContentClient()->renderer()->WillSendRequest(
[email protected]80744782012-05-04 01:47:003268 frame, request_url, &new_url)) {
[email protected]e48869a2011-04-01 19:56:033269 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:223270 }
3271
[email protected]2905f742011-10-13 03:51:583272 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073273 DocumentState* document_state = DocumentState::FromDataSource(data_source);
3274 NavigationState* navigation_state = document_state->navigation_state();
3275 if (document_state) {
3276 if (document_state->is_cache_policy_override_set())
3277 request.setCachePolicy(document_state->cache_policy_override());
3278 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:303279 }
[email protected]8a3125a712010-08-09 18:58:513280
[email protected]ca662822012-05-11 17:53:593281 WebKit::WebReferrerPolicy referrer_policy;
3282 if (document_state && document_state->is_referrer_policy_set()) {
3283 referrer_policy = document_state->referrer_policy();
3284 document_state->clear_referrer_policy();
3285 } else {
3286 referrer_policy = frame->document().referrerPolicy();
3287 }
3288
[email protected]91043a8232011-11-04 16:41:193289 request.setExtraData(
[email protected]ca662822012-05-11 17:53:593290 new RequestExtraData(referrer_policy,
[email protected]537fbe02011-11-24 00:58:063291 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193292 frame->identifier(),
3293 frame->parent() == top_frame,
3294 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]80744782012-05-04 01:47:003295 navigation_state->allow_download(),
[email protected]4ad5d77d2011-12-03 02:00:483296 transition_type,
3297 navigation_state->transferred_request_child_id(),
3298 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573299
[email protected]007733c2011-11-17 00:34:073300 DocumentState* top_document_state =
3301 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573302 // TODO(gavinp): separate out prefetching and prerender field trials
3303 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073304 if (top_document_state &&
[email protected]925dec1c2012-05-18 05:09:003305 request.targetType() == WebURLRequest::TargetIsPrefetch)
[email protected]007733c2011-11-17 00:34:073306 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513307
[email protected]3d9689372009-09-10 04:29:173308 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133309 request.setHasUserGesture(frame->isProcessingUserGesture());
3310
[email protected]0a8db0d2011-04-13 15:15:403311 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133312 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173313}
3314
[email protected]310ebd6302011-10-10 19:06:283315void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173316 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493317
[email protected]3d9689372009-09-10 04:29:173318 // Only do this for responses that correspond to a provisional data source
3319 // of the top-most frame. If we have a provisional data source, then we
3320 // can't have any sub-resources yet, so we know that this response must
3321 // correspond to a frame load.
3322 if (!frame->provisionalDataSource() || frame->parent())
3323 return;
3324
3325 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083326 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173327 if (frame->isViewSourceModeEnabled())
3328 return;
3329
[email protected]007733c2011-11-17 00:34:073330 DocumentState* document_state =
3331 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083332 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533333
[email protected]972ebdff2010-06-10 22:59:073334 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073335 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3336 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403337 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3338 if (extra_data) {
3339 document_state->set_npn_negotiated_protocol(
3340 extra_data->npn_negotiated_protocol());
3341 }
[email protected]007733c2011-11-17 00:34:073342 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573343 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073344 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3345 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093346 // Whether or not the http status code actually corresponds to an error is
3347 // only checked when the page is done loading, if |use_error_page| is
3348 // still true.
[email protected]007733c2011-11-17 00:34:073349 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173350}
3351
[email protected]310ebd6302011-10-10 19:06:283352void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173353 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073354 DocumentState* document_state =
3355 DocumentState::FromDataSource(frame->dataSource());
3356 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173357 return;
3358
[email protected]7bfc153f2011-09-23 22:00:203359 // Do not show error page when DevTools is attached.
3360 if (devtools_agent_->IsAttached())
3361 return;
3362
[email protected]06333afe2011-02-24 14:55:093363 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073364 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083365 if (http_status_code == 404) {
3366 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413367 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173368
[email protected]b6cb3a842011-06-24 18:28:413369 const GURL& error_page_url =
3370 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093371 if (error_page_url.is_valid()) {
3372 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473373 original_error.domain = "http";
3374 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413375 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173376
[email protected]007733c2011-11-17 00:34:073377 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093378 new AltErrorPageResourceFetcher(
3379 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083380 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3381 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093382 return;
3383 }
3384 }
[email protected]3d9689372009-09-10 04:29:173385
[email protected]e6a2ce52011-10-08 01:40:133386 std::string error_domain;
3387 if (content::GetContentClient()->renderer()->HasErrorPage(
3388 http_status_code, &error_domain)) {
3389 WebURLError error;
3390 error.unreachableURL = frame->document().url();
3391 error.domain = WebString::fromUTF8(error_domain);
3392 error.reason = http_status_code;
3393
3394 LoadNavigationErrorPage(
3395 frame, frame->dataSource()->request(), error, std::string(), true);
3396 }
[email protected]3d9689372009-09-10 04:29:173397}
3398
[email protected]310ebd6302011-10-10 19:06:283399void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173400 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3401 // Ignore
3402}
3403
[email protected]310ebd6302011-10-10 19:06:283404void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173405 WebFrame* frame, const WebURLRequest& request,
3406 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003407 // The recipients of this message have no use for data: URLs: they don't
3408 // affect the page's insecure content list and are not in the disk cache. To
3409 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3410 // filter them out here.
3411 GURL url(request.url());
3412 if (url.SchemeIs("data"))
3413 return;
3414
[email protected]3d9689372009-09-10 04:29:173415 // Let the browser know we loaded a resource from the memory cache. This
3416 // message is needed to display the correct SSL indicators.
3417 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3418 routing_id_,
[email protected]84703292011-10-28 20:44:003419 url,
[email protected]70435962011-08-02 20:13:283420 response.securityInfo(),
3421 request.httpMethod().utf8(),
[email protected]6d6cfb3a2012-05-23 22:53:183422 response.mimeType().utf8(),
[email protected]70435962011-08-02 20:13:283423 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173424}
3425
[email protected]310ebd6302011-10-10 19:06:283426void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293427 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3428}
3429
[email protected]310ebd6302011-10-10 19:06:283430void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023431 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293432 Send(new ViewHostMsg_DidRunInsecureContent(
3433 routing_id_,
[email protected]92771112011-01-20 00:13:023434 origin.toString().utf8(),
3435 target));
[email protected]e3d60e5d2009-09-25 21:08:293436}
3437
[email protected]310ebd6302011-10-10 19:06:283438void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173439 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3440}
3441
[email protected]310ebd6302011-10-10 19:06:283442void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3443 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583444 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283445 int world_id) {
[email protected]5bc10932011-09-21 21:03:303446 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583447 frame, context, extension_group, world_id);
3448}
3449
3450void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3451 v8::Handle<v8::Context> context,
3452 int world_id) {
3453 content::GetContentClient()->renderer()->DidCreateScriptContext(
3454 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283455}
3456
[email protected]310ebd6302011-10-10 19:06:283457void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3458 v8::Handle<v8::Context> context,
3459 int world_id) {
[email protected]5bc10932011-09-21 21:03:303460 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3461 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283462}
3463
[email protected]310ebd6302011-10-10 19:06:283464void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073465 // We don't always want to send the change messages over IPC, only if we've
3466 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3467 // message.
3468 if (!send_preferred_size_changes_ || !webview())
3469 return;
3470
[email protected]705243f2010-05-05 19:58:073471 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3472 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533473
3474 // In the presence of zoom, these sizes are still reported as if unzoomed,
3475 // so we need to adjust.
3476 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3477 size.set_width(static_cast<int>(size.width() * zoom_factor));
3478 size.set_height(static_cast<int>(size.height() * zoom_factor));
3479
[email protected]705243f2010-05-05 19:58:073480 if (size == preferred_size_)
3481 return;
[email protected]c27324b2009-11-19 22:44:293482
[email protected]705243f2010-05-05 19:58:073483 preferred_size_ = size;
3484 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3485 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173486}
3487
[email protected]273558fb2012-01-12 15:03:513488void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]7082fb942012-05-16 23:44:593489 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:403490 return;
3491
[email protected]4fb0f202012-05-30 22:44:533492#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513493 if (!p2p_socket_dispatcher_)
3494 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]273558fb2012-01-12 15:03:513495
3496 if (!media_stream_dispatcher_)
3497 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3498
[email protected]1bc65a42012-04-23 09:31:253499 if (!media_stream_impl_) {
[email protected]f3625c0b2012-05-03 09:18:283500 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory(
3501 RenderThreadImpl::current()->video_capture_impl_manager());
[email protected]273558fb2012-01-12 15:03:513502 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253503 this,
[email protected]273558fb2012-01-12 15:03:513504 media_stream_dispatcher_,
3505 p2p_socket_dispatcher_,
3506 RenderThreadImpl::current()->video_capture_impl_manager(),
3507 factory);
3508 }
[email protected]5b87e782012-02-09 18:19:323509#endif
[email protected]273558fb2012-01-12 15:03:513510}
3511
[email protected]310ebd6302011-10-10 19:06:283512void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3513 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313514 if (webview()->mainFrame() != frame)
3515 return;
3516 WebView* frameView = frame->view();
3517 if (!frameView)
3518 return;
3519
3520 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3521 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3522
3523 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3524 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3525 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3526 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3527
3528 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3529 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3530 }
3531}
3532
[email protected]310ebd6302011-10-10 19:06:283533void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313534 WebSize offset = frame->scrollOffset();
3535 WebSize minimum_offset = frame->minimumScrollOffset();
3536 WebSize maximum_offset = frame->maximumScrollOffset();
3537
3538 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3539 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3540
3541 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3542 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3543 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3544 routing_id_, is_pinned_to_left, is_pinned_to_right));
3545
3546 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3547 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3548 }
3549}
3550
[email protected]310ebd6302011-10-10 19:06:283551void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493552 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313553
3554 if (webview()->mainFrame() == frame)
3555 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:263556
3557 FOR_EACH_OBSERVER(
3558 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:313559}
3560
[email protected]310ebd6302011-10-10 19:06:283561void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313562 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493563}
3564
[email protected]ea931252012-02-15 22:01:033565void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3566 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3567}
3568
[email protected]310ebd6302011-10-10 19:06:283569void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3570 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113571 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3572 if (!count)
3573 active_match_ordinal = 0;
3574
3575 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3576 routing_id_,
3577 request_id,
3578 count,
3579 gfx::Rect(),
3580 active_match_ordinal,
3581 final_update);
3582
[email protected]8922e1f2009-10-03 05:01:263583 // If we have a message that has been queued up, then we should just replace
3584 // it. The ACK from the browser will make sure it gets sent when the browser
3585 // wants it.
3586 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263587 queued_find_reply_message_.reset(msg);
3588 } else {
3589 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113590 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263591 }
3592}
3593
[email protected]310ebd6302011-10-10 19:06:283594void RenderViewImpl::reportFindInPageSelection(int request_id,
3595 int active_match_ordinal,
3596 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263597 // Send the search result over to the browser process.
3598 Send(new ViewHostMsg_Find_Reply(routing_id_,
3599 request_id,
3600 -1,
3601 selection_rect,
3602 active_match_ordinal,
3603 false));
3604}
3605
[email protected]310ebd6302011-10-10 19:06:283606void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223607 WebFrame* frame,
3608 WebFileSystem::Type type,
3609 long long size,
[email protected]d275d7a2010-11-03 01:34:493610 bool create,
[email protected]2b06a992010-08-21 05:48:223611 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083612 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223613
[email protected]b6cb3a842011-06-24 18:28:413614 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563615 if (origin.isUnique()) {
3616 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083617 callbacks->didFail(WebKit::WebFileErrorAbort);
3618 return;
3619 }
[email protected]2b06a992010-08-21 05:48:223620
[email protected]c5a272d2010-09-27 18:37:083621 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3622 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493623 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223624}
3625
[email protected]310ebd6302011-10-10 19:06:283626void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403627 WebFrame* frame,
3628 WebStorageQuotaType type,
3629 WebStorageQuotaCallbacks* callbacks) {
3630 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413631 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563632 if (origin.isUnique()) {
3633 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403634 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3635 return;
3636 }
3637 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533638 GURL(origin.toString()),
3639 static_cast<quota::StorageType>(type),
3640 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403641}
3642
[email protected]310ebd6302011-10-10 19:06:283643void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403644 WebFrame* frame,
3645 WebStorageQuotaType type,
3646 unsigned long long requested_size,
3647 WebStorageQuotaCallbacks* callbacks) {
3648 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413649 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563650 if (origin.isUnique()) {
3651 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403652 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3653 return;
3654 }
3655 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533656 routing_id(), GURL(origin.toString()),
3657 static_cast<quota::StorageType>(type), requested_size,
3658 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403659}
3660
[email protected]8b5af492011-11-28 21:50:583661void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153662 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]3a3b75a2012-06-01 08:38:363663 webkit_glue::WebIntentServiceData data(service);
3664 if (data.title.empty())
3665 data.title = webview()->mainFrame()->document().title();
3666 bool user_gesture = frame->isProcessingUserGesture();
[email protected]8b5af492011-11-28 21:50:583667 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
[email protected]3a3b75a2012-06-01 08:38:363668 data,
3669 user_gesture));
[email protected]8b5af492011-11-28 21:50:583670}
3671
[email protected]ffc8bed2012-01-21 01:23:153672void RenderViewImpl::dispatchIntent(
3673 WebFrame* frame, const WebIntentRequest& intentRequest) {
3674 webkit_glue::WebIntentData intent_data(intentRequest.intent());
[email protected]4e1eb3392012-05-18 00:08:053675
3676 // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued()
3677 WebKit::WebMessagePortChannelArray* channels =
3678 intentRequest.intent().messagePortChannelsRelease();
3679 if (channels) {
3680 for (size_t i = 0; i < channels->size(); ++i) {
3681 WebMessagePortChannelImpl* webchannel =
3682 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
3683 intent_data.message_port_ids.push_back(webchannel->message_port_id());
3684 DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE);
3685 }
3686 delete channels;
3687 }
3688
[email protected]ffc8bed2012-01-21 01:23:153689 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583690 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153691 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583692}
3693
[email protected]f546640b2012-05-15 00:03:493694bool RenderViewImpl::willCheckAndDispatchMessageEvent(
3695 WebKit::WebFrame* source,
3696 WebKit::WebSecurityOrigin target_origin,
3697 WebKit::WebDOMMessageEvent event) {
3698 if (!is_swapped_out_)
3699 return false;
3700
3701 ViewMsg_PostMessage_Params params;
3702 params.data = event.data().toString();
3703 params.source_origin = event.origin();
3704 if (!target_origin.isNull())
3705 params.target_origin = target_origin.toString();
3706
3707 // Include the routing ID for the source frame, which the browser process
3708 // will translate into the routing ID for the equivalent frame in the target
3709 // process.
3710 // TODO(creis): Support source subframes.
3711 params.source_routing_id = MSG_ROUTING_NONE;
3712 RenderViewImpl* source_view = FromWebView(source->view());
3713 if (source_view)
3714 params.source_routing_id = source_view->routing_id();
3715
3716 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
3717 return true;
3718}
3719
[email protected]5fa3a062012-03-21 15:39:343720void RenderViewImpl::willOpenSocketStream(
3721 WebSocketStreamHandle* handle) {
3722 SocketStreamHandleData::AddToHandle(handle, routing_id_);
3723}
3724
[email protected]18d5be92011-07-25 18:00:193725// WebKit::WebPageSerializerClient implementation ------------------------------
3726
[email protected]310ebd6302011-10-10 19:06:283727void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193728 const WebURL& frame_url,
3729 const WebCString& data,
3730 WebPageSerializerClient::PageSerializationStatus status) {
3731 Send(new ViewHostMsg_SendSerializedHtmlData(
3732 routing_id(),
3733 frame_url,
3734 data.data(),
3735 static_cast<int32>(status)));
3736}
3737
[email protected]a2ef54c2011-10-10 16:20:313738// content::RenderView implementation ------------------------------------------
3739
[email protected]310ebd6302011-10-10 19:06:283740bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313741 return RenderWidget::Send(message);
3742}
3743
[email protected]82114f52012-03-20 22:53:413744int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:313745 return routing_id_;
3746}
3747
[email protected]82114f52012-03-20 22:53:413748int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:313749 return page_id_;
3750}
3751
[email protected]82114f52012-03-20 22:53:413752gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:313753 return size();
3754}
3755
[email protected]82114f52012-03-20 22:53:413756WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313757 return webkit_preferences_;
3758}
3759
[email protected]82114f52012-03-20 22:53:413760WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313761 return webview();
3762}
3763
[email protected]82114f52012-03-20 22:53:413764WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313765 if (!webview())
3766 return WebNode();
3767 WebFrame* focused_frame = webview()->focusedFrame();
3768 if (focused_frame) {
3769 WebDocument doc = focused_frame->document();
3770 if (!doc.isNull())
3771 return doc.focusedNode();
3772 }
3773
3774 return WebNode();
3775}
3776
[email protected]82114f52012-03-20 22:53:413777WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313778 return context_menu_node_;
3779}
3780
[email protected]2a84f9d2012-06-05 21:50:433781bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
3782 if (node.isNull())
3783 return false;
3784
3785 if (node.isContentEditable())
3786 return true;
3787
3788 if (node.isElementNode()) {
3789 const WebElement& element = node.toConst<WebElement>();
3790 if (element.isTextFormControlElement())
3791 return true;
3792
3793 // Also return true if it has an ARIA role of 'textbox'.
3794 for (unsigned i = 0; i < element.attributeCount(); ++i) {
3795 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
3796 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
3797 return true;
3798 break;
3799 }
[email protected]a2ef54c2011-10-10 16:20:313800 }
3801 }
[email protected]2a84f9d2012-06-05 21:50:433802
3803 return false;
[email protected]a2ef54c2011-10-10 16:20:313804}
3805
[email protected]468e4902012-05-23 01:49:313806void RenderViewImpl::GuestReady(PP_Instance instance) {
3807 guest_pp_instance_ = instance;
3808 if (guest_uninitialized_context_) {
[email protected]7900bfdb2012-05-24 19:31:243809 bool success = GetGuestToEmbedderChannel()->CreateGraphicsContext(
[email protected]468e4902012-05-23 01:49:313810 guest_uninitialized_context_,
3811 guest_attributes_,
3812 false,
3813 this);
3814 DCHECK(success);
[email protected]7900bfdb2012-05-24 19:31:243815 CompleteInit(host_window_);
3816 guest_uninitialized_context_ = NULL;
[email protected]468e4902012-05-23 01:49:313817 }
[email protected]468e4902012-05-23 01:49:313818}
3819
3820webkit::ppapi::WebPluginImpl* RenderViewImpl::CreateBrowserPlugin(
3821 const IPC::ChannelHandle& channel_handle,
3822 int guest_process_id,
3823 const WebKit::WebPluginParams& params) {
3824 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3825 pepper_delegate_.CreateBrowserPluginModule(channel_handle,
3826 guest_process_id));
3827 return new webkit::ppapi::WebPluginImpl(
3828 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3829}
3830
[email protected]310ebd6302011-10-10 19:06:283831WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313832 WebKit::WebFrame* frame,
3833 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:413834 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:313835 bool pepper_plugin_was_registered = false;
3836 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3837 pepper_delegate_.CreatePepperPluginModule(info,
3838 &pepper_plugin_was_registered));
3839 if (pepper_plugin_was_registered) {
3840 if (!pepper_module)
3841 return NULL;
3842 return new webkit::ppapi::WebPluginImpl(
3843 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3844 }
3845
[email protected]34b27e442012-01-20 20:07:413846#if defined(USE_AURA)
3847 return NULL;
3848#else
[email protected]a2ef54c2011-10-10 16:20:313849 return new webkit::npapi::WebPluginImpl(
3850 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413851#endif
[email protected]a2ef54c2011-10-10 16:20:313852}
3853
[email protected]310ebd6302011-10-10 19:06:283854void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3855 const string16& jscript,
3856 int id,
3857 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313858 v8::Handle<v8::Value> result;
3859 WebFrame* web_frame = GetChildFrame(frame_xpath);
3860 if (web_frame)
3861 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3862 if (notify_result) {
3863 ListValue list;
3864 if (!result.IsEmpty() && web_frame) {
3865 v8::HandleScope handle_scope;
3866 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3867 v8::Context::Scope context_scope(context);
3868 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:513869 converter.SetDateAllowed(true);
3870 converter.SetRegexpAllowed(true);
[email protected]a2ef54c2011-10-10 16:20:313871 list.Set(0, converter.FromV8Value(result, context));
3872 } else {
3873 list.Set(0, Value::CreateNullValue());
3874 }
3875 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3876 }
3877}
3878
[email protected]310ebd6302011-10-10 19:06:283879bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313880 return (!send_preferred_size_changes_ ||
3881 (disable_scrollbars_size_limit_.width() <= width ||
3882 disable_scrollbars_size_limit_.height() <= height));
3883}
3884
[email protected]82114f52012-03-20 22:53:413885int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:313886 return enabled_bindings_;
3887}
3888
[email protected]82114f52012-03-20 22:53:413889bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:313890 return send_content_state_immediately_;
3891}
3892
[email protected]82114f52012-03-20 22:53:413893float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:313894 return filtered_time_per_frame();
3895}
3896
[email protected]310ebd6302011-10-10 19:06:283897void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
[email protected]82114f52012-03-20 22:53:413898 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313899 showContextMenu(frame, data);
3900}
3901
[email protected]82114f52012-03-20 22:53:413902WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313903 return visibilityState();
3904}
3905
[email protected]310ebd6302011-10-10 19:06:283906void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3907 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313908 return runModalAlertDialog(frame, message);
3909}
3910
[email protected]310ebd6302011-10-10 19:06:283911void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313912 WebKit::WebFrame* frame,
3913 const WebKit::WebURLRequest& request,
3914 WebKit::WebNavigationPolicy policy) {
3915 loadURLExternally(frame, request, policy);
3916}
3917
3918// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513919
[email protected]310ebd6302011-10-10 19:06:283920webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533921 const FilePath& file_path,
3922 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203923 if (!PluginChannelHost::IsListening()) {
3924 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593925 return NULL;
[email protected]94752ee2012-02-10 10:38:203926 }
[email protected]f103ab72009-09-02 17:10:593927
[email protected]00c39612010-03-06 02:53:283928 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463929 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323930#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223931 return webkit::npapi::WebPluginDelegateImpl::Create(
3932 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093933#else
[email protected]7398dcc2011-09-06 21:40:323934 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223935 NOTIMPLEMENTED();
3936 return NULL;
[email protected]7b6616f2010-01-14 18:07:553937#endif
[email protected]f103ab72009-09-02 17:10:593938 }
3939
[email protected]4e0616e2010-05-28 14:55:533940 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593941}
3942
[email protected]6ac77cb2012-05-01 14:49:013943WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
3944 const FilePath& file_path) {
3945 return content::GetContentClient()->renderer()->CreatePluginReplacement(
3946 this, file_path);
3947}
3948
[email protected]310ebd6302011-10-10 19:06:283949void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033950#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273951 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593952#endif
3953}
3954
[email protected]310ebd6302011-10-10 19:06:283955void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033956#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273957 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593958#endif
3959 CleanupWindowInPluginMoves(window);
3960}
3961
[email protected]310ebd6302011-10-10 19:06:283962void RenderViewImpl::DidMovePlugin(
3963 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593964 SchedulePluginMove(move);
3965}
3966
[email protected]310ebd6302011-10-10 19:06:283967void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593968 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523969 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593970}
3971
[email protected]310ebd6302011-10-10 19:06:283972void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593973 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523974 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593975}
3976
[email protected]310ebd6302011-10-10 19:06:283977WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513978 return &cookie_jar_;
3979}
3980
[email protected]5d65fe92012-06-02 00:48:553981void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:073982 Send(new ViewHostMsg_MediaNotification(routing_id_,
3983 reinterpret_cast<int64>(player),
3984 player->hasVideo(),
3985 player->hasAudio(),
3986 true));
3987}
3988
[email protected]5d65fe92012-06-02 00:48:553989void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:073990 Send(new ViewHostMsg_MediaNotification(routing_id_,
3991 reinterpret_cast<int64>(player),
3992 player->hasVideo(),
3993 player->hasAudio(),
3994 false));
3995}
3996
[email protected]5d65fe92012-06-02 00:48:553997void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:073998 DidPause(player);
3999}
4000
[email protected]310ebd6302011-10-10 19:06:284001void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294002 if (!webview())
4003 return;
4004
[email protected]26aa0482009-09-30 16:55:274005 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054006 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294007}
4008
[email protected]310ebd6302011-10-10 19:06:284009void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364010 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004011 if (!frame)
4012 return;
[email protected]b781ff282011-08-20 06:19:364013
[email protected]e99ef6f2011-10-16 01:13:004014 string16 text;
4015 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:524016 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:004017
[email protected]3c8c74c2012-03-15 07:34:524018 if (pepper_delegate_.IsPluginFocused()) {
4019 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414020 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524021 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:004022 } else {
[email protected]3c8c74c2012-03-15 07:34:524023 size_t location, length;
4024 if (!webview()->caretOrSelectionRange(&location, &length))
4025 return;
4026
4027 range = ui::Range(location, location + length);
4028
4029 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
4030 // If current focused element is editable, we will send 100 more chars
4031 // before and after selection. It is for input method surrounding text
4032 // feature.
4033 if (location > kExtraCharsBeforeAndAfterSelection)
4034 offset = location - kExtraCharsBeforeAndAfterSelection;
4035 else
4036 offset = 0;
4037 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4038 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4039 if (!webrange.isNull())
4040 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4041 } else {
4042 offset = location;
4043 text = frame->selectionAsText();
4044 // http://crbug.com/101435
4045 // In some case, frame->selectionAsText() returned text's length is not
4046 // equal to the length returned from webview()->caretOrSelectionRange().
4047 // So we have to set the range according to text.length().
4048 range.set_end(range.start() + text.length());
4049 }
[email protected]b781ff282011-08-20 06:19:364050 }
4051
[email protected]b781ff282011-08-20 06:19:364052 // Sometimes we get repeated didChangeSelection calls from webkit when
4053 // the selection hasn't actually changed. We don't want to report these
4054 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004055 if (selection_text_offset_ != offset ||
4056 selection_range_ != range ||
4057 selection_text_ != text) {
4058 selection_text_ = text;
4059 selection_text_offset_ = offset;
4060 selection_range_ = range;
4061 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4062 }
[email protected]b781ff282011-08-20 06:19:364063}
4064
[email protected]310ebd6302011-10-10 19:06:284065GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4066 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554067 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294068 // If the URL that failed was secure, then the embedding web page was not
4069 // expecting a network attacker to be able to manipulate its contents. As
4070 // we fetch alternate error pages over HTTP, we would be allowing a network
4071 // attacker to manipulate the contents of the response if we tried to use
4072 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154073 return GURL();
initial.commit09911bf2008-07-26 23:55:294074 }
4075
4076 // Grab the base URL from the browser process.
4077 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154078 return GURL();
initial.commit09911bf2008-07-26 23:55:294079
4080 // Strip query params from the failed URL.
4081 GURL::Replacements remove_params;
4082 remove_params.ClearUsername();
4083 remove_params.ClearPassword();
4084 remove_params.ClearQuery();
4085 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554086 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504087 std::string spec_to_send = url_to_send.spec();
4088 // Notify link doctor of the url truncation by sending of "?" at the end.
4089 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414090 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294091
4092 // Construct the query params to send to link doctor.
4093 std::string params(alternate_error_page_url_.query());
4094 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024095 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294096 params.append("&sourceid=chrome");
4097 params.append("&error=");
4098 switch (error_type) {
4099 case DNS_ERROR:
4100 params.append("dnserror");
4101 break;
4102
4103 case HTTP_404:
4104 params.append("http404");
4105 break;
4106
[email protected]5df266ac2008-10-15 19:50:134107 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334108 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134109 break;
4110
initial.commit09911bf2008-07-26 23:55:294111 default:
4112 NOTREACHED() << "unknown ErrorPageType";
4113 }
4114
4115 // OK, build the final url to return.
4116 GURL::Replacements link_doctor_params;
4117 link_doctor_params.SetQueryStr(params);
4118 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4119 return url;
4120}
4121
[email protected]310ebd6302011-10-10 19:06:284122GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:594123 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
4124 return GURL();
4125 else
4126 return creator_url_;
4127}
4128
[email protected]69ddf852012-02-21 23:21:314129GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4130 WebDataSource* ds = frame->dataSource();
4131 if (ds->hasUnreachableURL())
4132 return ds->unreachableURL();
4133
4134 const WebURLRequest& request = ds->request();
4135 return request.url();
4136}
4137
[email protected]310ebd6302011-10-10 19:06:284138WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:274139 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:314140 web_ui_bindings_.reset(new WebUIBindings(
4141 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:464142 }
[email protected]c50008512011-02-03 01:17:274143 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464144}
4145
[email protected]310ebd6302011-10-10 19:06:284146WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014147 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494148}
4149
[email protected]310ebd6302011-10-10 19:06:284150void RenderViewImpl::OnFind(int request_id, const string16& search_text,
4151 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274152 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494153
[email protected]872542532011-06-23 00:43:164154 // Check if the plugin still exists in the document.
4155 if (main_frame->document().isPluginDocument() &&
4156 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494157 if (options.findNext) {
4158 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014159 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494160 } else {
[email protected]afdbd142010-07-10 08:01:234161 if (GetWebPluginFromPluginDocument()->startFind(
4162 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494163 } else {
[email protected]e7c58a32010-08-13 19:47:114164 // Send "no results".
4165 Send(new ViewHostMsg_Find_Reply(routing_id_,
4166 request_id,
4167 0,
4168 gfx::Rect(),
4169 0,
4170 true));
[email protected]24a7f3c2010-03-25 08:26:494171 }
4172 }
4173 return;
4174 }
4175
[email protected]b4bb2502009-10-01 22:35:274176 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274177 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294178 WebFrame* search_frame = focused_frame; // start searching focused frame.
4179
4180 bool multi_frame = (frame_after_main != main_frame);
4181
4182 // If we have multiple frames, we don't want to wrap the search within the
4183 // frame, so we check here if we only have main_frame in the chain.
4184 bool wrap_within_frame = !multi_frame;
4185
[email protected]b3f2b912009-04-09 16:18:524186 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294187 bool result = false;
4188
[email protected]7830da3e2009-11-06 16:27:264189 // If something is selected when we start searching it means we cannot just
4190 // increment the current match ordinal; we need to re-generate it.
4191 WebRange current_selection = focused_frame->selectionRange();
4192
initial.commit09911bf2008-07-26 23:55:294193 do {
[email protected]dd7daa82009-08-10 05:46:454194 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594195 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294196
4197 if (!result) {
4198 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224199 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294200
4201 // Find the next frame, but skip the invisible ones.
4202 do {
4203 // What is the next frame to search? (we might be going backwards). Note
4204 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594205 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274206 search_frame->traverseNext(true) :
4207 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454208 } while (!search_frame->hasVisibleContent() &&
4209 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294210
[email protected]884db412008-11-24 23:46:504211 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224212 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294213
4214 // If we have multiple frames and we have wrapped back around to the
4215 // focused frame, we need to search it once more allowing wrap within
4216 // the frame, otherwise it will report 'no match' if the focused frame has
4217 // reported matches, but no frames after the focused_frame contain a
4218 // match for the search word(s).
4219 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454220 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594221 request_id, search_text, options, true, // Force wrapping.
4222 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294223 }
4224 }
4225
[email protected]26aa0482009-09-30 16:55:274226 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294227 } while (!result && search_frame != focused_frame);
4228
[email protected]7830da3e2009-11-06 16:27:264229 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294230 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454231 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294232 } else {
4233 // If nothing is found, set result to "0 of 0", otherwise, set it to
4234 // "-1 of 1" to indicate that we found at least one item, but we don't know
4235 // yet what is active.
4236 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4237 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294238
[email protected]4f3dc372009-02-24 00:10:294239 // If we find no matches then this will be our last status update.
4240 // Otherwise the scoping effort will send more results.
4241 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294242
[email protected]4f3dc372009-02-24 00:10:294243 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404244 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594245 request_id,
[email protected]4f3dc372009-02-24 00:10:294246 match_count,
4247 selection_rect,
4248 ordinal,
4249 final_status_update));
initial.commit09911bf2008-07-26 23:55:294250
initial.commit09911bf2008-07-26 23:55:294251 // Scoping effort begins, starting with the mainframe.
4252 search_frame = main_frame;
4253
[email protected]dd7daa82009-08-10 05:46:454254 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294255
4256 do {
4257 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454258 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294259
4260 // We don't start another scoping effort unless at least one match has
4261 // been found.
4262 if (result) {
4263 // Start new scoping request. If the scoping function determines that it
4264 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454265 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594266 search_text,
4267 options,
initial.commit09911bf2008-07-26 23:55:294268 true); // reset the tickmarks
4269 }
4270
4271 // Iterate to the next frame. The frame will not necessarily scope, for
4272 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274273 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294274 } while (search_frame != main_frame);
4275 }
4276}
4277
[email protected]815dd9872011-11-23 18:40:304278void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494279 WebView* view = webview();
4280 if (!view)
4281 return;
4282
4283 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164284 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014285 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494286 return;
4287 }
4288
[email protected]815dd9872011-11-23 18:40:304289 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494290 if (clear_selection)
4291 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4292
4293 WebFrame* frame = view->mainFrame();
4294 while (frame) {
4295 frame->stopFinding(clear_selection);
4296 frame = frame->traverseNext(false);
4297 }
4298
[email protected]815dd9872011-11-23 18:40:304299 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494300 WebFrame* focused_frame = view->focusedFrame();
4301 if (focused_frame) {
4302 WebDocument doc = focused_frame->document();
4303 if (!doc.isNull()) {
4304 WebNode node = doc.focusedNode();
4305 if (!node.isNull())
4306 node.simulateClick();
4307 }
4308 }
4309 }
4310}
4311
[email protected]310ebd6302011-10-10 19:06:284312void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:494313 // Check if there is any queued up request waiting to be sent.
4314 if (queued_find_reply_message_.get()) {
4315 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424316 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494317 }
4318}
4319
[email protected]54087fe2011-10-28 22:02:484320void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514321 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4322 return;
4323
[email protected]258d31122010-05-09 10:59:414324 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104325
[email protected]b75b8292010-10-01 07:28:254326 double old_zoom_level = webview()->zoomLevel();
4327 double zoom_level;
[email protected]54087fe2011-10-28 22:02:484328 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254329 zoom_level = 0;
4330 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4331 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484332 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254333 } else {
4334 // Either the user hit the zoom factor limit and thus the zoom level is now
4335 // not a whole number, or a plugin changed it to a custom value. We want
4336 // to go to the next whole number so that the user can always get back to
4337 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484338 if ((old_zoom_level > 1 && zoom > 0) ||
4339 (old_zoom_level < 1 && zoom < 0)) {
4340 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254341 } else {
4342 // We're going towards 100%, so first go to the next whole number.
4343 zoom_level = static_cast<int>(old_zoom_level);
4344 }
4345 }
[email protected]b75b8292010-10-01 07:28:254346 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414347 zoomLevelChanged();
4348}
4349
4350void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
4351 int zoom_center_x, int zoom_center_y) {
4352 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4353 kScalingIncrementForGesture);
4354}
4355
4356void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
4357 int zoom_center_x,
4358 int zoom_center_y,
4359 float scaling_increment) {
4360 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4361 return;
4362
[email protected]c514d6372011-08-16 22:54:444363 double old_page_scale_factor = webview()->pageScaleFactor();
4364 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:484365 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444366 page_scale_factor = 1.0;
4367 } else {
4368 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414369 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444370 }
[email protected]47578fa02011-11-02 19:34:414371 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094372 webview()->setPageScaleFactor(page_scale_factor,
4373 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414374 }
[email protected]40bd6582009-12-04 23:49:514375}
4376
[email protected]310ebd6302011-10-10 19:06:284377void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174378 webview()->hidePopups();
4379 webview()->setZoomLevel(false, zoom_level);
4380 zoomLevelChanged();
4381}
4382
[email protected]310ebd6302011-10-10 19:06:284383void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4384 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544385 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294386}
4387
[email protected]310ebd6302011-10-10 19:06:284388void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274389 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294390}
4391
[email protected]310ebd6302011-10-10 19:06:284392void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274393 WebString no_encoding;
4394 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184395}
4396
[email protected]310ebd6302011-10-10 19:06:284397WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454398 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274399 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454400
4401 // xpath string can represent a frame deep down the tree (across multiple
4402 // frame DOMs).
4403 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4404 // should break into 2 xpaths
4405 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414406 std::vector<string16> xpaths;
4407 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454408
[email protected]26aa0482009-09-30 16:55:274409 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414410 for (std::vector<string16>::const_iterator i = xpaths.begin();
4411 frame && i != xpaths.end(); ++i) {
4412 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294413 }
4414
[email protected]dd7daa82009-08-10 05:46:454415 return frame;
initial.commit09911bf2008-07-26 23:55:294416}
4417
[email protected]310ebd6302011-10-10 19:06:284418void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4419 const string16& jscript,
4420 int id,
4421 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:534422 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294423}
4424
[email protected]f546640b2012-05-15 00:03:494425void RenderViewImpl::OnPostMessageEvent(
4426 const ViewMsg_PostMessage_Params& params) {
4427 // TODO(creis): Support sending to subframes.
4428 WebFrame *frame = webview()->mainFrame();
4429
4430 // Find the source frame if it exists.
4431 // TODO(creis): Support source subframes.
4432 WebFrame* source_frame = NULL;
4433 if (params.source_routing_id != MSG_ROUTING_NONE) {
4434 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
4435 if (source_view)
4436 source_frame = source_view->webview()->mainFrame();
4437 }
4438
4439 // Create an event with the message. The final parameter to initMessageEvent
4440 // is the last event ID, which is not used with postMessage.
4441 WebDOMEvent event = frame->document().createEvent("MessageEvent");
4442 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
4443 msg_event.initMessageEvent("message",
4444 // |canBubble| and |cancellable| are always false
4445 false, false,
4446 WebSerializedScriptValue::fromString(params.data),
4447 params.source_origin, source_frame, "");
4448
4449 // We must pass in the target_origin to do the security check on this side,
4450 // since it may have changed since the original postMessage call was made.
4451 WebSecurityOrigin target_origin;
4452 if (!params.target_origin.empty()) {
4453 target_origin =
4454 WebSecurityOrigin::createFromString(WebString(params.target_origin));
4455 }
4456 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
4457}
4458
[email protected]310ebd6302011-10-10 19:06:284459void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4460 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414461 WebFrame* frame = GetChildFrame(frame_xpath);
4462 if (!frame)
[email protected]216813952011-05-19 22:21:264463 return;
[email protected]ae461542009-06-19 19:03:414464
[email protected]01cf589c2011-07-28 18:04:034465 frame->document().insertUserStyleSheet(
4466 WebString::fromUTF8(css),
4467 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484468}
4469
[email protected]310ebd6302011-10-10 19:06:284470void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094471 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:044472
4473 // Keep track of the total bindings accumulated in this process.
4474 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:294475}
4476
[email protected]310ebd6302011-10-10 19:06:284477void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4478 const std::string& value) {
[email protected]808bda52012-03-09 22:43:324479 if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI)
4480 GetWebUIBindings()->SetProperty(name, value);
4481 else
4482 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:294483}
4484
[email protected]310ebd6302011-10-10 19:06:284485void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4486 const gfx::Point& client_point,
4487 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:424488 WebDragOperationsMask ops,
4489 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:554490 WebDragOperation operation = webview()->dragTargetDragEnter(
4491 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554492 client_point,
4493 screen_point,
[email protected]1f2230b2012-05-17 23:43:424494 ops,
4495 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:554496
4497 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4498}
4499
[email protected]310ebd6302011-10-10 19:06:284500void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4501 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:424502 WebDragOperationsMask ops,
4503 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:554504 WebDragOperation operation = webview()->dragTargetDragOver(
4505 client_point,
4506 screen_point,
[email protected]1f2230b2012-05-17 23:43:424507 ops,
4508 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:554509
4510 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4511}
4512
[email protected]310ebd6302011-10-10 19:06:284513void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554514 webview()->dragTargetDragLeave();
4515}
4516
[email protected]310ebd6302011-10-10 19:06:284517void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:424518 const gfx::Point& screen_point,
4519 int key_modifiers) {
4520 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:574521
4522 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554523}
4524
[email protected]310ebd6302011-10-10 19:06:284525void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4526 const gfx::Point& screen_point,
4527 bool ended,
4528 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034529 if (ended) {
[email protected]26aa0482009-09-30 16:55:274530 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204531 } else {
4532 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034533 }
initial.commit09911bf2008-07-26 23:55:294534}
4535
[email protected]310ebd6302011-10-10 19:06:284536void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274537 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294538}
4539
[email protected]310ebd6302011-10-10 19:06:284540void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594541 webkit_preferences_ = prefs;
4542 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294543}
4544
[email protected]310ebd6302011-10-10 19:06:284545void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294546 alternate_error_page_url_ = url;
4547}
4548
[email protected]310ebd6302011-10-10 19:06:284549void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514550 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084551 unsigned action) {
4552 if (custom_context.is_pepper_menu)
4553 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4554 else
4555 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584556 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4557 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334558}
4559
[email protected]310ebd6302011-10-10 19:06:284560void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514561 int id,
4562 const std::vector<FilePath>& paths) {
4563 if (!enumeration_completions_[id])
4564 return;
4565
4566 WebVector<WebString> ws_file_names(paths.size());
4567 for (size_t i = 0; i < paths.size(); ++i)
4568 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4569
4570 enumeration_completions_[id]->didChooseFile(ws_file_names);
4571 enumeration_completions_.erase(id);
4572}
4573
[email protected]fb11b6a42012-03-14 07:25:124574void RenderViewImpl::OnFileChooserResponse(
4575 const std::vector<content::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:364576 // This could happen if we navigated to a different page before the user
4577 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474578 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364579 return;
4580
[email protected]b5188522012-03-15 00:18:044581 // Convert Chrome's SelectedFileInfo list to WebKit's.
4582 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
4583 files.size());
4584 for (size_t i = 0; i < files.size(); ++i) {
4585 WebFileChooserCompletion::SelectedFileInfo selected_file;
4586 selected_file.path = webkit_glue::FilePathToWebString(files[i].path);
4587 selected_file.displayName = webkit_glue::FilePathStringToWebString(
4588 files[i].display_name);
4589 selected_files[i] = selected_file;
4590 }
[email protected]a1128322009-10-06 18:38:464591
[email protected]cdaf8d02010-03-30 19:52:474592 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:044593 file_chooser_completions_.front()->completion->didChooseFile(
4594 selected_files);
[email protected]cdaf8d02010-03-30 19:52:474595 file_chooser_completions_.pop_front();
4596
4597 // If there are more pending file chooser requests, schedule one now.
4598 if (!file_chooser_completions_.empty()) {
4599 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4600 file_chooser_completions_.front()->params));
4601 }
initial.commit09911bf2008-07-26 23:55:294602}
4603
[email protected]244ac1892011-12-02 17:04:474604void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4605 const gfx::Size& max_size) {
4606 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4607 if (!webview())
4608 return;
[email protected]61e2b3cc2012-03-02 16:13:344609 webview()->enableAutoResizeMode(min_size, max_size);
4610}
4611
4612void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
4613 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4614 if (!webview())
4615 return;
4616 webview()->disableAutoResizeMode();
4617
4618 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:474619}
4620
[email protected]2bf834f2011-11-17 20:02:214621void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244622 if (send_preferred_size_changes_)
4623 return;
[email protected]9fb325e2010-05-06 18:23:244624 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394625
[email protected]d812fd12011-05-27 23:05:074626 // Start off with an initial preferred size notification (in case
4627 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594628 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084629}
4630
[email protected]310ebd6302011-10-10 19:06:284631void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104632 const gfx::Size& disable_scrollbar_size_limit) {
4633 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4634}
4635
[email protected]310ebd6302011-10-10 19:06:284636void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314637 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504638 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514639 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374640 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:224641#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414642 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4643 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464644 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]f78452f2012-05-15 02:07:524645 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344646 renderer_prefs.thumb_inactive_color,
4647 renderer_prefs.thumb_active_color,
4648 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554649#endif
[email protected]93623c5d2009-12-10 21:40:324650
[email protected]a13283cc2012-04-05 00:21:224651#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:104652 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:224653#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:324654 webview()->setScrollbarColors(
4655 renderer_prefs.thumb_inactive_color,
4656 renderer_prefs.thumb_active_color,
4657 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554658#endif
[email protected]644d77e2010-01-27 01:03:104659 webview()->setSelectionColors(
4660 renderer_prefs.active_selection_bg_color,
4661 renderer_prefs.active_selection_fg_color,
4662 renderer_prefs.inactive_selection_bg_color,
4663 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464664 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104665 }
[email protected]7a74e102009-09-03 00:16:564666#endif
[email protected]d299d972012-03-23 02:26:554667
[email protected]d051d9a2011-12-10 02:02:504668 // If the zoom level for this page matches the old zoom default, and this
4669 // is not a plugin, update the zoom level to match the new default.
4670 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4671 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4672 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4673 zoomLevelChanged();
4674 }
[email protected]80d96fa2009-06-10 22:34:514675}
4676
[email protected]310ebd6302011-10-10 19:06:284677void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4678 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284679 if (webview())
4680 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564681}
4682
[email protected]77829642012-05-15 14:47:174683void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
4684 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
4685}
4686
[email protected]81375e872012-01-11 21:40:364687void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4688 const WebPluginAction& action) {
4689 if (webview())
4690 webview()->performPluginAction(action, location);
4691}
4692
[email protected]310ebd6302011-10-10 19:06:284693void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194694 const GURL& page_url) {
4695 // Prepare list to storage all savable resource links.
4696 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:464697 std::vector<GURL> referrer_urls_list;
4698 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:194699 std::vector<GURL> frames_list;
4700 webkit_glue::SavableResourcesResult result(&resources_list,
[email protected]c2d986512012-05-12 00:22:464701 &referrer_urls_list,
4702 &referrer_policies_list,
[email protected]18d5be92011-07-25 18:00:194703 &frames_list);
4704
[email protected]c2d986512012-05-12 00:22:464705 // webkit/ doesn't know about content::Referrer.
[email protected]18d5be92011-07-25 18:00:194706 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4707 webview(),
4708 page_url,
4709 &result,
[email protected]1de7a172012-05-28 18:36:434710 const_cast<const char**>(content::GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:194711 // If something is wrong when collecting all savable resource links,
4712 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:464713 referrer_urls_list.clear();
4714 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:194715 resources_list.clear();
4716 frames_list.clear();
4717 }
4718
[email protected]c2d986512012-05-12 00:22:464719 std::vector<content::Referrer> referrers_list;
4720 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
4721 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
4722 referrers_list.push_back(
4723 content::Referrer(referrer_urls_list[i], referrer_policies_list[i]));
4724 }
4725
[email protected]18d5be92011-07-25 18:00:194726 // Send result of all savable resource links to embedder.
4727 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4728 resources_list,
4729 referrers_list,
4730 frames_list));
4731}
4732
[email protected]310ebd6302011-10-10 19:06:284733void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194734 const std::vector<GURL>& links,
4735 const std::vector<FilePath>& local_paths,
4736 const FilePath& local_directory_name) {
4737
4738 // Convert std::vector of GURLs to WebVector<WebURL>
4739 WebVector<WebURL> weburl_links(links);
4740
4741 // Convert std::vector of std::strings to WebVector<WebString>
4742 WebVector<WebString> webstring_paths(local_paths.size());
4743 for (size_t i = 0; i < local_paths.size(); i++)
4744 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4745
4746 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4747 webstring_paths,
4748 webkit_glue::FilePathToWebString(
4749 local_directory_name));
4750}
4751
[email protected]310ebd6302011-10-10 19:06:284752void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:124753 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:274754 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:124755 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
4756 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
4757 before_unload_start_time,
4758 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:294759}
4760
[email protected]310ebd6302011-10-10 19:06:284761void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:314762 // Ensure that no other in-progress navigation continues.
4763 OnStop();
4764
[email protected]73eb2602012-02-09 19:50:554765 // Only run unload if we're not swapped out yet, but send the ack either way.
4766 if (!is_swapped_out_) {
4767 // Swap this RenderView out so the tab can navigate to a page rendered by a
4768 // different process. This involves running the unload handler and clearing
4769 // the page. Once WasSwappedOut is called, we also allow this process to
4770 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154771
[email protected]73eb2602012-02-09 19:50:554772 // Send an UpdateState message before we get swapped out.
4773 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154774
[email protected]73eb2602012-02-09 19:50:554775 // Synchronously run the unload handler before sending the ACK.
4776 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154777
[email protected]73eb2602012-02-09 19:50:554778 // Swap out and stop sending any IPC messages that are not ACKs.
4779 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154780
[email protected]285f4bb82012-04-17 15:57:284781 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:554782 // run a second time, thanks to a check in FrameLoader::stopLoading.
4783 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:284784 // beforeunload handler. For now, we just run it a second time silently.
[email protected]14392a52012-05-02 20:28:444785 NavigateToSwappedOutURL();
[email protected]961541a92012-06-01 21:15:284786
4787 // Let WebKit know that this view is hidden so it can drop resources and
4788 // stop compositing.
4789 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:554790 }
[email protected]992db4c2011-05-12 15:37:154791
4792 // Just echo back the params in the ACK.
4793 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4794}
4795
[email protected]14392a52012-05-02 20:28:444796void RenderViewImpl::NavigateToSwappedOutURL() {
4797 // We use loadRequest instead of loadHTMLString because the former commits
4798 // synchronously. Otherwise a new navigation can interrupt the navigation
4799 // to content::kSwappedOutURL. If that happens to be to the page we had been
4800 // showing, then WebKit will never send a commit and we'll be left spinning.
4801 GURL swappedOutURL(content::kSwappedOutURL);
4802 WebURLRequest request(swappedOutURL);
4803 webview()->mainFrame()->loadRequest(request);
4804}
4805
[email protected]310ebd6302011-10-10 19:06:284806void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374807 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294808 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4809 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4810 // in the onunload handler from appearing. For now, we're bypassing that and
4811 // calling the FrameLoader's CloseURL method directly. This should be
4812 // revisited to avoid having two ways to close a page. Having a single way
4813 // to close that can run onunload is also useful for fixing
4814 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274815 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294816
[email protected]992db4c2011-05-12 15:37:154817 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294818}
4819
[email protected]310ebd6302011-10-10 19:06:284820void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024821#if defined(USE_AURA)
4822 // Aura doesn't care if we switch themes.
4823#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:524824 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464825 if (webview())
4826 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574827#else // defined(OS_WIN)
4828 // TODO(port): we don't support theming on non-Windows platforms yet
4829 NOTIMPLEMENTED();
4830#endif
initial.commit09911bf2008-07-26 23:55:294831}
4832
[email protected]310ebd6302011-10-10 19:06:284833void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084834 if (decrement_shared_popup_at_destruction_)
4835 shared_popup_counter_->data--;
4836 shared_popup_counter_ = new SharedRenderViewCounter(0);
4837 decrement_shared_popup_at_destruction_ = false;
4838}
4839
[email protected]310ebd6302011-10-10 19:06:284840bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4841 const WebURLError& error,
4842 bool replace) {
[email protected]15d79e12009-08-02 19:23:454843 // We only show alternate error pages in the main frame. They are
4844 // intended to assist the user when navigating, so there is not much
4845 // value in showing them for failed subframes. Ideally, we would be
4846 // able to use the TYPED transition type for this, but that flag is
4847 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454848 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454849 return false;
4850
4851 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374852 // connection failure.
[email protected]15d79e12009-08-02 19:23:454853 int ec = error.reason;
4854 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4855 ec != net::ERR_CONNECTION_FAILED &&
4856 ec != net::ERR_CONNECTION_REFUSED &&
4857 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:414858 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:454859 return false;
[email protected]82114f52012-03-20 22:53:414860 }
[email protected]15d79e12009-08-02 19:23:454861
4862 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554863 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454864 if (!error_page_url.is_valid())
4865 return false;
4866
4867 // Load an empty page first so there is an immediate response to the error,
4868 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454869 frame->loadHTMLString(std::string(),
[email protected]285f4bb82012-04-17 15:57:284870 GURL(content::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454871 error.unreachableURL,
4872 replace);
4873
4874 // Now, create a fetcher for the error page and associate it with the data
4875 // source we just created via the LoadHTMLString call. That way if another
4876 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074877 DocumentState* document_state =
4878 DocumentState::FromDataSource(frame->provisionalDataSource());
4879 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454880 new AltErrorPageResourceFetcher(
4881 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084882 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4883 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454884 return true;
4885}
4886
[email protected]310ebd6302011-10-10 19:06:284887void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4888 const WebURLError& original_error,
4889 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454890 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094891 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554892 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094893 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454894}
4895
[email protected]310ebd6302011-10-10 19:06:284896void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004897 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474898 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004899}
4900
[email protected]310ebd6302011-10-10 19:06:284901void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094902 const gfx::Rect& resizer_rect,
4903 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104904 if (webview()) {
[email protected]7ddea9802012-02-22 23:08:054905 // This setting has no effect if fixed layout is not enabled.
[email protected]60051ec2012-06-08 22:40:574906 DCHECK(device_scale_factor_);
4907 if (device_scale_factor_) {
[email protected]7ddea9802012-02-22 23:08:054908 webview()->settings()->setLayoutFallbackWidth(
[email protected]60051ec2012-06-08 22:40:574909 new_size.width() / device_scale_factor_);
4910 }
[email protected]a72a1fa2010-05-03 22:18:474911 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104912 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204913 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314914 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104915 }
[email protected]dd6afca2011-08-13 03:44:314916 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104917 }
4918
[email protected]ee41e7d22011-10-14 19:34:094919 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004920}
[email protected]0aa477bd2009-03-23 22:21:434921
[email protected]29ed96a2012-02-04 18:12:164922void RenderViewImpl::WillInitiatePaint() {
4923 // Notify the pepper plugins that we're about to paint.
4924 pepper_delegate_.ViewWillInitiatePaint();
4925}
4926
[email protected]310ebd6302011-10-10 19:06:284927void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164928 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014929 pepper_delegate_.ViewInitiatedPaint();
[email protected]7900bfdb2012-05-24 19:31:244930 if (GetGuestToEmbedderChannel())
4931 GetGuestToEmbedderChannel()->IssueSwapBuffers(guest_graphics_resource());
[email protected]00c39612010-03-06 02:53:284932}
4933
[email protected]310ebd6302011-10-10 19:06:284934void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284935 // Notify any pepper plugins that we painted. This will call into the plugin,
4936 // and we it may ask to close itself as a result. This will, in turn, modify
4937 // our set, possibly invalidating the iterator. So we iterate on a copy that
4938 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014939 pepper_delegate_.ViewFlushedPaint();
4940
[email protected]5b1dec8c2012-02-07 04:35:384941 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4942 // See crbug.com/112921.
4943 if (!webview())
4944 return;
4945
[email protected]00c39612010-03-06 02:53:284946 WebFrame* main_frame = webview()->mainFrame();
4947
4948 // If we have a provisional frame we are between the start and commit stages
4949 // of loading and we don't want to save stats.
4950 if (!main_frame->provisionalDataSource()) {
4951 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074952 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284953
[email protected]05c8e502010-08-15 15:13:524954 // TODO(jar): The following code should all be inside a method, probably in
4955 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284956 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074957 if (document_state->first_paint_time().is_null()) {
4958 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284959 }
[email protected]007733c2011-11-17 00:34:074960 if (document_state->first_paint_after_load_time().is_null() &&
4961 !document_state->finish_load_time().is_null()) {
4962 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284963 }
4964 }
4965}
4966
[email protected]310ebd6302011-10-10 19:06:284967void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084968 RenderWidget::OnSwapBuffersPosted();
4969}
4970
[email protected]310ebd6302011-10-10 19:06:284971void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244972 RenderWidget::OnSwapBuffersComplete();
4973}
4974
[email protected]310ebd6302011-10-10 19:06:284975void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244976 RenderWidget::OnSwapBuffersAborted();
4977}
4978
[email protected]310ebd6302011-10-10 19:06:284979webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154980 const gfx::Rect& paint_bounds,
4981 TransportDIB** dib,
4982 gfx::Rect* location,
4983 gfx::Rect* clip) {
4984 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4985 paint_bounds, dib, location, clip);
4986}
4987
[email protected]310ebd6302011-10-10 19:06:284988gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074989 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434990 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524991}
4992
[email protected]310ebd6302011-10-10 19:06:284993void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164994 if (webview())
[email protected]26aa0482009-09-30 16:55:274995 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164996}
4997
[email protected]310ebd6302011-10-10 19:06:284998void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144999 if (webview())
[email protected]b4bb2502009-10-01 22:35:275000 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145001
5002 SetBackground(background);
5003}
5004
[email protected]2a84f9d2012-06-05 21:50:435005void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5006 if (accessibility_mode_ == new_mode)
5007 return;
5008 accessibility_mode_ = new_mode;
5009 if (renderer_accessibility_) {
5010 delete renderer_accessibility_;
5011 renderer_accessibility_ = NULL;
5012 }
5013 if (accessibility_mode_ == AccessibilityModeComplete)
5014 renderer_accessibility_ = new RendererAccessibilityComplete(this);
5015 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5016 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
5017}
5018
[email protected]310ebd6302011-10-10 19:06:285019void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345020 if (webview())
[email protected]b4bb2502009-10-01 22:35:275021 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265022
5023#if defined(OS_MACOSX)
5024 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5025 for (plugin_it = plugin_delegates_.begin();
5026 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5027 (*plugin_it)->SetWindowFocus(active);
5028 }
5029#endif
[email protected]8c66c5a2009-07-22 17:26:345030}
5031
[email protected]7a17bac02012-03-07 21:58:125032void RenderViewImpl::OnSetNavigationStartTime(
5033 const base::TimeTicks& browser_navigation_start) {
5034 if (!webview())
5035 return;
5036
5037 // Only the initial navigation can be a cross-renderer navigation. If we've
5038 // already navigated away from that page, we can ignore this message.
5039 if (page_id_ != -1)
5040 return;
5041
5042 // browser_navigation_start is likely before this process existed, so we can't
5043 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
5044 // ensure we don't report a bogus value in the future.
5045 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
5046 browser_navigation_start);
5047 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
5048 (navigation_start - base::TimeTicks()).InSecondsF());
5049}
5050
[email protected]6ce7abc52010-02-02 18:40:145051#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285052void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:145053 // Inform plugins that their container has changed visibility.
5054 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5055 for (plugin_it = plugin_delegates_.begin();
5056 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5057 (*plugin_it)->SetContainerVisibility(visible);
5058 }
5059}
[email protected]1e6e3c992010-02-08 15:52:135060
[email protected]310ebd6302011-10-10 19:06:285061void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5062 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135063 // Inform plugins that their window's frame has changed.
5064 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5065 for (plugin_it = plugin_delegates_.begin();
5066 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5067 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5068 }
5069}
[email protected]935d63d2010-10-15 23:31:555070
[email protected]310ebd6302011-10-10 19:06:285071void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5072 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135073 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555074 // applies to it or not, so inform all the delegates.
5075 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5076 for (plugin_it = plugin_delegates_.begin();
5077 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135078 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555079 }
5080}
[email protected]6ce7abc52010-02-02 18:40:145081#endif // OS_MACOSX
5082
[email protected]310ebd6302011-10-10 19:06:285083void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:485084 const EditCommands& edit_commands) {
5085 edit_commands_ = edit_commands;
5086}
5087
[email protected]310ebd6302011-10-10 19:06:285088void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595089 // We need to grab a pointer to the doomed WebView before we destroy it.
5090 WebView* doomed = webview();
5091 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495092 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595093}
5094
[email protected]310ebd6302011-10-10 19:06:285095void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:485096 edit_commands_.clear();
5097}
5098
[email protected]310ebd6302011-10-10 19:06:285099bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:115100 pepper_delegate_.WillHandleMouseEvent();
5101
5102 // If the mouse is locked, only the current owner of the mouse lock can
5103 // process mouse events.
5104 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375105}
5106
[email protected]2b942c332012-04-25 16:26:265107void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515108 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065109}
5110
[email protected]310ebd6302011-10-10 19:06:285111void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245112 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5113}
5114
[email protected]310ebd6302011-10-10 19:06:285115void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435116 RenderWidget::OnWasHidden();
5117
[email protected]2d7b82c2012-06-01 05:57:505118#if defined(OS_ANDROID)
5119 // Inform WebMediaPlayerManagerAndroid to release all media player resources.
5120 media_player_manager_->ReleaseMediaResources();
5121#endif
5122
[email protected]a6939ca42011-02-18 17:58:075123 if (webview()) {
5124 webview()->settings()->setMinimumTimerInterval(
5125 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445126 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075127 }
5128
[email protected]204f1df2012-01-04 20:21:135129 // Inform PPAPI plugins that their page is no longer visible.
5130 pepper_delegate_.PageVisibilityChanged(false);
5131
[email protected]a6939ca42011-02-18 17:58:075132#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135133 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435134 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5135 for (plugin_it = plugin_delegates_.begin();
5136 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5137 (*plugin_it)->SetContainerVisibility(false);
5138 }
[email protected]a6939ca42011-02-18 17:58:075139#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435140}
5141
[email protected]310ebd6302011-10-10 19:06:285142void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:435143 RenderWidget::OnWasRestored(needs_repainting);
5144
[email protected]a6939ca42011-02-18 17:58:075145 if (webview()) {
5146 webview()->settings()->setMinimumTimerInterval(
5147 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445148 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075149 }
5150
[email protected]204f1df2012-01-04 20:21:135151 // Inform PPAPI plugins that their page is visible.
5152 pepper_delegate_.PageVisibilityChanged(true);
5153
[email protected]a6939ca42011-02-18 17:58:075154#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135155 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435156 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5157 for (plugin_it = plugin_delegates_.begin();
5158 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5159 (*plugin_it)->SetContainerVisibility(true);
5160 }
[email protected]784ea1ab2010-09-18 00:02:345161#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075162}
[email protected]1e6e3c992010-02-08 15:52:135163
[email protected]310ebd6302011-10-10 19:06:285164bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:385165 if (WebWidgetHandlesCompositorScheduling())
5166 return false;
5167
[email protected]05a980d7a2012-02-07 22:16:425168 if (queried_for_swapbuffers_complete_callback_)
5169 return context_has_swapbuffers_complete_callback_;
5170
5171 queried_for_swapbuffers_complete_callback_ = true;
5172
[email protected]65225772011-05-12 21:10:245173 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:425174 if (context && context->makeContextCurrent()) {
5175 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
5176 context_has_swapbuffers_complete_callback_ =
5177 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
5178 != std::string::npos;
5179 }
5180
5181 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:245182}
5183
[email protected]310ebd6302011-10-10 19:06:285184void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135185 RenderWidget::OnSetFocus(enable);
5186
[email protected]7d3c02c2010-05-05 23:10:315187 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075188 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135189 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5190 for (plugin_it = plugin_delegates_.begin();
5191 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345192#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315193 // RenderWidget's call to setFocus can cause the underlying webview's
5194 // activation state to change just like a call to setIsActive.
5195 if (enable)
5196 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345197#endif
[email protected]7d3c02c2010-05-05 23:10:315198 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135199 }
[email protected]589621b2010-09-23 22:01:075200
5201 // Notify all Pepper plugins.
5202 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135203 }
5204}
[email protected]941e4552010-02-01 21:23:435205
[email protected]310ebd6302011-10-10 19:06:285206void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:005207 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:505208 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575209}
5210
[email protected]73bf95812011-10-12 11:38:325211void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:005212 UpdateTextInputState();
[email protected]8fe8f742012-06-14 00:36:085213 if (renderer_accessibility_)
5214 renderer_accessibility_->FocusedNodeChanged(WebNode());
[email protected]73bf95812011-10-12 11:38:325215}
5216
[email protected]3f783362011-10-21 22:40:505217void RenderViewImpl::PpapiPluginCaretPositionChanged() {
5218 UpdateSelectionBounds();
5219}
5220
[email protected]b25b3ee2012-01-13 05:19:545221bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
5222 if (!pepper_delegate_.IsPluginFocused())
5223 return false;
5224 *rect = pepper_delegate_.GetCaretBounds();
5225 return true;
5226}
5227
[email protected]397c23962012-05-21 07:09:325228void RenderViewImpl::SimulateImeSetComposition(
5229 const string16& text,
5230 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5231 int selection_start,
5232 int selection_end) {
5233 OnImeSetComposition(text, underlines, selection_start, selection_end);
5234}
5235
5236void RenderViewImpl::SimulateImeConfirmComposition(
5237 const string16& text,
5238 const ui::Range& replacement_range) {
5239 OnImeConfirmComposition(text, replacement_range);
5240}
5241
[email protected]73bf95812011-10-12 11:38:325242void RenderViewImpl::PpapiPluginCancelComposition() {
5243 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]58b48a0d2012-06-13 07:01:355244 const ui::Range range(ui::Range::InvalidRange());
5245 const std::vector<gfx::Rect> empty_bounds;
5246 UpdateCompositionInfo(range, empty_bounds);
[email protected]73bf95812011-10-12 11:38:325247}
5248
[email protected]3c8c74c2012-03-15 07:34:525249void RenderViewImpl::PpapiPluginSelectionChanged() {
5250 SyncSelectionIfRequired();
5251}
5252
[email protected]310ebd6302011-10-10 19:06:285253void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575254 const string16& text,
5255 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5256 int selection_start,
5257 int selection_end) {
[email protected]73bf95812011-10-12 11:38:325258 if (pepper_delegate_.IsPluginFocused()) {
5259 // When a PPAPI plugin has focus, we bypass WebKit.
5260 pepper_delegate_.OnImeSetComposition(text,
5261 underlines,
5262 selection_start,
5263 selection_end);
5264 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235265#if defined(OS_WIN)
5266 // When a plug-in has focus, we create platform-specific IME data used by
5267 // our IME emulator and send it directly to the focused plug-in, i.e. we
5268 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5269 // instance ID is the same one as the specified ID.)
5270 if (focused_plugin_id_ >= 0) {
5271 std::vector<int> clauses;
5272 std::vector<int> target;
5273 for (size_t i = 0; i < underlines.size(); ++i) {
5274 clauses.push_back(underlines[i].startOffset);
5275 clauses.push_back(underlines[i].endOffset);
5276 if (underlines[i].thick) {
5277 target.clear();
5278 target.push_back(underlines[i].startOffset);
5279 target.push_back(underlines[i].endOffset);
5280 }
5281 }
5282 std::set<WebPluginDelegateProxy*>::iterator it;
5283 for (it = plugin_delegates_.begin();
5284 it != plugin_delegates_.end(); ++it) {
5285 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5286 focused_plugin_id_);
5287 }
5288 return;
5289 }
5290#endif
[email protected]56ea1a62011-05-30 07:05:575291 RenderWidget::OnImeSetComposition(text,
5292 underlines,
5293 selection_start,
5294 selection_end);
5295 }
5296}
5297
[email protected]4de6d1692011-10-12 08:45:445298void RenderViewImpl::OnImeConfirmComposition(
5299 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:575300 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325301 // When a PPAPI plugin has focus, we bypass WebKit.
5302 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:575303 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235304#if defined(OS_WIN)
5305 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5306 // plug-ins. When we send IME text directly to plug-ins, we should not send
5307 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:445308 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:235309 if (focused_plugin_id_ >= 0) {
5310 std::set<WebPluginDelegateProxy*>::iterator it;
5311 for (it = plugin_delegates_.begin();
5312 it != plugin_delegates_.end(); ++it) {
5313 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5314 }
5315 return;
5316 }
5317#endif
[email protected]ebd28ac2011-10-13 18:49:055318 if (replacement_range.IsValid() && webview()) {
5319 // Select the text in |replacement_range|, it will then be replaced by
5320 // text added by the call to RenderWidget::OnImeConfirmComposition().
5321 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:165322 WebRange webrange = WebRange::fromDocumentRange(
5323 frame, replacement_range.start(), replacement_range.length());
5324 if (!webrange.isNull())
5325 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:055326 }
5327 }
[email protected]4de6d1692011-10-12 08:45:445328 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:575329 }
5330}
5331
[email protected]310ebd6302011-10-10 19:06:285332ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:325333 return pepper_delegate_.IsPluginFocused() ?
5334 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
5335}
5336
[email protected]3f783362011-10-21 22:40:505337void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
5338 if (pepper_delegate_.IsPluginFocused()) {
5339 // TODO(kinaba) http://crbug.com/101101
5340 // Current Pepper IME API does not handle selection bounds. So we simply
5341 // use the caret position as an empty range for now. It will be updated
5342 // after Pepper API equips features related to surrounding text retrieval.
5343 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
5344 *start = caret;
5345 *end = caret;
5346 return;
5347 }
5348 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455349}
5350
[email protected]58b48a0d2012-06-13 07:01:355351void RenderViewImpl::GetCompositionCharacterBounds(
5352 std::vector<gfx::Rect>* bounds) {
5353 DCHECK(bounds);
5354 bounds->clear();
5355
5356 if (!webview())
5357 return;
5358 size_t start_offset = 0;
5359 size_t character_count = 0;
5360 if (!webview()->compositionRange(&start_offset, &character_count))
5361 return;
5362 if (character_count == 0)
5363 return;
5364
5365 WebKit::WebFrame* frame = webview()->focusedFrame();
5366 if (!frame)
5367 return;
5368
5369 bounds->reserve(character_count);
5370 WebKit::WebRect webrect;
5371 for (size_t i = 0; i < character_count; ++i) {
5372 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
5373 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
5374 bounds->clear();
5375 return;
5376 }
5377 bounds->push_back(webrect);
5378 }
5379}
5380
[email protected]310ebd6302011-10-10 19:06:285381bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:325382 return pepper_delegate_.IsPluginFocused() ?
5383 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:575384}
5385
[email protected]e6ae0f6c2011-10-04 10:39:235386#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:285387void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:235388 if (focused)
5389 focused_plugin_id_ = plugin_id;
5390 else
5391 focused_plugin_id_ = -1;
5392}
5393#endif
5394
[email protected]43f28f832010-02-03 02:28:485395#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285396void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:415397 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:135398}
5399
[email protected]310ebd6302011-10-10 19:06:285400void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:135401 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555402 // This message can be sent during event-handling, and needs to be delivered
5403 // within that context.
5404 msg->set_unblock(true);
5405 Send(msg);
5406}
5407
[email protected]310ebd6302011-10-10 19:06:285408gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235409 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:515410 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:485411 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235412 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115413 if (window) {
5414 fake_plugin_window_handles_.insert(window);
5415 }
[email protected]43f28f832010-02-03 02:28:485416 return window;
5417}
5418
[email protected]310ebd6302011-10-10 19:06:285419void RenderViewImpl::DestroyFakePluginWindowHandle(
5420 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115421 if (window && fake_plugin_window_handles_.find(window) !=
5422 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485423 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115424 fake_plugin_window_handles_.erase(window);
5425 }
[email protected]43f28f832010-02-03 02:28:485426}
5427
[email protected]310ebd6302011-10-10 19:06:285428void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
5429 gfx::PluginWindowHandle window,
5430 int32 width,
5431 int32 height,
5432 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:335433 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485434 routing_id(), window, width, height, io_surface_identifier));
5435}
5436
[email protected]310ebd6302011-10-10 19:06:285437void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335438 gfx::PluginWindowHandle window,
5439 int32 width,
5440 int32 height,
5441 TransportDIB::Handle transport_dib) {
5442 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075443 routing_id(), window, width, height, transport_dib));
5444}
5445
[email protected]310ebd6302011-10-10 19:06:285446TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335447 size_t size) {
[email protected]1aef98132010-02-23 18:00:075448 TransportDIB::Handle dib_handle;
5449 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385450 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075451 return dib_handle;
5452 // Return an invalid handle if Send() fails.
5453 return TransportDIB::DefaultHandleValue();
5454}
5455
[email protected]310ebd6302011-10-10 19:06:285456void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
5457 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075458 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5459}
5460
[email protected]310ebd6302011-10-10 19:06:285461void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325462 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:145463 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325464 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:485465}
[email protected]82114f52012-03-20 22:53:415466#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:285467
[email protected]310ebd6302011-10-10 19:06:285468bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:235469 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:475470 WebFileChooserCompletion* completion) {
5471 static const size_t kMaximumPendingFileChooseRequests = 4;
5472 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5473 // This sanity check prevents too many file choose requests from getting
5474 // queued which could DoS the user. Getting these is most likely a
5475 // programming error (there are many ways to DoS the user so it's not
5476 // considered a "real" security check), either in JS requesting many file
5477 // choosers to pop up, or in a plugin.
5478 //
5479 // TODO(brettw) we might possibly want to require a user gesture to open
5480 // a file picker, which will address this issue in a better way.
5481 return false;
5482 }
5483
5484 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5485 new PendingFileChooser(params, completion)));
5486 if (file_chooser_completions_.size() == 1) {
5487 // Actually show the browse dialog when this is the first request.
5488 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5489 }
5490 return true;
5491}
5492
[email protected]310ebd6302011-10-10 19:06:285493WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515494 if (!geolocation_dispatcher_)
5495 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5496 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255497}
[email protected]61c9f032010-03-31 23:04:195498
[email protected]310ebd6302011-10-10 19:06:285499WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:115500 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:225501#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:025502 if (!input_tag_speech_dispatcher_)
5503 input_tag_speech_dispatcher_ =
5504 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:225505#endif
[email protected]c52b2892012-03-07 11:01:025506 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:115507}
5508
[email protected]64d09222012-05-25 10:10:345509WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
5510#if defined(ENABLE_INPUT_SPEECH)
5511 if (!speech_recognition_dispatcher_)
5512 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
5513#endif
5514 return speech_recognition_dispatcher_;
5515}
5516
[email protected]310ebd6302011-10-10 19:06:285517WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515518 if (!device_orientation_dispatcher_)
5519 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5520 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535521}
5522
[email protected]310ebd6302011-10-10 19:06:285523void RenderViewImpl::zoomLimitsChanged(double minimum_level,
5524 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:255525 // For now, don't remember plugin zoom values. We don't want to mix them with
5526 // normal web content (i.e. a fixed layout plugin would usually want them
5527 // different).
5528 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5529
[email protected]b75b8292010-10-01 07:28:255530 int minimum_percent = static_cast<int>(
5531 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5532 int maximum_percent = static_cast<int>(
5533 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255534
5535 Send(new ViewHostMsg_UpdateZoomLimits(
5536 routing_id_, minimum_percent, maximum_percent, remember));
5537}
5538
[email protected]310ebd6302011-10-10 19:06:285539void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:255540 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:085541 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:265542
5543 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
5544
[email protected]b75b8292010-10-01 07:28:255545 // Tell the browser which url got zoomed so it can update the menu and the
5546 // saved values if necessary
5547 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:085548 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:415549 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:255550}
5551
[email protected]310ebd6302011-10-10 19:06:285552void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
5553 const WebString& base_url,
5554 const WebString& url,
5555 const WebString& title) {
[email protected]3a3b75a2012-06-01 08:38:365556 bool user_gesture = (webview()->focusedFrame() &&
5557 webview()->focusedFrame()->isProcessingUserGesture());
[email protected]a6d36cc2011-02-23 00:39:485558 GURL base(base_url);
5559 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
5560 if (base.GetOrigin() != absolute_url.GetOrigin()) {
5561 return;
5562 }
[email protected]f1a29a02011-10-06 23:08:445563 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
5564 UTF16ToUTF8(scheme),
5565 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:365566 title,
5567 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:485568}
5569
[email protected]310ebd6302011-10-10 19:06:285570WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:445571 WebKit::WebPageVisibilityState current_state = is_hidden() ?
5572 WebKit::WebPageVisibilityStateHidden :
5573 WebKit::WebPageVisibilityStateVisible;
5574 WebKit::WebPageVisibilityState override_state = current_state;
5575 if (content::GetContentClient()->renderer()->
5576 ShouldOverridePageVisibilityState(this,
5577 &override_state))
5578 return override_state;
5579 return current_state;
[email protected]94dec932011-05-26 20:04:215580}
5581
[email protected]273558fb2012-01-12 15:03:515582WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:515583 EnsureMediaStreamImpl();
5584 return media_stream_impl_;
5585}
5586
[email protected]310ebd6302011-10-10 19:06:285587void RenderViewImpl::OnAsyncFileOpened(
5588 base::PlatformFileError error_code,
5589 IPC::PlatformFileForTransit file_for_transit,
5590 int message_id) {
[email protected]27a9ef32010-09-10 04:06:245591 pepper_delegate_.OnAsyncFileOpened(
5592 error_code,
5593 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5594 message_id);
5595}
[email protected]caf706f2010-10-26 17:54:085596
[email protected]310ebd6302011-10-10 19:06:285597void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:475598 int request_id,
[email protected]d54305072011-06-22 20:58:435599 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:475600 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
[email protected]2b657fd2011-04-18 16:00:475601 handle);
[email protected]eb415bf0e2011-04-14 02:45:425602}
5603
[email protected]caf706f2010-10-26 17:54:085604#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285605void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155606 if (external_popup_menu_ == NULL) {
5607 // Crash reports from the field indicate that we can be notified with a
5608 // NULL external popup menu (we probably get notified twice).
5609 // If you hit this please file a bug against jcivelli and include the page
5610 // and steps to repro.
5611 NOTREACHED();
5612 return;
5613 }
[email protected]caf706f2010-10-26 17:54:085614 external_popup_menu_->DidSelectItem(selected_index);
5615 external_popup_menu_.reset();
5616}
5617#endif
[email protected]bb461532010-11-26 21:50:235618
[email protected]24d2b172012-05-26 00:54:125619#if defined(OS_ANDROID)
5620void RenderViewImpl::OnSelectPopupMenuItems(
5621 bool canceled,
5622 const std::vector<int>& selected_indices) {
5623 // It is possible to receive more than one of these calls if the user presses
5624 // a select faster than it takes for the show-select-popup IPC message to make
5625 // it to the browser UI thread. Ignore the extra-messages.
5626 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
5627 if (!external_popup_menu_.get())
5628 return;
5629
5630 external_popup_menu_->DidSelectItems(canceled, selected_indices);
5631 external_popup_menu_.reset();
5632}
5633#endif
5634
[email protected]310ebd6302011-10-10 19:06:285635void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515636 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085637 if (custom_context.is_pepper_menu)
5638 pepper_delegate_.OnContextMenuClosed(custom_context);
5639 else
5640 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105641}
[email protected]5a7b15a2011-08-22 22:48:185642
[email protected]310ebd6302011-10-10 19:06:285643void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185644 if (!webview())
5645 return;
5646 WebFrame* main_frame = webview()->mainFrame();
5647 if (!main_frame)
5648 return;
5649 main_frame->enableViewSourceMode(true);
5650}
[email protected]67bfb83f2011-09-22 03:36:375651
[email protected]310ebd6302011-10-10 19:06:285652bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085653 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405654}
[email protected]7f3c7af2011-10-20 22:52:515655
[email protected]64d0e192011-12-09 14:44:205656void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:315657 DCHECK(!java_bridge_dispatcher_);
[email protected]464750f2011-10-24 23:16:185658#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7e9c5bb02012-05-14 13:58:315659 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]464750f2011-10-24 23:16:185660#endif
[email protected]7f3c7af2011-10-20 22:52:515661}