blob: 117a583a2391aed1208aa7db21fe903fd79b0c6f [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]663bd9e2011-03-21 01:07:0190#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:2091#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]64d09222012-05-25 10:10:3492#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3293#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1994#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:1395#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:0196#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3597#include "content/renderer/webplugin_delegate_proxy.h"
98#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4999#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41100#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:50101#include "media/base/message_loop_factory.h"
[email protected]37136d162012-04-09 23:39:19102#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:18103#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:29104#include "net/base/escape.h"
105#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04106#include "net/http/http_util.h"
[email protected]8bd0fe62011-01-17 06:44:37107#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]f546640b2012-05-15 00:03:49108#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
[email protected]be2510c02012-05-28 14:52:14110#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
111#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37112#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
113#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37114#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
115#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37119#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57121#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58122#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44123#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58124#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14125#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]4e1eb3392012-05-18 00:08:05126#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h"
[email protected]8bd0fe62011-01-17 06:44:37127#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19128#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37129#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36130#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37131#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37134#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37135#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17138#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37139#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]10e5cf12011-04-13 04:10:40140#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51141#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08142#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]50da23d02012-04-13 17:47:48148#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
[email protected]273558fb2012-01-12 15:03:51150#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08152#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]f546640b2012-05-15 00:03:49154#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
[email protected]9c4bf232011-12-15 02:25:08155#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34156#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37157#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
158#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
159#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
160#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
161#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
162#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26163#include "third_party/skia/include/core/SkBitmap.h"
[email protected]08397d52011-02-05 01:53:38164#include "ui/gfx/native_widget_types.h"
165#include "ui/gfx/point.h"
166#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55167#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04168#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]b928936b2012-04-13 01:16:16169#include "webkit/dom_storage/dom_storage_types.h"
[email protected]9c4bf232011-12-15 02:25:08170#include "webkit/forms/form_data.h"
171#include "webkit/forms/form_field.h"
172#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43173#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19174#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24175#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29176#include "webkit/glue/webdropdata.h"
[email protected]3a3b75a2012-06-01 08:38:36177#include "webkit/glue/web_intent_service_data.h"
[email protected]a6939ca42011-02-18 17:58:07178#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29179#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03180#include "webkit/glue/weburlloader_impl.h"
[email protected]b9fd01ba2012-02-28 01:50:40181#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51182#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16183#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50184#include "webkit/plugins/npapi/plugin_list.h"
185#include "webkit/plugins/npapi/webplugin_delegate.h"
186#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
187#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52188#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29189
[email protected]25fb9b32012-04-27 03:21:55190#if defined(OS_ANDROID)
191#include "webkit/media/android/webmediaplayer_android.h"
[email protected]2d7b82c2012-06-01 05:57:50192#include "webkit/media/android/webmediaplayer_manager_android.h"
[email protected]25fb9b32012-04-27 03:21:55193#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57194// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57195// * theming
[email protected]f78452f2012-05-15 02:07:52196#include "ui/base/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03197#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37198#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]f78452f2012-05-15 02:07:52199#include "ui/base/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33200#elif defined(OS_MACOSX)
201#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57202#endif
203
[email protected]9892b472010-09-16 00:23:42204using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08205using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21206using WebKit::WebApplicationCacheHost;
207using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26208using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41209using WebKit::WebColor;
210using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59211using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44212using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51213using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55214using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28215using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00216using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49217using WebKit::WebDOMEvent;
218using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58219using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25220using WebKit::WebDragOperation;
221using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51222using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51223using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08224using WebKit::WebExternalPopupMenu;
225using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47226using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22227using WebKit::WebFileSystem;
228using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49229using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59230using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48231using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45232using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51233using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17234using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13235using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41236using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50237using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15238using WebKit::WebIntentRequest;
239using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17240using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28241using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17242using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26243using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28244using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28245using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51246using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19247using WebKit::WebPageSerializer;
248using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48249using WebKit::WebPeerConnection00Handler;
250using WebKit::WebPeerConnection00HandlerClient;
251using WebKit::WebPeerConnectionHandler;
252using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17253using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36254using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40255using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49256using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09257using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52258using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59259using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51260using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52261using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15262using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40263using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35264using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29265using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17266using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49267using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59268using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42269using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02270using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34271using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34272using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40273using WebKit::WebStorageQuotaCallbacks;
274using WebKit::WebStorageQuotaError;
275using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28276using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51277using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52278using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24279using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28280using WebKit::WebURL;
281using WebKit::WebURLError;
282using WebKit::WebURLRequest;
283using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28284using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03285using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28286using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26287using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26288using appcache::WebApplicationCacheHostImpl;
289using base::Time;
290using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07291using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32292using content::NavigationState;
[email protected]380244092011-10-07 17:26:27293using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44294using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36295using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15296using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19297using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08298using webkit::forms::FormField;
299using webkit::forms::PasswordForm;
300using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26301using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23302using webkit_glue::ResourceFetcher;
[email protected]6717bf272012-05-11 23:31:25303using webkit_glue::WebPreferences;
[email protected]b9fd01ba2012-02-28 01:50:40304using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33305
initial.commit09911bf2008-07-26 23:55:29306//-----------------------------------------------------------------------------
307
[email protected]310ebd6302011-10-10 19:06:28308typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49309static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02310
[email protected]882daa92009-11-05 16:31:31311// Time, in seconds, we delay before sending content state changes (such as form
312// state and scroll position) to the browser. We delay sending changes to avoid
313// spamming the browser.
314// To avoid having tab/session restore require sending a message to get the
315// current content state during tab closing we use a shorter timeout for the
316// foreground renderer. This means there is a small window of time from which
317// content state is modified and not sent to session restore, but this is
318// better than having to wake up all renderers during shutdown.
319static const int kDelaySecondsForContentStateSyncHidden = 5;
320static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29321
[email protected]e99ef6f2011-10-16 01:13:00322static const size_t kExtraCharsBeforeAndAfterSelection = 100;
323
[email protected]0aa55312008-10-17 21:53:08324// The maximum number of popups that can be spawned from one page.
325static const int kMaximumNumberOfUnacknowledgedPopups = 25;
326
[email protected]c514d6372011-08-16 22:54:44327static const float kScalingIncrement = 0.1f;
328
[email protected]47578fa02011-11-02 19:34:41329static const float kScalingIncrementForGesture = 0.01f;
330
[email protected]f546640b2012-05-15 00:03:49331static RenderViewImpl* FromRoutingID(int32 routing_id) {
332 return static_cast<RenderViewImpl*>(
333 ChildThread::current()->ResolveRoute(routing_id));
334}
335
[email protected]726985e22009-06-18 21:09:28336static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
337 WebVector<WebURL> urls;
338 ds->redirectChain(urls);
339 result->reserve(urls.size());
340 for (size_t i = 0; i < urls.size(); ++i)
341 result->push_back(urls[i]);
342}
343
[email protected]007733c2011-11-17 00:34:07344// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44345// the AltErrorPageResourceFetcher is reset.
346static void StopAltErrorPageFetcher(WebDataSource* data_source) {
347 if (data_source) {
[email protected]007733c2011-11-17 00:34:07348 DocumentState* document_state = DocumentState::FromDataSource(data_source);
349 if (document_state)
350 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44351 }
352}
353
[email protected]007733c2011-11-17 00:34:07354static bool IsReload(const ViewMsg_Navigate_Params& params) {
355 return
356 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
357 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
358}
359
[email protected]b9fd01ba2012-02-28 01:50:40360static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59361 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15362 const WebURLRequest& request) {
363 return request.extraData() ?
364 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59365 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15366}
367
[email protected]b9fd01ba2012-02-28 01:50:40368static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
369 const WebURLResponse& response) {
370 return static_cast<WebURLResponseExtraDataImpl*>(
371 response.extraData());
372}
373
[email protected]2149cc622012-02-14 01:12:12374NOINLINE static void CrashIntentionally() {
375 // NOTE(shess): Crash directly rather than using NOTREACHED() so
376 // that the signature is easier to triage in crash reports.
377 volatile int* zero = NULL;
378 *zero = 0;
379}
380
[email protected]8bf1048012012-02-08 01:22:18381static void MaybeHandleDebugURL(const GURL& url) {
382 if (!url.SchemeIs(chrome::kChromeUIScheme))
383 return;
384 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12385 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18386 } else if (url == GURL(chrome::kChromeUIKillURL)) {
387 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
388 } else if (url == GURL(chrome::kChromeUIHangURL)) {
389 for (;;) {
390 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
391 }
392 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
393 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
394 }
395}
396
[email protected]fd3238af2012-05-22 18:55:30397// Returns false unless this is a top-level navigation.
398static bool IsTopLevelNavigation(WebFrame* frame) {
399 return frame->parent() == NULL;
400}
401
402// Returns false unless this is a top-level navigation that crosses origins.
403static bool IsNonLocalTopLevelNavigation(const GURL& url,
404 WebFrame* frame,
405 WebNavigationType type) {
406 if (!IsTopLevelNavigation(frame))
407 return false;
408
409 // Navigations initiated within Webkit are not sent out to the external host
410 // in the following cases.
411 // 1. The url scheme is not http/https
412 // 2. The origin of the url and the opener is the same in which case the
413 // opener relationship is maintained.
414 // 3. Reloads/form submits/back forward navigations
415 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
416 return false;
417
418 // Not interested in reloads/form submits/resubmits/back forward navigations.
419 if (type != WebKit::WebNavigationTypeReload &&
420 type != WebKit::WebNavigationTypeFormSubmitted &&
421 type != WebKit::WebNavigationTypeFormResubmitted &&
422 type != WebKit::WebNavigationTypeBackForward) {
423 // The opener relationship between the new window and the parent allows the
424 // new window to script the parent and vice versa. This is not allowed if
425 // the origins of the two domains are different. This can be treated as a
426 // top level navigation and routed back to the host.
427 WebKit::WebFrame* opener = frame->opener();
428 if (!opener) {
429 return true;
430 }
431
432 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
433 return true;
434 }
435 return false;
436}
437
initial.commit09911bf2008-07-26 23:55:29438///////////////////////////////////////////////////////////////////////////////
439
[email protected]310ebd6302011-10-10 19:06:28440struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23441 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47442 WebFileChooserCompletion* c)
443 : params(p),
444 completion(c) {
445 }
[email protected]8caadeb2011-11-22 02:45:23446 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47447 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
448};
449
[email protected]217690d2012-01-27 07:33:11450namespace {
451
452class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
453 public:
[email protected]82114f52012-03-20 22:53:41454 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11455 : webwidget_(webwidget) {}
456
457 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
458 if (succeeded)
459 webwidget_->didAcquirePointerLock();
460 else
461 webwidget_->didNotAcquirePointerLock();
462 }
463
464 virtual void OnMouseLockLost() OVERRIDE {
465 webwidget_->didLosePointerLock();
466 }
467
468 virtual bool HandleMouseLockedInputEvent(
469 const WebKit::WebMouseEvent &event) OVERRIDE {
470 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
471 return false;
472 }
473
474 private:
475 WebKit::WebWidget* webwidget_;
476};
477
[email protected]86cd9472012-02-03 19:51:05478int64 ExtractPostId(const WebHistoryItem& item) {
479 if (item.isNull())
480 return -1;
481
482 if (item.httpBody().isNull())
483 return -1;
484
485 return item.httpBody().identifier();
486}
487
[email protected]217690d2012-01-27 07:33:11488} // namespace
489
[email protected]daf82f82011-10-31 22:35:31490RenderViewImpl::RenderViewImpl(
491 gfx::NativeViewId parent_hwnd,
492 int32 opener_id,
493 const content::RendererPreferences& renderer_prefs,
494 const WebPreferences& webkit_prefs,
495 SharedRenderViewCounter* counter,
496 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56497 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31498 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46499 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44500 bool is_renderer_created,
501 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41502 int32 next_page_id,
[email protected]468e4902012-05-23 01:49:31503 content::GuestToEmbedderChannel* guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29504 AccessibilityMode accessibility_mode)
[email protected]dfec1952012-06-01 15:39:22505 : RenderWidget(WebKit::WebPopupTypeNone, swapped_out),
[email protected]676126f72011-01-15 00:03:51506 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02507 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09508 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02509 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24510 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21511 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02512 opened_by_user_gesture_(true),
513 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24514 page_id_(-1),
515 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46516 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00517 history_list_offset_(-1),
518 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02519 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55520 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31521 cached_is_main_frame_pinned_to_left_(false),
522 cached_is_main_frame_pinned_to_right_(false),
523 cached_has_main_frame_horizontal_scrollbar_(false),
524 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]05a980d7a2012-02-07 22:16:42525 context_has_swapbuffers_complete_callback_(false),
526 queried_for_swapbuffers_complete_callback_(false),
[email protected]d0fb8a72012-03-10 18:54:52527 context_is_web_graphics_context_3d_command_buffer_impl_(false),
[email protected]3354d3e2010-06-10 19:53:02528 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51529 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02530 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34531 speech_recognition_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51532 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51533 media_stream_dispatcher_(NULL),
[email protected]1bc65a42012-04-23 09:31:25534 media_stream_impl_(NULL),
[email protected]cae8c8492011-03-03 11:12:18535 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41536 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32537 renderer_accessibility_(NULL),
[email protected]7e9c5bb02012-05-14 13:58:31538 java_bridge_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11539 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08540 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18541 handling_select_range_(false),
542#if defined(OS_WIN)
543 focused_plugin_id_(-1),
544#endif
[email protected]468e4902012-05-23 01:49:31545 guest_to_embedder_channel_(guest_to_embedder_channel),
546 guest_pp_instance_(0),
547 guest_uninitialized_context_(NULL),
[email protected]3e3c4522012-04-13 21:16:29548 accessibility_mode_(accessibility_mode),
[email protected]ef5e98e2011-12-06 09:49:18549 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51550 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56551 surface_id_ = surface_id;
[email protected]14392a52012-05-02 20:28:44552 if (opener_id != MSG_ROUTING_NONE && is_renderer_created)
[email protected]676126f72011-01-15 00:03:51553 opener_id_ = opener_id;
554
[email protected]74ce1ad2011-12-16 21:51:46555 // Ensure we start with a valid next_page_id_ from the browser.
556 DCHECK_GE(next_page_id_, 0);
557
[email protected]21b3a6ae2011-11-30 00:45:29558#if defined(ENABLE_NOTIFICATIONS)
559 notification_provider_ = new NotificationProvider(this);
560#else
561 notification_provider_ = NULL;
562#endif
563
[email protected]11fee2332011-03-29 20:36:35564 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11565 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35566
[email protected]676126f72011-01-15 00:03:51567 if (counter) {
568 shared_popup_counter_ = counter;
[email protected]14392a52012-05-02 20:28:44569 // Only count this if it isn't swapped out upon creation.
570 if (!swapped_out)
571 shared_popup_counter_->data++;
[email protected]676126f72011-01-15 00:03:51572 decrement_shared_popup_at_destruction_ = true;
573 } else {
574 shared_popup_counter_ = new SharedRenderViewCounter(0);
575 decrement_shared_popup_at_destruction_ = false;
576 }
577
[email protected]380244092011-10-07 17:26:27578 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51579 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47580 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51581 AddRef();
582
583 // If this is a popup, we must wait for the CreatingNew_ACK message before
584 // completing initialization. Otherwise, we can finish it now.
[email protected]468e4902012-05-23 01:49:31585 if (!guest_to_embedder_channel && opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51586 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55587 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51588 }
589
[email protected]34c61bd52011-05-02 19:38:33590 g_view_map.Get().insert(std::make_pair(webview(), this));
591 webkit_preferences_.Apply(webview());
592 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35593 if (!frame_name.empty())
594 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33595 webview()->settings()->setMinimumTimerInterval(
596 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
597 webkit_glue::kForegroundTabTimerInterval);
598
599 OnSetRendererPrefs(renderer_prefs);
600
[email protected]676126f72011-01-15 00:03:51601 host_window_ = parent_hwnd;
602
[email protected]4fb0f202012-05-30 22:44:53603#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:51604 if (!p2p_socket_dispatcher_)
605 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]735873d2012-01-25 23:31:02606 if (!media_stream_dispatcher_)
607 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32608#endif
[email protected]735873d2012-01-25 23:31:02609
[email protected]8f6a3b852011-07-19 16:48:56610 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32611#if defined(OS_MACOSX)
612 new TextInputClientObserver(this);
613#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56614
[email protected]2d7b82c2012-06-01 05:57:50615#if defined(OS_ANDROID)
616 media_player_manager_.reset(
617 new webkit_media::WebMediaPlayerManagerAndroid());
618#endif
619
[email protected]217690d2012-01-27 07:33:11620 // The next group of objects all implement RenderViewObserver, so are deleted
621 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41622 devtools_agent_ = new DevToolsAgent(this);
[email protected]3e3c4522012-04-13 21:16:29623 renderer_accessibility_ = new RendererAccessibility(this, accessibility_mode);
[email protected]89054502012-06-03 10:29:24624 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40625 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32626
[email protected]1784b2f2011-11-24 10:53:48627 new IdleUserDetector(this);
628
[email protected]766a7082012-02-03 23:39:15629 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
630 if (command_line.HasSwitch(switches::kDomAutomationController))
631 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
632
[email protected]5b52cd2f712012-03-28 02:12:48633 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05634
[email protected]e48869a2011-04-01 19:56:03635 content::GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44636
637 // If we have an opener_id but we weren't created by a renderer, then
638 // it's the browser asking us to set our opener to another RenderView.
639 // TODO(creis): This doesn't yet handle openers that are subframes.
640 if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) {
[email protected]f546640b2012-05-15 00:03:49641 RenderViewImpl* opener_view = FromRoutingID(opener_id);
642 if (opener_view)
643 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44644 }
645
646 // If we are initially swapped out, navigate to kSwappedOutURL.
647 // This ensures we are in a unique origin that others cannot script.
648 if (is_swapped_out_)
649 NavigateToSwappedOutURL();
initial.commit09911bf2008-07-26 23:55:29650}
651
[email protected]310ebd6302011-10-10 19:06:28652RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03653 history_page_ids_.clear();
654
[email protected]0aa55312008-10-17 21:53:08655 if (decrement_shared_popup_at_destruction_)
656 shared_popup_counter_->data--;
657
[email protected]a1128322009-10-06 18:38:46658 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47659 while (!file_chooser_completions_.empty()) {
660 if (file_chooser_completions_.front()->completion) {
661 file_chooser_completions_.front()->completion->didChooseFile(
662 WebVector<WebString>());
663 }
664 file_chooser_completions_.pop_front();
665 }
[email protected]a1128322009-10-06 18:38:46666
[email protected]83dde542009-09-11 20:59:55667#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11668 // Destroy all fake plugin window handles on the browser side.
669 while (!fake_plugin_window_handles_.empty()) {
670 // Make sure no NULL plugin window handles were inserted into this list.
671 DCHECK(*fake_plugin_window_handles_.begin());
672 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
673 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
674 }
[email protected]83dde542009-09-11 20:59:55675#endif
[email protected]98324892009-09-09 21:16:05676
[email protected]60c42a8c72009-10-09 04:08:59677#ifndef NDEBUG
678 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49679 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59680 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
681 DCHECK_NE(this, it->second) << "Failed to call Close?";
682#endif
[email protected]676126f72011-01-15 00:03:51683
[email protected]310ebd6302011-10-10 19:06:28684 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51685 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59686}
687
688/*static*/
[email protected]310ebd6302011-10-10 19:06:28689RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31690 ViewMap* views = g_view_map.Pointer();
691 ViewMap::iterator it = views->find(webview);
692 return it == views->end() ? NULL : it->second;
693}
694
695/*static*/
696content::RenderView*
697 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28698 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31699}
700
701/*static*/
702void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49703 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59704 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
705 if (!visitor->Visit(it->second))
706 return;
707 }
708}
709
710/*static*/
[email protected]310ebd6302011-10-10 19:06:28711RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15712 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08713 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31714 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08715 const WebPreferences& webkit_prefs,
716 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34717 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56718 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26719 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46720 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44721 bool is_renderer_created,
722 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41723 int32 next_page_id,
[email protected]468e4902012-05-23 01:49:31724 content::GuestToEmbedderChannel* guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29725 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29726 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28727 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51728 parent_hwnd,
729 opener_id,
730 renderer_prefs,
731 webkit_prefs,
732 counter,
733 routing_id,
[email protected]9f4f3322012-01-18 22:29:56734 surface_id,
[email protected]676126f72011-01-15 00:03:51735 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46736 frame_name,
[email protected]14392a52012-05-02 20:28:44737 is_renderer_created,
738 swapped_out,
[email protected]6fd35b72012-03-01 19:46:41739 next_page_id,
[email protected]468e4902012-05-23 01:49:31740 guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29741 accessibility_mode);
initial.commit09911bf2008-07-26 23:55:29742}
743
[email protected]50da23d02012-04-13 17:47:48744WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
745 WebPeerConnectionHandlerClient* client) {
[email protected]273558fb2012-01-12 15:03:51746 EnsureMediaStreamImpl();
[email protected]1bc65a42012-04-23 09:31:25747 if (!media_stream_impl_)
[email protected]5b87e782012-02-09 18:19:32748 return NULL;
[email protected]273558fb2012-01-12 15:03:51749 return media_stream_impl_->CreatePeerConnectionHandler(client);
750}
751
[email protected]50da23d02012-04-13 17:47:48752WebPeerConnection00Handler* RenderViewImpl::CreatePeerConnectionHandlerJsep(
753 WebPeerConnection00HandlerClient* client) {
754 EnsureMediaStreamImpl();
[email protected]1bc65a42012-04-23 09:31:25755 if (!media_stream_impl_)
[email protected]50da23d02012-04-13 17:47:48756 return NULL;
757 return media_stream_impl_->CreatePeerConnectionHandlerJsep(client);
758}
759
[email protected]310ebd6302011-10-10 19:06:28760void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51761 observers_.AddObserver(observer);
762}
763
[email protected]310ebd6302011-10-10 19:06:28764void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
765 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51766 observers_.RemoveObserver(observer);
767}
768
[email protected]310ebd6302011-10-10 19:06:28769WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26770 return static_cast<WebKit::WebView*>(webwidget());
771}
772
[email protected]310ebd6302011-10-10 19:06:28773void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40774 if (!enabled) {
775 load_progress_tracker_.reset(NULL);
776 return;
777 }
778 if (load_progress_tracker_ == NULL)
779 load_progress_tracker_.reset(new LoadProgressTracker(this));
780}
781
[email protected]7900bfdb2012-05-24 19:31:24782content::GuestToEmbedderChannel*
783 RenderViewImpl::GetGuestToEmbedderChannel() const {
784 return guest_to_embedder_channel_;
785}
786
787void RenderViewImpl::SetGuestToEmbedderChannel(
788 content::GuestToEmbedderChannel* channel) {
789 guest_to_embedder_channel_ = channel;
790}
791
[email protected]310ebd6302011-10-10 19:06:28792void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51793 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29794}
795
[email protected]310ebd6302011-10-10 19:06:28796void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26797 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30798 // If the renderer is visible, set initial visibility and focus state.
799 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34800#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30801 delegate->SetContainerVisibility(true);
802 if (webview() && webview()->isActive())
803 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34804#endif
[email protected]49232292010-09-03 19:07:30805 }
[email protected]784ea1ab2010-09-18 00:02:34806 // Plugins start assuming the content has focus (so that they work in
807 // environments where RenderView isn't hosting them), so we always have to
808 // set the initial state. See webplugin_delegate_impl.h for details.
809 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26810}
811
[email protected]310ebd6302011-10-10 19:06:28812void RenderViewImpl::UnregisterPluginDelegate(
813 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26814 plugin_delegates_.erase(delegate);
815}
[email protected]d8fd6fa2010-02-01 15:54:26816
[email protected]310ebd6302011-10-10 19:06:28817bool RenderViewImpl::GetPluginInfo(const GURL& url,
818 const GURL& page_url,
819 const std::string& mime_type,
820 webkit::WebPluginInfo* plugin_info,
821 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08822 bool found = false;
823 Send(new ViewHostMsg_GetPluginInfo(
824 routing_id_, url, page_url, mime_type, &found, plugin_info,
825 actual_mime_type));
826 return found;
827}
828
[email protected]7a1ec28a2012-03-28 21:10:24829void RenderViewImpl::TransferActiveWheelFlingAnimation(
830 const WebKit::WebActiveWheelFlingParameters& params) {
831 if (webview())
832 webview()->transferActiveWheelFlingAnimation(params);
833}
834
[email protected]310ebd6302011-10-10 19:06:28835bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27836 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27837 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41838 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26839
[email protected]676126f72011-01-15 00:03:51840 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
841 RenderViewObserver* observer;
842 while ((observer = it.GetNext()) != NULL)
843 if (observer->OnMessageReceived(message))
844 return true;
[email protected]b2abac72009-02-26 12:39:28845
[email protected]a95986a82010-12-24 06:19:28846 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40847 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28848 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29849 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
850 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56851 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29852 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
853 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
854 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
855 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27856#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35857 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27858#endif
initial.commit09911bf2008-07-26 23:55:29859 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15860 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29861 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
862 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
863 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08864 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29865 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15866 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29867 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49868 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
869 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17870 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17871 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41872 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54873 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
874 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29875 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18876 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
877 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29878 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:49879 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:48880 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55881 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
882 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
883 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
884 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
885 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
886 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
887 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45888 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40889 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29890 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19891 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
892 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29893 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
894 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
895 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51896 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
897 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29898 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04899 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15900 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29901 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
902 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08903 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
904 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00905 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16906 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14907 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25908 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
909 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47910 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34911 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10912 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
913 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51914 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56915 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:17916 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
917 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:36918 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34919 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:12920 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
921 OnSetNavigationStartTime)
[email protected]6ce7abc52010-02-02 18:40:14922#if defined(OS_MACOSX)
923 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13924 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13925 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
926 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14927#endif
[email protected]446705872009-09-10 07:22:48928 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33929 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33930 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
931 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24932 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42933 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
934 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19935 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
936 OnGetAllSavableResourceLinksForCurrentPage)
937 IPC_MESSAGE_HANDLER(
938 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
939 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08940#if defined(OS_MACOSX)
941 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
[email protected]24d2b172012-05-26 00:54:12942#elif defined(OS_ANDROID)
943 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
[email protected]caf706f2010-10-26 17:54:08944#endif
[email protected]521b2482011-01-15 00:10:10945 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51946 // TODO(viettrungluu): Move to a separate message filter.
[email protected]54ca3ca892011-06-07 21:14:54947#if defined(OS_MACOSX)
948 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
949#endif
[email protected]9e1ad4b2011-08-14 16:49:19950 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
951 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18952 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51953 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19954
initial.commit09911bf2008-07-26 23:55:29955 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28956 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29957 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40958
959 if (!msg_is_ok) {
960 // The message had a handler, but its deserialization failed.
961 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28962 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40963 }
964
[email protected]a95986a82010-12-24 06:19:28965 return handled;
initial.commit09911bf2008-07-26 23:55:29966}
967
[email protected]310ebd6302011-10-10 19:06:28968void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]7900bfdb2012-05-24 19:31:24969 // If we don't have guest-to-embedder channel associated with this RenderView
970 // but we need one, grab one now.
971 if (!params.embedder_channel_name.empty() && !GetGuestToEmbedderChannel()) {
972 content::GuestToEmbedderChannel* embedder_channel =
973 RenderThreadImpl::current()->browser_plugin_channel_manager()->
974 GetChannelByName(params.embedder_channel_name);
975 DCHECK(embedder_channel);
976 SetGuestToEmbedderChannel(embedder_channel);
977 host_window_set_ = false;
978 // TODO(fsamuel): This is test code. Need to find a better way to tell
979 // a WebView to drop its context. This needs to change in
980 // GuestToEmbedderChannel::OnContextLost.
981 GetWebView()->loseCompositorContext(1);
982 RenderThreadImpl::current()->browser_plugin_channel_manager()->
983 ReportChannelToEmbedder(this,
984 embedder_channel->embedder_channel_handle(),
985 params.embedder_channel_name,
986 params.embedder_container_id);
987 }
[email protected]8bf1048012012-02-08 01:22:18988 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:29989 if (!webview())
990 return;
991
[email protected]440a0e52011-09-13 17:38:58992 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
993
[email protected]007733c2011-11-17 00:34:07994 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03995
996 // If this is a stale back/forward (due to a recent navigation the browser
997 // didn't know about), ignore it.
998 if (IsBackForwardToStaleEntry(params, is_reload))
999 return;
1000
[email protected]992db4c2011-05-12 15:37:151001 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281002 if (is_swapped_out_) {
1003 // We marked the view as hidden when swapping the view out, so be sure to
1004 // reset the visibility state before navigating to the new URL.
1005 webview()->setVisibilityState(visibilityState(), false);
[email protected]992db4c2011-05-12 15:37:151006 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281007 }
[email protected]992db4c2011-05-12 15:37:151008
[email protected]3cc72b12010-03-18 23:03:001009 history_list_offset_ = params.current_history_list_offset;
1010 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031011 if (history_list_length_ >= 0)
1012 history_page_ids_.resize(history_list_length_, -1);
1013 if (params.pending_history_list_offset >= 0 &&
1014 params.pending_history_list_offset < history_list_length_)
1015 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001016
[email protected]38b592902011-04-16 02:08:421017 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291018
[email protected]26aa0482009-09-30 16:55:271019 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451020 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291021 // We cannot reload if we do not have any history state. This happens, for
1022 // example, when recovering from a crash. Our workaround here is a bit of
1023 // a hack since it means that reload after a crashed tab does not cause an
1024 // end-to-end cache validation.
1025 is_reload = false;
1026 }
1027
[email protected]007733c2011-11-17 00:34:071028 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
1029 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:501030
[email protected]04d3c6e2009-05-22 17:00:131031 // If we are reloading, then WebKit will use the history state of the current
1032 // page, so we should just ignore any given history state. Otherwise, if we
1033 // have history state, then we need to navigate to it, which corresponds to a
1034 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551035 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:291036 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021037 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:291038 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551039 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131040 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581041 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:451042 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171043 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131044 } else {
1045 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281046 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291047
[email protected]e6f546c32009-07-01 17:12:551048 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231049 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131050
[email protected]dd7daa82009-08-10 05:46:451051 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551052 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131053
[email protected]445e1042011-12-03 21:03:151054 if (params.referrer.url.is_valid()) {
1055 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1056 params.referrer.policy,
1057 params.url,
1058 WebString::fromUTF8(params.referrer.url.spec()));
1059 if (!referrer.isEmpty())
1060 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281061 }
[email protected]04d3c6e2009-05-22 17:00:131062
[email protected]52c68652010-12-07 17:47:041063 if (!params.extra_headers.empty()) {
1064 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1065 params.extra_headers.end(), "\n");
1066 i.GetNext(); ) {
1067 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1068 WebString::fromUTF8(i.values()));
1069 }
1070 }
[email protected]dd7daa82009-08-10 05:46:451071 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501072 }
1073
[email protected]77f17a82009-05-21 04:42:541074 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071075 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291076}
1077
[email protected]310ebd6302011-10-10 19:06:281078bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031079 const ViewMsg_Navigate_Params& params,
1080 bool is_reload) {
1081 // Make sure this isn't a back/forward to an entry we have already cropped
1082 // or replaced from our history, before the browser knew about it. If so,
1083 // a new navigation has committed in the mean time, and we can ignore this.
1084 bool is_back_forward = !is_reload && !params.state.empty();
1085
1086 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1087 // restoring from a previous session. We'll update our state in OnNavigate.
1088 if (!is_back_forward || history_list_length_ <= 0)
1089 return false;
1090
1091 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1092
1093 // Check for whether the forward history has been cropped due to a recent
1094 // navigation the browser didn't know about.
1095 if (params.pending_history_list_offset >= history_list_length_)
1096 return true;
1097
1098 // Check for whether this entry has been replaced with a new one.
1099 int expected_page_id =
1100 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441101 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1102 if (params.page_id < expected_page_id)
1103 return true;
1104
1105 // Otherwise we've removed an earlier entry and should have shifted all
1106 // entries left. For now, it's ok to lazily update the list.
1107 // TODO(creis): Notify all live renderers when we remove entries from
1108 // the front of the list, so that we don't hit this case.
1109 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1110 }
[email protected]d466b8a2011-07-15 21:48:031111
1112 return false;
1113}
1114
initial.commit09911bf2008-07-26 23:55:291115// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281116void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441117 if (webview()) {
1118 WebFrame* main_frame = webview()->mainFrame();
1119 // Stop the alt error page fetcher. If we let it continue it may complete
1120 // and cause RenderViewHostManager to swap to this RenderView, even though
1121 // it may no longer be active.
1122 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1123 StopAltErrorPageFetcher(main_frame->dataSource());
1124 main_frame->stopLoading();
1125 }
initial.commit09911bf2008-07-26 23:55:291126}
1127
[email protected]ecbf10d2010-02-18 13:03:291128// Reload current focused frame.
1129// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281130void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291131 if (webview() && webview()->focusedFrame()) {
1132 // We always obey the cache (ignore_cache=false) here.
1133 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1134 // a cache-ignoring reload of the frame.
1135 webview()->focusedFrame()->reload(false);
1136 }
[email protected]1dda4022010-01-28 18:24:561137}
1138
[email protected]310ebd6302011-10-10 19:06:281139void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271140 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291141}
1142
[email protected]310ebd6302011-10-10 19:06:281143void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251144 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271145 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251146 return;
1147
[email protected]26aa0482009-09-30 16:55:271148 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451149 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251150}
1151
[email protected]310ebd6302011-10-10 19:06:281152void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291153 // Check if there is a targeturl waiting to be sent.
1154 if (target_url_status_ == TARGET_PENDING) {
1155 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1156 pending_target_url_));
1157 }
1158
1159 target_url_status_ = TARGET_NONE;
1160}
1161
[email protected]310ebd6302011-10-10 19:06:281162void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291163 if (!webview())
1164 return;
1165
[email protected]26aa0482009-09-30 16:55:271166 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291167}
1168
[email protected]310ebd6302011-10-10 19:06:281169void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291170 if (!webview())
1171 return;
1172
[email protected]26aa0482009-09-30 16:55:271173 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291174}
1175
[email protected]310ebd6302011-10-10 19:06:281176void RenderViewImpl::OnCut() {
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("Cut"));
initial.commit09911bf2008-07-26 23:55:291181}
1182
[email protected]310ebd6302011-10-10 19:06:281183void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291184 if (!webview())
1185 return;
1186
[email protected]f6b1856b2011-06-29 22:02:531187 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1188 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291189}
1190
[email protected]c0cc3092009-09-12 08:27:271191#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281192void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351193 if (!webview())
1194 return;
1195
1196 // Since the find pasteboard supports only plain text, this can be simpler
1197 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271198 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351199 if (frame->hasSelection()) {
1200 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271201 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171202 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351203 }
[email protected]a954bf72009-09-12 07:30:351204}
[email protected]c0cc3092009-09-12 08:27:271205#endif
[email protected]a954bf72009-09-12 07:30:351206
[email protected]310ebd6302011-10-10 19:06:281207void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291208 if (!webview())
1209 return;
1210
[email protected]26aa0482009-09-30 16:55:271211 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291212}
1213
[email protected]44bf7002011-10-16 02:46:151214void RenderViewImpl::OnPasteAndMatchStyle() {
1215 if (!webview())
1216 return;
1217
1218 webview()->focusedFrame()->executeCommand(
1219 WebString::fromUTF8("PasteAndMatchStyle"));
1220}
1221
[email protected]310ebd6302011-10-10 19:06:281222void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291223 if (!webview())
1224 return;
1225
[email protected]1ff7a032010-02-03 02:46:031226 WebFrame* frame = webview()->focusedFrame();
1227 if (!frame->hasSelection())
1228 frame->selectWordAroundCaret();
1229 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291230}
1231
[email protected]310ebd6302011-10-10 19:06:281232void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291233 if (!webview())
1234 return;
1235
[email protected]26aa0482009-09-30 16:55:271236 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291237}
1238
[email protected]310ebd6302011-10-10 19:06:281239void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291240 if (!webview())
1241 return;
1242
[email protected]26aa0482009-09-30 16:55:271243 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221244 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291245}
1246
[email protected]310ebd6302011-10-10 19:06:281247void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1248 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081249 if (!webview())
1250 return;
1251
1252 handling_select_range_ = true;
1253 webview()->focusedFrame()->selectRange(start, end);
1254 handling_select_range_ = false;
1255}
1256
[email protected]310ebd6302011-10-10 19:06:281257void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1258 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191259 DCHECK(history_length >= 0);
1260 DCHECK(history_list_offset_ == history_list_length_ - 1);
1261 DCHECK(minimum_page_id >= -1);
1262
1263 // Generate the new list.
1264 std::vector<int32> new_history_page_ids(history_length, -1);
1265 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1266 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1267 continue;
1268 new_history_page_ids.push_back(history_page_ids_[i]);
1269 }
1270 new_history_page_ids.swap(history_page_ids_);
1271
1272 // Update indexes.
1273 history_list_length_ = history_page_ids_.size();
1274 history_list_offset_ = history_list_length_ - 1;
1275}
1276
1277
[email protected]310ebd6302011-10-10 19:06:281278void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291279 if (!webview())
1280 return;
[email protected]26aa0482009-09-30 16:55:271281 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291282}
1283
[email protected]54ca3ca892011-06-07 21:14:541284#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281285void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331286 if (!webview())
1287 return;
1288 if (in_live_resize)
1289 webview()->willStartLiveResize();
1290 else
1291 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541292}
1293#endif
1294
[email protected]310ebd6302011-10-10 19:06:281295void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1296 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091297 WebKit::WebNode node = GetFocusedNode();
1298 if (!node.isNull()) {
1299 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191300 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511301 }
1302}
1303
initial.commit09911bf2008-07-26 23:55:291304///////////////////////////////////////////////////////////////////////////////
1305
1306// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281307void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451308 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291309 DCHECK(ds);
1310
[email protected]726985e22009-06-18 21:09:281311 const WebURLRequest& request = ds->request();
1312 const WebURLRequest& original_request = ds->originalRequest();
1313 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291314
[email protected]007733c2011-11-17 00:34:071315 DocumentState* document_state = DocumentState::FromDataSource(ds);
1316 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291317
1318 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281319 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291320 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051321 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291322 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071323 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191324 params.socket_address.set_host(response.remoteIPAddress().utf8());
1325 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031326 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091327 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071328 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291329 // SSL state specified in the request takes precedence over the one in the
1330 // response.
1331 // So far this is only intended for error pages that are not expected to be
1332 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281333 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071334 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291335 } else {
[email protected]726985e22009-06-18 21:09:281336 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291337 }
1338
1339 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311340 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291341
[email protected]5f9b8712011-11-23 08:55:571342 if (frame->document().baseURL() != params.url)
1343 params.base_url = frame->document().baseURL();
1344
[email protected]726985e22009-06-18 21:09:281345 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241346 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041347 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291348
[email protected]007733c2011-11-17 00:34:071349 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351350 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071351 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291352
1353 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071354 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291355 if (password_form_data)
1356 params.password_form = *password_form_data;
1357
1358 params.gesture = navigation_gesture_;
1359 navigation_gesture_ = NavigationGestureUnknown;
1360
[email protected]0f38dc4552011-02-25 11:24:001361 // Make navigation state a part of the FrameNavigate message so that commited
1362 // entry had it at all times.
1363 const WebHistoryItem& item = frame->currentHistoryItem();
1364 if (!item.isNull()) {
1365 params.content_state = webkit_glue::HistoryItemToString(item);
1366 } else {
1367 params.content_state =
1368 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1369 }
1370
[email protected]dd7daa82009-08-10 05:46:451371 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291372 // Top-level navigation.
1373
[email protected]b75b8292010-10-01 07:28:251374 // Set zoom level, but don't do it for full-page plugin since they don't use
1375 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011376 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541377 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251378 if (webview()->mainFrame()->document().isPluginDocument()) {
1379 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251380 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251381 } else {
1382 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251383 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251384 }
1385
[email protected]f85f0702010-01-30 09:31:011386 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511387 // This zoom level was merely recorded transiently for this load. We can
1388 // erase it now. If at some point we reload this page, the browser will
1389 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011390 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511391 }
1392
[email protected]b75b8292010-10-01 07:28:251393 // Reset the zoom limits in case a plugin had changed them previously. This
1394 // will also call us back which will cause us to send a message to
[email protected]770005b2012-04-16 15:58:131395 // update WebContentsImpl.
[email protected]b75b8292010-10-01 07:28:251396 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011397 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1398 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251399
initial.commit09911bf2008-07-26 23:55:291400 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551401 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291402
[email protected]daa8c58e2009-06-15 17:21:101403 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581404 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291405 // If the main frame does a load, it should not be reported as a subframe
1406 // navigation. This can occur in the following case:
1407 // 1. You're on a site with frames.
1408 // 2. You do a subframe navigation. This is stored with transition type
1409 // MANUAL_SUBFRAME.
1410 // 3. You navigate to some non-frame site, say, google.com.
1411 // 4. You navigate back to the page from step 2. Since it was initially
1412 // MANUAL_SUBFRAME, it will be that same transition type here.
1413 // We don't want that, because any navigation that changes the toplevel
1414 // frame should be tracked as a toplevel navigation (this allows us to
1415 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581416 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291417 }
1418
initial.commit09911bf2008-07-26 23:55:291419 // If we have a valid consumed client redirect source,
1420 // the page contained a client redirect (meta refresh, document.loc...),
1421 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151422 if (completed_client_redirect_src_.url.is_valid()) {
1423 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291424 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581425 params.transition = static_cast<content::PageTransition>(
1426 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291427 } else {
1428 // Bug 654101: the referrer will be empty on https->http transitions. It
1429 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151430 params.referrer = Referrer(GURL(
1431 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:591432 GetReferrerPolicyFromRequest(frame, original_request));
initial.commit09911bf2008-07-26 23:55:291433 }
1434
[email protected]726985e22009-06-18 21:09:281435 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051436 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291437 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051438 params.post_id = ExtractPostId(item);
1439 }
initial.commit09911bf2008-07-26 23:55:291440
[email protected]c2a797d2009-09-21 16:46:321441 // Save some histogram data so we can compute the average memory used per
1442 // page load of the glyphs.
1443 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1444 webkit_glue::GetGlyphPageCount());
1445
[email protected]15cf526b2010-02-12 06:33:491446 // This message needs to be sent before any of allowScripts(),
1447 // allowImages(), allowPlugins() is called for the new page, so that when
1448 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1449 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291450 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1451 } else {
1452 // Subframe navigation: the type depends on whether this navigation
1453 // generated a new session history entry. When they do generate a session
1454 // history entry, it means the user initiated the navigation and we should
1455 // mark it as such. This test checks if this is the first time UpdateURL
1456 // has been called since WillNavigateToURL was called to initiate the load.
1457 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581458 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291459 else
[email protected]2905f742011-10-13 03:51:581460 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291461
initial.commit09911bf2008-07-26 23:55:291462 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1463 }
1464
1465 last_page_id_sent_to_browser_ =
1466 std::max(last_page_id_sent_to_browser_, page_id_);
1467
1468 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101469 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581470 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291471}
1472
1473// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281474void RenderViewImpl::UpdateTitle(WebFrame* frame,
1475 const string16& title,
1476 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461477 // Ignore all but top level navigations.
1478 if (frame->parent())
1479 return;
1480
1481 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1482 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1483 title_direction));
initial.commit09911bf2008-07-26 23:55:291484}
1485
[email protected]310ebd6302011-10-10 19:06:281486void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1487 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291488 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271489 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291490 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301491 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291492 last_encoding_name_ = encoding_name;
1493
[email protected]e38f40152008-09-12 23:08:301494 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291495 }
1496}
1497
[email protected]e15f680732010-11-23 22:30:201498// Sends the last committed session history state to the browser so it will be
1499// saved before we navigate to a new page. This must be called *before* the
1500// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281501void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291502 // If we have a valid page ID at this point, then it corresponds to the page
1503 // we are navigating away from. Otherwise, this is the first navigation, so
1504 // there is no past session history to record.
1505 if (page_id_ == -1)
1506 return;
1507
[email protected]ca948a22009-06-25 19:36:171508 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271509 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051510 SendUpdateState(item);
1511}
1512
1513void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171514 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291515 return;
[email protected]ca948a22009-06-25 19:36:171516
[email protected]285f4bb82012-04-17 15:57:281517 // Don't send state updates for content::kSwappedOutURL.
1518 if (item.urlString() == WebString::fromUTF8(content::kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051519 return;
1520
[email protected]ca948a22009-06-25 19:36:171521 Send(new ViewHostMsg_UpdateState(
1522 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291523}
1524
[email protected]310ebd6302011-10-10 19:06:281525void RenderViewImpl::OpenURL(WebFrame* frame,
1526 const GURL& url,
[email protected]445e1042011-12-03 21:03:151527 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281528 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171529 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581530 routing_id_,
1531 url,
1532 referrer,
1533 NavigationPolicyToDisposition(policy),
1534 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171535}
1536
[email protected]79dbc662009-09-04 05:42:511537// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291538
[email protected]310ebd6302011-10-10 19:06:281539void RenderViewImpl::LoadNavigationErrorPage(
1540 WebFrame* frame,
1541 const WebURLRequest& failed_request,
1542 const WebURLError& error,
1543 const std::string& html,
1544 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581545 std::string alt_html;
1546 const std::string* error_html;
1547
1548 if (!html.empty()) {
1549 error_html = &html;
1550 } else {
1551 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1552 failed_request, error, &alt_html, NULL);
1553 error_html = &alt_html;
1554 }
1555
1556 frame->loadHTMLString(*error_html,
[email protected]285f4bb82012-04-17 15:57:281557 GURL(content::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251558 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551559 replace);
initial.commit09911bf2008-07-26 23:55:291560}
1561
[email protected]be2510c02012-05-28 14:52:141562bool RenderViewImpl::RunJavaScriptMessage(content::JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281563 const string16& message,
1564 const string16& default_value,
1565 const GURL& frame_url,
1566 string16* result) {
initial.commit09911bf2008-07-26 23:55:291567 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411568 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291569 if (!result)
1570 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291571
[email protected]12636df2009-09-28 22:32:211572 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1573 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291574 return success;
1575}
1576
[email protected]310ebd6302011-10-10 19:06:281577bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571578 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1579 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1580 // it is particularly important that we do not call willEnterModalLoop as
1581 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441582 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1583 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571584
1585 message->EnableMessagePumping(); // Runs a nested message loop.
1586 return Send(message);
1587}
1588
[email protected]48c9cf2d2009-09-16 16:47:521589// WebKit::WebViewClient ------------------------------------------------------
1590
[email protected]916dfb62012-03-05 03:39:371591WebView* RenderViewImpl::createView(
1592 WebFrame* creator,
1593 const WebURLRequest& request,
1594 const WebWindowFeatures& features,
1595 const WebString& frame_name,
1596 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521597 // Check to make sure we aren't overloading on popups.
1598 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1599 return NULL;
1600
[email protected]8ab04652010-06-12 02:47:261601 ViewHostMsg_CreateWindow_Params params;
1602 params.opener_id = routing_id_;
1603 params.user_gesture = creator->isProcessingUserGesture();
1604 params.window_container_type = WindowFeaturesToContainerType(features);
1605 params.session_storage_namespace_id = session_storage_namespace_id_;
1606 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111607 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411608 params.opener_url = creator->document().url();
1609 params.opener_security_origin =
1610 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591611 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1612 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111613 if (!request.isNull())
1614 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261615
[email protected]48c9cf2d2009-09-16 16:47:521616 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561617 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341618 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521619
[email protected]380244092011-10-07 17:26:271620 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261621 new ViewHostMsg_CreateWindow(params,
1622 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561623 &surface_id,
[email protected]8ab04652010-06-12 02:47:261624 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211625 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521626 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521627
[email protected]8cca3da2012-03-20 08:26:341628 // TODO(fsamuel): The host renderer needs to be able to control whether
1629 // the guest renderer is allowed to do this or not. This current
1630 // behavior is not well defined.
[email protected]310ebd6302011-10-10 19:06:281631 RenderViewImpl* view = RenderViewImpl::Create(
1632 0,
1633 routing_id_,
1634 renderer_preferences_,
1635 webkit_preferences_,
1636 shared_popup_counter_,
1637 routing_id,
[email protected]9f4f3322012-01-18 22:29:561638 surface_id,
[email protected]310ebd6302011-10-10 19:06:281639 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461640 frame_name,
[email protected]14392a52012-05-02 20:28:441641 true,
1642 false,
[email protected]6fd35b72012-03-01 19:46:411643 1,
[email protected]468e4902012-05-23 01:49:311644 guest_to_embedder_channel_,
[email protected]3e3c4522012-04-13 21:16:291645 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261646 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521647
[email protected]007a848b2009-10-26 15:55:461648 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591649 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461650
[email protected]48c9cf2d2009-09-16 16:47:521651 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411652 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521653 if (!creator_url.is_valid() || !creator_url.IsStandard())
1654 creator_url = GURL();
1655 view->creator_url_ = creator_url;
1656
1657 // Copy over the alternate error page URL so we can have alt error pages in
1658 // the new render view (we don't need the browser to send the URL back down).
1659 view->alternate_error_page_url_ = alternate_error_page_url_;
1660
1661 return view->webview();
1662}
1663
[email protected]310ebd6302011-10-10 19:06:281664WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411665 RenderWidget* widget =
[email protected]dfec1952012-06-01 15:39:221666 RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521667 return widget->webwidget();
1668}
1669
[email protected]310ebd6302011-10-10 19:06:281670WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081671 const WebPopupMenuInfo& popup_menu_info,
1672 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:271673 // An IPC message is sent to the browser to build and display the actual
1674 // popup. The user could have time to click a different select by the time
1675 // the popup is shown. In that case external_popup_menu_ is non NULL.
1676 // By returning NULL in that case, we instruct WebKit to cancel that new
1677 // popup. So from the user perspective, only the first one will show, and
1678 // will have to close the first one before another one can be shown.
1679 if (external_popup_menu_.get())
1680 return NULL;
[email protected]caf706f2010-10-26 17:54:081681 external_popup_menu_.reset(
1682 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1683 return external_popup_menu_.get();
1684}
1685
[email protected]310ebd6302011-10-10 19:06:281686RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521687 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531688 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421689 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411690 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531691 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271692 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391693 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561694 return widget;
[email protected]79c7bed2010-09-14 22:28:391695}
1696
[email protected]310ebd6302011-10-10 19:06:281697WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1698 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:161699 CHECK(session_storage_namespace_id_ !=
1700 dom_storage::kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101701 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341702}
1703
[email protected]7e8b4d12012-01-20 23:39:511704WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]40ec0c12012-03-08 12:34:401705 const WebGraphicsContext3D::Attributes& attributes) {
[email protected]7e8b4d12012-01-20 23:39:511706 if (!webview())
1707 return NULL;
[email protected]468e4902012-05-23 01:49:311708
[email protected]7900bfdb2012-05-24 19:31:241709 if (GetGuestToEmbedderChannel()) {
[email protected]468e4902012-05-23 01:49:311710 WebGraphicsContext3DCommandBufferImpl* context =
[email protected]7900bfdb2012-05-24 19:31:241711 GetGuestToEmbedderChannel()->CreateWebGraphicsContext3D(
[email protected]468e4902012-05-23 01:49:311712 this, attributes, false);
1713 if (!guest_pp_instance()) {
1714 guest_uninitialized_context_ = context;
1715 guest_attributes_ = attributes;
1716 }
1717 return context;
1718 }
1719
[email protected]7e8b4d12012-01-20 23:39:511720 // The WebGraphicsContext3DInProcessImpl code path is used for
1721 // layout tests (though not through this code) as well as for
1722 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511723 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571724 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
[email protected]29dea0e2012-03-16 01:46:581725 attributes, true);
[email protected]7e8b4d12012-01-20 23:39:511726 } else {
[email protected]b3e83de2012-02-07 03:33:281727 GURL url;
1728 if (webview()->mainFrame())
1729 url = GURL(webview()->mainFrame()->document().url());
1730
[email protected]b3e83de2012-02-07 03:33:281731 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1732 new WebGraphicsContext3DCommandBufferImpl(
[email protected]8c9e0a02012-04-02 05:13:191733 surface_id(),
1734 url,
1735 RenderThreadImpl::current(),
1736 AsWeakPtr()));
[email protected]b3e83de2012-02-07 03:33:281737
[email protected]8c9e0a02012-04-02 05:13:191738 if (!context->Initialize(
1739 attributes,
1740 false /* bind generates resources */,
1741 content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
[email protected]56200f012012-02-03 23:13:571742 return NULL;
[email protected]d0fb8a72012-03-10 18:54:521743 context_is_web_graphics_context_3d_command_buffer_impl_ = true;
[email protected]56200f012012-02-03 23:13:571744 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511745 }
[email protected]7e8b4d12012-01-20 23:39:511746}
1747
[email protected]310ebd6302011-10-10 19:06:281748void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521749 const WebConsoleMessage& message, const WebString& source_name,
1750 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081751 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511752 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081753 case WebConsoleMessage::LevelTip:
1754 log_severity = logging::LOG_VERBOSE;
1755 break;
1756 case WebConsoleMessage::LevelLog:
1757 log_severity = logging::LOG_INFO;
1758 break;
1759 case WebConsoleMessage::LevelWarning:
1760 log_severity = logging::LOG_WARNING;
1761 break;
1762 case WebConsoleMessage::LevelError:
1763 log_severity = logging::LOG_ERROR;
1764 break;
1765 default:
1766 NOTREACHED();
1767 }
1768
[email protected]48c9cf2d2009-09-16 16:47:521769 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081770 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311771 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521772 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311773 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521774}
1775
[email protected]310ebd6302011-10-10 19:06:281776void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421777 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521778}
1779
[email protected]310ebd6302011-10-10 19:06:281780WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511781 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021782}
1783
[email protected]310ebd6302011-10-10 19:06:281784bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121785 const WebString& path,
1786 WebFileChooserCompletion* chooser_completion) {
1787 int id = enumeration_completion_id_++;
1788 enumeration_completions_[id] = chooser_completion;
1789 return Send(new ViewHostMsg_EnumerateDirectory(
1790 routing_id_,
1791 id,
1792 webkit_glue::WebStringToFilePath(path)));
1793}
1794
[email protected]310ebd6302011-10-10 19:06:281795void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521796 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141797 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521798 return;
1799 }
1800
1801 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521802
1803 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311804
1805 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521806}
1807
[email protected]310ebd6302011-10-10 19:06:281808void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521809 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141810 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521811 return;
1812 }
1813
1814 is_loading_ = false;
1815
1816 // NOTE: For now we're doing the safest thing, and sending out notification
1817 // when done loading. This currently isn't an issue as the favicon is only
1818 // displayed when done loading. Ideally we would send notification when
1819 // finished parsing the head, but webkit doesn't support that yet.
1820 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521821 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1822
[email protected]90109412010-12-15 17:14:241823 if (load_progress_tracker_ != NULL)
1824 load_progress_tracker_->DidStopLoading();
1825
[email protected]93b9d692011-04-13 00:44:311826 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521827}
1828
[email protected]310ebd6302011-10-10 19:06:281829void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1830 double load_progress) {
[email protected]90109412010-12-15 17:14:241831 if (load_progress_tracker_ != NULL)
1832 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1833}
1834
[email protected]310ebd6302011-10-10 19:06:281835bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061836#if defined(OS_MACOSX)
1837 return true;
1838#else
1839 return false;
1840#endif
1841}
1842
[email protected]310ebd6302011-10-10 19:06:281843bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031844#if defined(OS_WIN)
1845 return true;
1846#else
1847 return false;
1848#endif
1849}
1850
[email protected]310ebd6302011-10-10 19:06:281851void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081852 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031853 return;
[email protected]4fb60142011-08-09 02:22:081854 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011855
[email protected]fca52022012-04-03 17:00:501856 if (is_empty_selection)
1857 selection_text_.clear();
1858
[email protected]b781ff282011-08-20 06:19:361859 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031860}
1861
[email protected]310ebd6302011-10-10 19:06:281862void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121863 const std::string& name = UTF16ToUTF8(command_name);
1864 if (StartsWithASCII(name, "Move", true) ||
1865 StartsWithASCII(name, "Insert", true) ||
1866 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031867 return;
[email protected]f1a29a02011-10-06 23:08:441868 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031869}
1870
[email protected]310ebd6302011-10-10 19:06:281871bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101872 if (edit_commands_.empty())
1873 return false;
1874
[email protected]26aa0482009-09-30 16:55:271875 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101876 if (!frame)
1877 return false;
1878
1879 EditCommands::iterator it = edit_commands_.begin();
1880 EditCommands::iterator end = edit_commands_.end();
1881
[email protected]507b33ea2009-09-29 03:56:511882 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101883 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331884 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1885 // key (but it's the exception). Once one edit command is not executed, it
1886 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101887 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1888 WebString::fromUTF8(it->value)))
1889 break;
[email protected]507b33ea2009-09-29 03:56:511890 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101891 }
1892
[email protected]507b33ea2009-09-29 03:56:511893 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101894}
1895
[email protected]da8543762012-03-20 08:52:201896WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
1897 WebKit::WebColorChooserClient* client,
1898 const WebKit::WebColor& initial_color) {
1899 RendererWebColorChooserImpl* color_chooser =
1900 new RendererWebColorChooserImpl(this, client);
1901 color_chooser->Open(static_cast<SkColor>(initial_color));
1902 return color_chooser;
1903}
1904
[email protected]310ebd6302011-10-10 19:06:281905bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351906 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471907 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351908 // Do not open the file dialog in a hidden RenderView.
1909 if (is_hidden())
1910 return false;
[email protected]8caadeb2011-11-22 02:45:231911 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261912 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231913 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261914 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231915 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501916 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231917 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261918 else
[email protected]8caadeb2011-11-22 02:45:231919 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471920 ipc_params.title = params.title;
1921 ipc_params.default_file_name =
1922 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:321923 ipc_params.accept_types.reserve(params.acceptTypes.size());
1924 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
1925 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471926
1927 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461928}
1929
[email protected]269f86d2011-12-07 02:43:471930void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1931 const WebString& message) {
[email protected]be2510c02012-05-28 14:52:141932 RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411933 message,
1934 string16(),
[email protected]b6cb3a842011-06-24 18:28:411935 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521936 NULL);
1937}
1938
[email protected]269f86d2011-12-07 02:43:471939bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1940 const WebString& message) {
[email protected]be2510c02012-05-28 14:52:141941 return RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411942 message,
1943 string16(),
[email protected]b6cb3a842011-06-24 18:28:411944 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521945 NULL);
1946}
1947
[email protected]269f86d2011-12-07 02:43:471948bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1949 const WebString& message,
1950 const WebString& default_value,
1951 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411952 string16 result;
[email protected]be2510c02012-05-28 14:52:141953 bool ok = RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411954 message,
1955 default_value,
[email protected]b6cb3a842011-06-24 18:28:411956 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521957 &result);
1958 if (ok)
[email protected]4f5ce842011-05-27 19:34:411959 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521960 return ok;
1961}
1962
[email protected]310ebd6302011-10-10 19:06:281963bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521964 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151965 // If we are swapping out, we have already run the beforeunload handler.
1966 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1967 // at all, to avoid running it twice.
1968 if (is_swapped_out_)
1969 return true;
1970
[email protected]3b3301f62012-02-29 04:32:321971 bool is_reload = false;
1972 WebDataSource* ds = frame->provisionalDataSource();
1973 if (ds)
1974 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
1975
[email protected]48c9cf2d2009-09-16 16:47:521976 bool success = false;
1977 // This is an ignored return value, but is included so we can accept the same
1978 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411979 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211980 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:321981 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:411982 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521983 return success;
1984}
1985
[email protected]310ebd6302011-10-10 19:06:281986void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441987 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:511988 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:371989
1990 // frame is NULL if invoked by BlockedPlugin.
1991 if (frame)
1992 params.frame_id = frame->identifier();
1993
[email protected]db803aae2011-03-05 02:00:421994 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271995 // it. We replace it with an empty GURL so the appropriate items are disabled
1996 // in the context menu.
1997 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1998 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421999 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272000 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102001 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:292002 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442003}
2004
[email protected]310ebd6302011-10-10 19:06:282005void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522006}
2007
[email protected]310ebd6302011-10-10 19:06:282008void RenderViewImpl::UpdateTargetURL(const GURL& url,
2009 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582010 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522011 if (latest_url == target_url_)
2012 return;
[email protected]163f8242009-10-30 20:19:552013
[email protected]48c9cf2d2009-09-16 16:47:522014 // Tell the browser to display a destination link.
2015 if (target_url_status_ == TARGET_INFLIGHT ||
2016 target_url_status_ == TARGET_PENDING) {
2017 // If we have a request in-flight, save the URL to be sent when we
2018 // receive an ACK to the in-flight request. We can happily overwrite
2019 // any existing pending sends.
2020 pending_target_url_ = latest_url;
2021 target_url_status_ = TARGET_PENDING;
2022 } else {
[email protected]c85f0212011-11-04 16:54:412023 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
2024 // see |ParamTraits<GURL>|.
2025 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
2026 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522027 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2028 target_url_ = latest_url;
2029 target_url_status_ = TARGET_INFLIGHT;
2030 }
2031}
2032
[email protected]310ebd6302011-10-10 19:06:282033void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:312034 int delay;
2035 if (send_content_state_immediately_)
2036 delay = 0;
2037 else if (is_hidden())
2038 delay = kDelaySecondsForContentStateSyncHidden;
2039 else
2040 delay = kDelaySecondsForContentStateSync;
2041
2042 if (nav_state_sync_timer_.IsRunning()) {
2043 // The timer is already running. If the delay of the timer maches the amount
2044 // we want to delay by, then return. Otherwise stop the timer so that it
2045 // gets started with the right delay.
2046 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2047 return;
2048 nav_state_sync_timer_.Stop();
2049 }
2050
[email protected]d323a172011-09-02 18:23:022051 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282052 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312053}
2054
[email protected]310ebd6302011-10-10 19:06:282055void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552056 mouse_over_url_ = GURL(url);
2057 UpdateTargetURL(mouse_over_url_, focus_url_);
2058}
2059
[email protected]310ebd6302011-10-10 19:06:282060void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552061 focus_url_ = GURL(url);
2062 UpdateTargetURL(focus_url_, mouse_over_url_);
2063}
2064
[email protected]0407e422012-05-18 19:51:252065void RenderViewImpl::startDragging(WebFrame* frame,
2066 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282067 WebDragOperationsMask mask,
2068 const WebImage& image,
2069 const WebPoint& imageOffset) {
[email protected]b67151d2012-05-25 23:23:242070 WebDropData drop_data(data);
2071 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]59f4f2fa2011-03-23 01:00:552072 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242073 drop_data,
[email protected]c27ae592010-03-18 15:24:412074 mask,
[email protected]976127072012-05-10 20:08:112075 image.getSkBitmap(),
[email protected]c27ae592010-03-18 15:24:412076 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522077}
2078
[email protected]310ebd6302011-10-10 19:06:282079bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452080 return renderer_preferences_.can_accept_load_drops;
2081}
2082
[email protected]310ebd6302011-10-10 19:06:282083void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522084 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2085}
2086
[email protected]310ebd6302011-10-10 19:06:282087void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522088 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2089}
2090
[email protected]310ebd6302011-10-10 19:06:282091void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512092 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072093
[email protected]38b592902011-04-16 02:08:422094 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492095}
2096
[email protected]169d4282011-11-30 19:33:592097void RenderViewImpl::didUpdateLayout() {
2098 // We don't always want to set up a timer, only if we've been put in that
2099 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2100 // message.
2101 if (!send_preferred_size_changes_ || !webview())
2102 return;
2103
2104 if (check_preferred_size_timer_.IsRunning())
2105 return;
2106 check_preferred_size_timer_.Start(FROM_HERE,
2107 TimeDelta::FromMilliseconds(0), this,
2108 &RenderViewImpl::CheckPreferredSize);
2109}
2110
[email protected]310ebd6302011-10-10 19:06:282111void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522112 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2113}
2114
[email protected]310ebd6302011-10-10 19:06:282115int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002116 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522117}
2118
[email protected]310ebd6302011-10-10 19:06:282119int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002120 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522121}
2122
[email protected]310ebd6302011-10-10 19:06:282123void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322124 const WebAccessibilityObject& obj,
2125 WebAccessibilityNotification notification) {
2126 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
2127}
2128
[email protected]310ebd6302011-10-10 19:06:282129void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142130 const WebString& value) {
2131 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2132 key.utf8(),
2133 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262134}
2135
[email protected]79dbc662009-09-04 05:42:512136// WebKit::WebWidgetClient ----------------------------------------------------
2137
[email protected]310ebd6302011-10-10 19:06:282138void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122139 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2140 // we won't have to test for user gesture anymore and we can
2141 // move that code back to render_widget.cc
2142 if (webview() && webview()->mainFrame() &&
2143 webview()->mainFrame()->isProcessingUserGesture()) {
2144 Send(new ViewHostMsg_Focus(routing_id_));
2145 }
2146}
2147
[email protected]310ebd6302011-10-10 19:06:282148void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122149 // TODO(jcivelli): see TODO above in didFocus().
2150 if (webview() && webview()->mainFrame() &&
2151 webview()->mainFrame()->isProcessingUserGesture()) {
2152 Send(new ViewHostMsg_Blur(routing_id_));
2153 }
2154}
2155
initial.commit09911bf2008-07-26 23:55:292156// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282157// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292158// point to dispatch the ShowView message.
2159//
2160// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282161// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292162//
[email protected]310ebd6302011-10-10 19:06:282163void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292164 DCHECK(!did_show_) << "received extraneous Show call";
2165 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2166
2167 if (did_show_)
2168 return;
2169 did_show_ = true;
2170
[email protected]6779aa12011-03-29 17:32:242171 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042172 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042173
[email protected]28295ec2009-10-16 05:34:332174 // Force new windows to a popup if they were not opened with a user gesture.
2175 if (!opened_by_user_gesture_) {
2176 // We exempt background tabs for compat with older versions of Chrome.
2177 // TODO(darin): This seems bogus. These should have a user gesture, so
2178 // we probably don't need this check.
2179 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2180 policy = WebKit::WebNavigationPolicyNewPopup;
2181 }
2182
initial.commit09911bf2008-07-26 23:55:292183 // NOTE: initial_pos_ may still have its default values at this point, but
2184 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2185 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282186 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2187 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292188 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242189 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292190}
2191
[email protected]310ebd6302011-10-10 19:06:282192void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292193 DCHECK(did_show_) << "should already have shown the view";
2194
[email protected]c1f50aa2010-02-18 03:46:572195 // We must keep WebKit's shared timer running in this case in order to allow
2196 // showModalDialog to function properly.
2197 //
2198 // TODO(darin): WebKit should really be smarter about suppressing events and
2199 // timers so that we do not need to manage the shared timer in such a heavy
2200 // handed manner.
2201 //
[email protected]f1a29a02011-10-06 23:08:442202 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2203 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572204
[email protected]08a1c8102012-05-11 23:14:262205 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2206 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292207}
2208
[email protected]2b624c562011-10-27 22:58:262209bool RenderViewImpl::enterFullScreen() {
2210 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2211 return true;
2212}
2213
2214void RenderViewImpl::exitFullScreen() {
2215 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2216}
2217
[email protected]217690d2012-01-27 07:33:112218bool RenderViewImpl::requestPointerLock() {
2219 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2220}
2221
2222void RenderViewImpl::requestPointerUnlock() {
2223 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2224}
2225
2226bool RenderViewImpl::isPointerLocked() {
2227 return mouse_lock_dispatcher_->IsMouseLockedTo(
2228 webwidget_mouse_lock_target_.get());
2229}
2230
[email protected]7a1ec28a2012-03-28 21:10:242231void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2232 CompositorThread* compositor_thread =
2233 RenderThreadImpl::current()->compositor_thread();
2234 if (compositor_thread)
2235 compositor_thread->AddInputHandler(
2236 routing_id_, input_handler_identifier, AsWeakPtr());
2237
2238 RenderWidget::didActivateCompositor(input_handler_identifier);
2239}
2240
[email protected]3d9689372009-09-10 04:29:172241// WebKit::WebFrameClient -----------------------------------------------------
2242
[email protected]310ebd6302011-10-10 19:06:282243WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2244 const WebPluginParams& params) {
[email protected]0361b942012-03-14 06:42:532245 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2246 if (command_line.HasSwitch(switches::kEnableBrowserPlugin) &&
2247 UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType)
[email protected]468e4902012-05-23 01:49:312248 return BrowserPlugin::Create(this, frame, params);
[email protected]0361b942012-03-14 06:42:532249
[email protected]eaacd1f2011-09-23 02:32:552250 WebPlugin* plugin = NULL;
2251 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2252 this, frame, params, &plugin)) {
2253 return plugin;
2254 }
2255
[email protected]a813c8e2011-10-08 01:34:112256 webkit::WebPluginInfo info;
2257 std::string mime_type;
2258 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2259 params.mimeType.utf8(), &info, &mime_type);
2260 if (!found)
2261 return NULL;
2262
2263 WebPluginParams params_to_use = params;
2264 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312265 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172266}
2267
[email protected]6ac77cb2012-05-01 14:49:012268WebPlugin* RenderViewImpl::createPluginReplacement(
2269 WebFrame* frame,
2270 const WebPluginParams& params) {
2271 webkit::WebPluginInfo info;
2272 std::string mime_type;
2273 GetPluginInfo(params.url, frame->top()->document().url(),
2274 params.mimeType.utf8(), &info, &mime_type);
2275 return content::GetContentClient()->renderer()->CreatePluginReplacement(
2276 this, info.path);
2277}
2278
[email protected]310ebd6302011-10-10 19:06:282279WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422280 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372281 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422282
[email protected]30447b62009-11-13 01:13:372283 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512284 bool exists = false;
[email protected]30447b62009-11-13 01:13:372285 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512286 ViewHostMsg_CreateWorker_Params params;
2287 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512288 params.name = name;
2289 params.document_id = document_id;
2290 params.render_view_route_id = routing_id_;
2291 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232292 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372293 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512294 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372295 if (url_mismatch) {
2296 return NULL;
2297 } else {
[email protected]f1a29a02011-10-06 23:08:442298 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492299 document_id,
[email protected]6de0bcf2010-02-17 22:00:512300 exists,
[email protected]30447b62009-11-13 01:13:372301 route_id,
2302 routing_id_);
2303 }
[email protected]9c00f002009-11-05 22:37:422304}
2305
[email protected]310ebd6302011-10-10 19:06:282306WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172307 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442308 FOR_EACH_OBSERVER(
2309 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172310
[email protected]25fb9b32012-04-27 03:21:552311#if defined(OS_ANDROID)
[email protected]2d7b82c2012-06-01 05:57:502312 // TODO(qinmin): upstream the implementation of StreamTextureFactoryImpl
2313 // to replace the NULL param here.
[email protected]25fb9b32012-04-27 03:21:552314 return new webkit_media::WebMediaPlayerAndroid(
[email protected]2d7b82c2012-06-01 05:57:502315 frame, client, cookieJar(frame), media_player_manager_.get(), NULL);
[email protected]25fb9b32012-04-27 03:21:552316#endif
2317
[email protected]bb6fd402011-12-09 02:45:442318 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502319 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442320 media::FilterCollection* collection = new media::FilterCollection();
2321 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372322
[email protected]9e2269d2012-01-07 00:06:212323 RenderAudioSourceProvider* audio_source_provider = NULL;
2324
[email protected]3d9689372009-09-10 04:29:172325 // Add in any custom filter factories first.
2326 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2327 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212328 // audio_source_provider is a "provider" to WebKit, and a sink
2329 // from the perspective of the audio renderer.
2330 audio_source_provider = new RenderAudioSourceProvider();
2331
2332 // Add the chrome specific audio renderer, using audio_source_provider
2333 // as the sink.
[email protected]37136d162012-04-09 23:39:192334 media::AudioRendererImpl* audio_renderer =
2335 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212336 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172337 }
2338
[email protected]95970422012-05-22 04:00:202339 // Currently only cros/arm has any HW video decode support in
[email protected]e1d69d762011-12-13 05:12:182340 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2341 // platforms. This is a startup-time optimization. When new VDA
[email protected]95970422012-05-22 04:00:202342 // implementations are added, relax the #if above.
2343#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
[email protected]d0fb8a72012-03-10 18:54:522344 // Note we don't actually use the result of this blind down-cast unless it's
2345 // valid (not NULL and of the right type).
[email protected]43567302012-02-16 23:21:392346 WebGraphicsContext3DCommandBufferImpl* context3d =
2347 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2348 webview()->graphicsContext3D());
[email protected]d0fb8a72012-03-10 18:54:522349 if (context_is_web_graphics_context_3d_command_buffer_impl_ && context3d) {
[email protected]84a83e192012-03-09 18:43:402350 MessageLoop* factories_loop =
2351 RenderThreadImpl::current()->compositor_thread() ?
2352 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
2353 ->message_loop() :
2354 MessageLoop::current();
[email protected]e1d69d762011-12-13 05:12:182355 GpuChannelHost* gpu_channel_host =
2356 RenderThreadImpl::current()->EstablishGpuChannelSync(
2357 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2358 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312359 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
[email protected]84a83e192012-03-09 18:43:402360 factories_loop,
[email protected]8d4359282012-01-14 00:53:312361 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402362 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182363 }
2364#endif
2365
[email protected]5d65fe92012-06-02 00:48:552366 WebMediaPlayer* media_player =
[email protected]da952fd2012-01-13 03:49:252367 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2368 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1bc65a42012-04-23 09:31:252369 message_loop_factory, media_stream_impl_, render_media_log);
[email protected]da952fd2012-01-13 03:49:252370 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562371 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252372 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1bc65a42012-04-23 09:31:252373 message_loop_factory, media_stream_impl_, render_media_log);
[email protected]bb6fd402011-12-09 02:45:442374 }
[email protected]cec4eb82012-01-12 17:51:562375 return media_player;
[email protected]3d9689372009-09-10 04:29:172376}
2377
[email protected]310ebd6302011-10-10 19:06:282378WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212379 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232380 if (!frame || !frame->view())
2381 return NULL;
[email protected]035545f2010-04-09 13:10:212382 return new RendererWebApplicationCacheHostImpl(
2383 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442384 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212385}
2386
[email protected]310ebd6302011-10-10 19:06:282387WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382388 return &cookie_jar_;
2389}
2390
[email protected]310ebd6302011-10-10 19:06:282391void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512392 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452393}
2394
[email protected]310ebd6302011-10-10 19:06:282395void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512396 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172397}
2398
[email protected]310ebd6302011-10-10 19:06:282399void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172400 WebFrame* frame, const WebURLRequest& request,
2401 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342402 loadURLExternally(frame, request, policy, WebString());
2403}
2404
[email protected]310ebd6302011-10-10 19:06:282405void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342406 WebFrame* frame, const WebURLRequest& request,
2407 WebNavigationPolicy policy,
2408 const WebString& suggested_name) {
[email protected]56505542012-05-12 00:25:372409 Referrer referrer(
2410 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2411 GetReferrerPolicyFromRequest(frame, request));
[email protected]efce17b2009-09-11 18:04:592412 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342413 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2414 suggested_name));
[email protected]efce17b2009-09-11 18:04:592415 } else {
[email protected]56505542012-05-12 00:25:372416 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:592417 }
[email protected]3d9689372009-09-10 04:29:172418}
2419
[email protected]310ebd6302011-10-10 19:06:282420WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172421 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222422 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332423 Referrer referrer(
2424 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:592425 GetReferrerPolicyFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:332426
[email protected]992db4c2011-05-12 15:37:152427 if (is_swapped_out_) {
[email protected]285f4bb82012-04-17 15:57:282428 if (request.url() != GURL(content::kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332429 // Targeted links may try to navigate a swapped out frame. Allow the
2430 // browser process to navigate the tab instead. Note that it is also
2431 // possible for non-targeted navigations (from this view) to arrive
2432 // here just after we are swapped out. It's ok to send them to the
2433 // browser, as long as they're for the top level frame.
2434 // TODO(creis): Ensure this supports targeted form submissions when
2435 // fixing http://crbug.com/101395.
2436 if (frame->parent() == NULL) {
2437 OpenURL(frame, request.url(), referrer, default_policy);
2438 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2439 }
2440
2441 // We should otherwise ignore in-process iframe navigations, if they
2442 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552443 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332444 }
[email protected]73eb2602012-02-09 19:50:552445
[email protected]285f4bb82012-04-17 15:57:282446 // Allow content::kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152447 return default_policy;
2448 }
2449
[email protected]3d9689372009-09-10 04:29:172450 // Webkit is asking whether to navigate to a new URL.
2451 // This is fine normally, except if we're showing UI from one security
2452 // context and they're trying to navigate to a different context.
2453 const GURL& url = request.url();
2454
[email protected]d19ea342011-04-20 20:31:132455 // A content initiated navigation may have originated from a link-click,
2456 // script, drag-n-drop operation, etc.
2457 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072458 DocumentState::FromDataSource(frame->provisionalDataSource())->
2459 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132460
[email protected]a8c269a2011-10-25 20:17:222461 // Experimental:
2462 // If --enable-strict-site-isolation is enabled, send all top-level
2463 // navigations to the browser to let it swap processes when crossing site
2464 // boundaries. This is currently expected to break some script calls and
2465 // navigations, such as form submissions.
2466 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102467 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2468 !frame->parent() && (is_content_initiated || is_redirect)) {
2469 WebString origin_str = frame->document().securityOrigin().toString();
2470 GURL frame_url(origin_str.utf8().data());
2471 // TODO(cevans): revisit whether this origin check is still necessary once
2472 // crbug.com/101395 is fixed.
2473 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]313b80bd2011-11-23 03:49:102474 OpenURL(frame, url, referrer, default_policy);
2475 return WebKit::WebNavigationPolicyIgnore;
2476 }
[email protected]a8c269a2011-10-25 20:17:222477 }
2478
[email protected]fd3238af2012-05-22 18:55:302479 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:082480 if (is_content_initiated) {
[email protected]fd3238af2012-05-22 18:55:302481 bool browser_handles_request =
2482 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]5f000f272012-01-19 05:25:082483 IsNonLocalTopLevelNavigation(url, frame, type);
[email protected]fd3238af2012-05-22 18:55:302484 if (!browser_handles_request) {
2485 browser_handles_request =
2486 renderer_preferences_.browser_handles_all_top_level_requests &&
2487 IsTopLevelNavigation(frame);
2488 }
2489
2490 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:082491 // Reset these counters as the RenderView could be reused for the next
2492 // navigation.
2493 page_id_ = -1;
2494 last_page_id_sent_to_browser_ = -1;
2495 OpenURL(frame, url, referrer, default_policy);
2496 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2497 }
[email protected]3d9689372009-09-10 04:29:172498 }
2499
[email protected]6101c342010-12-16 22:44:372500 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552501 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042502 // top-level navigations (not iframes). But we sometimes navigate to
2503 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372504 //
[email protected]744c2a22012-03-15 18:42:042505 // Note: this is known to break POST submissions when crossing process
2506 // boundaries until http://crbug.com/101395 is fixed. This is better for
2507 // security than loading a WebUI, extension or app page in the wrong process.
2508 // POST requests don't work because this mechanism does not preserve form
2509 // POST data. We will need to send the request's httpBody data up to the
2510 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572511 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2512 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222513 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042514 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372515 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042516
2517 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2518 // must be handled by the browser process so that the correct bindings and
2519 // data sources can be registered.
2520 // Similarly, navigations to view-source URLs or within ViewSource mode
2521 // must be handled by the browser process.
2522 int cumulative_bindings =
2523 RenderProcess::current()->GetEnabledBindings();
[email protected]6101c342010-12-16 22:44:372524 bool should_fork =
[email protected]744c2a22012-03-15 18:42:042525 content::GetContentClient()->HasWebUIScheme(url) ||
2526 (cumulative_bindings & content::BINDINGS_POLICY_WEB_UI) ||
2527 url.SchemeIs(chrome::kViewSourceScheme) ||
2528 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112529
[email protected]e48869a2011-04-01 19:56:032530 if (!should_fork) {
2531 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042532 // For now, we skip this for POST submissions. This is because
2533 // http://crbug.com/101395 is more likely to cause compatibility issues
2534 // with hosted apps and extensions than WebUI pages. We will remove this
2535 // check when cross-process POST submissions are supported.
2536 if (request.httpMethod() == "GET") {
2537 bool is_initial_navigation = page_id_ == -1;
2538 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2539 frame, url, is_initial_navigation, &send_referrer);
2540 }
[email protected]6101c342010-12-16 22:44:372541 }
2542
2543 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152544 OpenURL(
2545 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112546 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2547 }
[email protected]3d9689372009-09-10 04:29:172548 }
2549
[email protected]43763f982011-08-26 18:33:402550 // Use the frame's original request's URL rather than the document's URL for
2551 // this check. For a popup, the document's URL may become the opener window's
2552 // URL if the opener has called document.write. See http://crbug.com/93517.
2553 GURL old_url(frame->dataSource()->request().url());
2554
[email protected]3d9689372009-09-10 04:29:172555 // Detect when a page is "forking" a new tab that can be safely rendered in
2556 // its own process. This is done by sites like Gmail that try to open links
2557 // in new windows without script connections back to the original page. We
2558 // treat such cases as browser navigations (in which we will create a new
2559 // renderer for a cross-site navigation), rather than WebKit navigations.
2560 //
2561 // We use the following heuristic to decide whether to fork a new page in its
2562 // own process:
2563 // The parent page must open a new tab to about:blank, set the new tab's
2564 // window.opener to null, and then redirect the tab to a cross-site URL using
2565 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462566 //
2567 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2568 // (see below).
[email protected]3d9689372009-09-10 04:29:172569 bool is_fork =
2570 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582571 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172572 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522573 historyBackListCount() < 1 &&
2574 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172575 // The parent page must have set the child's window.opener to null before
2576 // redirecting to the desired URL.
2577 frame->opener() == NULL &&
2578 // Must be a top-level frame.
2579 frame->parent() == NULL &&
2580 // Must not have issued the request from this page.
2581 is_content_initiated &&
2582 // Must be targeted at the current tab.
2583 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2584 // Must be a JavaScript navigation, which appears as "other".
2585 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462586
[email protected]f92ce2b2012-03-06 18:02:592587 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172588 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152589 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172590 return WebKit::WebNavigationPolicyIgnore;
2591 }
2592
2593 return default_policy;
2594}
2595
[email protected]310ebd6302011-10-10 19:06:282596bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492597 WebFrame* frame, const WebURLRequest& request) {
2598 // We allow WebKit to think that everything can be handled even though
2599 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342600 return true;
2601}
2602
[email protected]310ebd6302011-10-10 19:06:282603WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492604 WebFrame* frame, const WebURLRequest& request) {
2605 NOTREACHED(); // Since we said we can handle all requests.
2606 return WebURLError();
2607}
2608
[email protected]310ebd6302011-10-10 19:06:282609WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492610 WebFrame* frame, const WebURLRequest& request) {
2611 WebURLError error;
2612 error.domain = WebString::fromUTF8(net::kErrorDomain);
2613 error.reason = net::ERR_ABORTED;
2614 error.unreachableURL = request.url();
2615 return error;
[email protected]7b7a7dc2009-10-19 02:23:342616}
2617
[email protected]310ebd6302011-10-10 19:06:282618void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492619 WebFrame*, const WebURLError&) {
2620 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342621}
2622
[email protected]310ebd6302011-10-10 19:06:282623void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432624 const WebKit::WebFormElement& form) {
2625 // Some login forms have onSubmit handlers that put a hash of the password
2626 // into a hidden field and then clear the password. (Issue 28910.)
2627 // This method gets called before any of those handlers run, so save away
2628 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072629 DocumentState* document_state =
2630 DocumentState::FromDataSource(frame->dataSource());
2631 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432632 PasswordFormDomManager::CreatePasswordForm(form));
2633}
2634
[email protected]310ebd6302011-10-10 19:06:282635void RenderViewImpl::willSubmitForm(WebFrame* frame,
2636 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072637 DocumentState* document_state =
2638 DocumentState::FromDataSource(frame->provisionalDataSource());
2639 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172640
[email protected]2905f742011-10-13 03:51:582641 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2642 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172643
2644 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352645 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072646 document_state->set_searchable_form_url(web_searchable_form_data.url());
2647 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212648 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432649 PasswordForm* password_form_data =
2650 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072651 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432652
[email protected]098c95cb2011-04-28 16:49:012653 // In order to save the password that the user actually typed and not one
2654 // that may have gotten transformed by the site prior to submit, recover it
2655 // from the form contents already stored by |willSendSubmitEvent| into the
2656 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2657 // which is what we're storing into now.)
2658 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072659 DocumentState* old_document_state =
2660 DocumentState::FromDataSource(frame->dataSource());
2661 if (old_document_state) {
2662 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432663 if (old_form_data && old_form_data->action == password_form_data->action)
2664 password_form_data->password_value = old_form_data->password_value;
2665 }
2666 }
[email protected]3d9689372009-09-10 04:29:172667
[email protected]2a5b1732011-04-01 23:55:552668 FOR_EACH_OBSERVER(
2669 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172670}
2671
[email protected]310ebd6302011-10-10 19:06:282672void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172673 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2674 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382675 FOR_EACH_OBSERVER(
2676 RenderViewObserver, observers_,
2677 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172678}
2679
[email protected]310ebd6302011-10-10 19:06:282680void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382681 FOR_EACH_OBSERVER(
2682 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172683}
2684
[email protected]310ebd6302011-10-10 19:06:282685void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172686 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152687 if (!frame->parent()) {
2688 WebDataSource* ds = frame->provisionalDataSource();
2689 // If there's no provisional data source, it's a reference fragment
2690 // navigation.
2691 completed_client_redirect_src_ = Referrer(
[email protected]ca662822012-05-11 17:53:592692 from, ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:042693 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:152694 }
[email protected]eb0bff942011-04-07 22:08:382695 FOR_EACH_OBSERVER(
2696 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172697}
2698
[email protected]310ebd6302011-10-10 19:06:282699void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572700 bool content_initiated = !pending_navigation_params_.get();
2701
[email protected]007733c2011-11-17 00:34:072702 DocumentState* document_state = DocumentState::FromDataSource(ds);
2703 if (!document_state) {
2704 document_state = new DocumentState;
2705 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572706 if (!content_initiated)
2707 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072708 }
2709
[email protected]3d9689372009-09-10 04:29:172710 // The rest of RenderView assumes that a WebDataSource will always have a
2711 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072712 if (content_initiated)
2713 document_state->set_navigation_state(
2714 NavigationState::CreateContentInitiated());
[email protected]45d83a12012-04-06 22:57:572715 else {
2716 document_state->set_navigation_state(CreateNavigationStateFromPending());
2717 pending_navigation_params_.reset();
2718 }
[email protected]8a3125a712010-08-09 18:58:512719
[email protected]007733c2011-11-17 00:34:072720 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512721 // navigating from a page that used prefetching using a link on that
2722 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072723 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512724 // this value appropriately.
2725 // TODO(gavinp): catch the important case of navigation in a new
2726 // renderer process.
2727 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302728 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522729 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512730 const GURL referrer(
2731 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2732 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072733 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512734 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:412735 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:512736 WebDataSource* old_frame_ds = old_frame->dataSource();
2737 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072738 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512739 break;
2740 }
2741 }
2742 }
2743 }
2744 }
2745
[email protected]4c1b6f0b2010-02-07 16:38:182746 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522747 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512748 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182749 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072750 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182751 break;
2752 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072753 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182754 break;
2755 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072756 document_state->set_load_type(
2757 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182758 break;
2759 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072760 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182761 break;
2762 }
2763 }
[email protected]fa7b6b542009-11-03 05:02:302764
[email protected]946a0032011-03-31 18:42:282765 FOR_EACH_OBSERVER(
2766 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172767}
2768
[email protected]45d83a12012-04-06 22:57:572769void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:072770 DocumentState* document_state) {
2771 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:572772 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:072773
[email protected]45d83a12012-04-06 22:57:572774 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
2775 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2776 // We're doing a load of a page that was restored from the last session. By
2777 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
2778 // can result in stale data for pages that are set to expire. We explicitly
2779 // override that by setting the policy here so that as necessary we load
2780 // from the network.
2781 document_state->set_cache_policy_override(
2782 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:072783 }
2784
2785 if (IsReload(params))
2786 document_state->set_load_type(DocumentState::RELOAD);
2787 else if (!params.state.empty())
2788 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2789 else
2790 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:592791
2792 document_state->set_referrer_policy(params.referrer.policy);
[email protected]45d83a12012-04-06 22:57:572793}
[email protected]007733c2011-11-17 00:34:072794
[email protected]45d83a12012-04-06 22:57:572795NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
2796 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2797 NavigationState* navigation_state = NULL;
2798
2799 // A navigation resulting from loading a javascript URL should not be treated
2800 // as a browser initiated event. Instead, we want it to look as if the page
2801 // initiated any load resulting from JS execution.
2802 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2803 navigation_state = NavigationState::CreateBrowserInitiated(
2804 params.page_id,
2805 params.pending_history_list_offset,
2806 params.transition);
2807 navigation_state->set_transferred_request_child_id(
2808 params.transferred_request_child_id);
2809 navigation_state->set_transferred_request_request_id(
2810 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:002811 navigation_state->set_allow_download(params.allow_download);
[email protected]45d83a12012-04-06 22:57:572812 } else {
2813 navigation_state = NavigationState::CreateContentInitiated();
2814 }
2815 return navigation_state;
[email protected]007733c2011-11-17 00:34:072816}
2817
[email protected]5b52cd2f712012-03-28 02:12:482818void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
2819 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:102820 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:482821 bool enable_fixed_layout =
2822 command_line.HasSwitch(switches::kEnableFixedLayout);
2823
2824 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
2825 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
2826
2827 if (enable_viewport) {
2828 webview()->settings()->setViewportEnabled(true);
2829 } else if (enable_fixed_layout) {
2830 std::string str =
2831 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
2832 std::vector<std::string> tokens;
2833 base::SplitString(str, ',', &tokens);
2834 if (tokens.size() == 2) {
2835 int width, height;
2836 if (base::StringToInt(tokens[0], &width) &&
2837 base::StringToInt(tokens[1], &height))
2838 webview()->setFixedLayoutSize(WebSize(width,height));
2839 }
2840 }
2841}
2842
[email protected]310ebd6302011-10-10 19:06:282843void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172844 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072845 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172846
[email protected]3d9689372009-09-10 04:29:172847 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072848 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172849 double event_time = ds->triggeringEventTime();
2850 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072851 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172852 }
2853
[email protected]05c8e502010-08-15 15:13:522854 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072855 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522856
[email protected]3d9689372009-09-10 04:29:172857 bool is_top_most = !frame->parent();
2858 if (is_top_most) {
2859 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132860 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172861
2862 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152863 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172864 } else if (frame->parent()->isLoading()) {
2865 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002866 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072867 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582868 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172869 }
2870
[email protected]28685da92011-02-07 21:49:172871 FOR_EACH_OBSERVER(
2872 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2873
[email protected]3d9689372009-09-10 04:29:172874 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592875 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262876 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172877}
2878
[email protected]310ebd6302011-10-10 19:06:282879void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2880 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172881 if (frame->parent())
2882 return;
2883 // Received a redirect on the main frame.
2884 WebDataSource* data_source = frame->provisionalDataSource();
2885 if (!data_source) {
2886 // Should only be invoked when we have a data source.
2887 NOTREACHED();
2888 return;
2889 }
2890 std::vector<GURL> redirects;
2891 GetRedirectChain(data_source, &redirects);
2892 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512893 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592894 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172895 }
2896}
2897
[email protected]310ebd6302011-10-10 19:06:282898void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2899 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172900 // Notify the browser that we failed a provisional load with an error.
2901 //
2902 // Note: It is important this notification occur before DidStopLoading so the
2903 // SSL manager can react to the provisional load failure before being
2904 // notified the load stopped.
2905 //
2906 WebDataSource* ds = frame->provisionalDataSource();
2907 DCHECK(ds);
2908
2909 const WebURLRequest& failed_request = ds->request();
2910
[email protected]28685da92011-02-07 21:49:172911 FOR_EACH_OBSERVER(
2912 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2913
[email protected]3d9689372009-09-10 04:29:172914 bool show_repost_interstitial =
2915 (error.reason == net::ERR_CACHE_MISS &&
2916 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582917
2918 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2919 params.frame_id = frame->identifier();
2920 params.is_main_frame = !frame->parent();
2921 params.error_code = error.reason;
2922 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2923 failed_request,
2924 error,
2925 NULL,
2926 &params.error_description);
2927 params.url = error.unreachableURL;
2928 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172929 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582930 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172931
2932 // Don't display an error page if this is simply a cancelled load. Aside
2933 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2934 if (error.reason == net::ERR_ABORTED)
2935 return;
[email protected]b553edd52012-01-10 12:15:232936 // Don't display an error message if the request was handled by an
2937 // external protocol handler.
2938 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2939 return;
[email protected]3d9689372009-09-10 04:29:172940
2941 // Make sure we never show errors in view source mode.
2942 frame->enableViewSourceMode(false);
2943
[email protected]007733c2011-11-17 00:34:072944 DocumentState* document_state = DocumentState::FromDataSource(ds);
2945 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172946
2947 // If this is a failed back/forward/reload navigation, then we need to do a
2948 // 'replace' load. This is necessary to avoid messing up session history.
2949 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2950 // as session history is concerned.
2951 //
2952 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2953 // the page id.
2954 //
2955 bool replace =
2956 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582957 navigation_state->transition_type() ==
2958 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172959
2960 // If we failed on a browser initiated request, then make sure that our error
2961 // page load is regarded as the same browser initiated request.
2962 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072963 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2964 pending_navigation_params_->page_id =
2965 navigation_state->pending_page_id();
2966 pending_navigation_params_->pending_history_list_offset =
2967 navigation_state->pending_history_list_offset();
2968 pending_navigation_params_->transition =
2969 navigation_state->transition_type();
2970 pending_navigation_params_->request_time =
2971 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172972 }
2973
2974 // Provide the user with a more helpful error page?
2975 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2976 return;
2977
2978 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082979 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172980}
2981
[email protected]310ebd6302011-10-10 19:06:282982void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172983 WebFrame* frame, const char* data, size_t data_len,
2984 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072985 DocumentState* document_state =
2986 DocumentState::FromDataSource(frame->dataSource());
2987 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172988}
2989
[email protected]310ebd6302011-10-10 19:06:282990void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2991 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072992 DocumentState* document_state =
2993 DocumentState::FromDataSource(frame->dataSource());
2994 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172995
[email protected]007733c2011-11-17 00:34:072996 if (document_state->commit_load_time().is_null())
2997 document_state->set_commit_load_time(Time::Now());
2998
[email protected]3d9689372009-09-10 04:29:172999 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203000 // When we perform a new navigation, we need to update the last committed
3001 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173002 UpdateSessionHistory(frame);
3003
3004 // We bump our Page ID to correspond with the new session history entry.
3005 page_id_ = next_page_id_++;
3006
[email protected]285f4bb82012-04-17 15:57:283007 // Don't update history_page_ids_ (etc) for content::kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263008 // we don't want to forget the entry that was there, and since we will
[email protected]285f4bb82012-04-17 15:57:283009 // never come back to content::kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313010 // UpdateSessionHistory and update page_id_ even in this case, so that
3011 // the current entry gets a state update and so that we don't send a
3012 // state update to the wrong entry when we swap back in.
[email protected]285f4bb82012-04-17 15:57:283013 if (GetLoadingUrl(frame) != GURL(content::kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313014 // Advance our offset in session history, applying the length limit.
3015 // There is now no forward history.
3016 history_list_offset_++;
3017 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
3018 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
3019 history_list_length_ = history_list_offset_ + 1;
3020 history_page_ids_.resize(history_list_length_, -1);
3021 history_page_ids_[history_list_offset_] = page_id_;
3022 }
[email protected]3d9689372009-09-10 04:29:173023 } else {
3024 // Inspect the navigation_state on this frame to see if the navigation
3025 // corresponds to a session history navigation... Note: |frame| may or
3026 // may not be the toplevel frame, but for the case of capturing session
3027 // history, the first committed frame suffices. We keep track of whether
3028 // we've seen this commit before so that only capture session history once
3029 // per navigation.
3030 //
3031 // Note that we need to check if the page ID changed. In the case of a
3032 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3033 // previous URL and the current page ID, which would be wrong.
3034 if (navigation_state->pending_page_id() != -1 &&
3035 navigation_state->pending_page_id() != page_id_ &&
3036 !navigation_state->request_committed()) {
3037 // This is a successful session history navigation!
3038 UpdateSessionHistory(frame);
3039 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003040
3041 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033042
3043 // If the history list is valid, our list of page IDs should be correct.
3044 DCHECK(history_list_length_ <= 0 ||
3045 history_list_offset_ < 0 ||
3046 history_list_offset_ >= history_list_length_ ||
3047 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173048 }
3049 }
3050
[email protected]28685da92011-02-07 21:49:173051 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3052 DidCommitProvisionalLoad(frame, is_new_navigation));
3053
[email protected]3d9689372009-09-10 04:29:173054 // Remember that we've already processed this request, so we don't update
3055 // the session history again. We do this regardless of whether this is
3056 // a session history navigation, because if we attempted a session history
3057 // navigation without valid HistoryItem state, WebCore will think it is a
3058 // new navigation.
3059 navigation_state->set_request_committed(true);
3060
3061 UpdateURL(frame);
3062
3063 // If this committed load was initiated by a client redirect, we're
3064 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153065 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173066
3067 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273068 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173069}
3070
[email protected]310ebd6302011-10-10 19:06:283071void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103072 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3073 DidClearWindowObject(frame));
3074
[email protected]b6cb3a842011-06-24 18:28:413075 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:213076 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:253077 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3078 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273079 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173080 }
[email protected]766a7082012-02-03 23:39:153081
3082 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
3083 if (!dom_automation_controller_.get())
3084 dom_automation_controller_.reset(new DomAutomationController());
3085 dom_automation_controller_->set_message_sender(
3086 static_cast<content::RenderView*>(this));
3087 dom_automation_controller_->set_routing_id(routing_id());
3088 dom_automation_controller_->BindToJavascript(frame,
3089 "domAutomationController");
3090 }
[email protected]3d9689372009-09-10 04:29:173091}
3092
[email protected]310ebd6302011-10-10 19:06:283093void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173094 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:413095 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:253096 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:433097 if (frame == webview()->mainFrame())
3098 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173099 }
[email protected]e48869a2011-04-01 19:56:033100
3101 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3102 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173103}
3104
[email protected]310ebd6302011-10-10 19:06:283105void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3106 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463107 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173108
3109 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273110 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173111}
3112
[email protected]310ebd6302011-10-10 19:06:283113void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:133114 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3115 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:583116}
3117
[email protected]310ebd6302011-10-10 19:06:283118void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173119 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073120 DocumentState* document_state = DocumentState::FromDataSource(ds);
3121 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173122
[email protected]622474d2010-11-04 09:21:083123 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173124
[email protected]28685da92011-02-07 21:49:173125 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3126 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173127
3128 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273129 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173130}
3131
[email protected]310ebd6302011-10-10 19:06:283132void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083133 if (webview()->mainFrame() == frame) {
3134 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3135 page_id_));
3136 }
[email protected]3d9689372009-09-10 04:29:173137}
3138
[email protected]310ebd6302011-10-10 19:06:283139void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5b2011-11-29 11:36:313140 WebDataSource* ds = frame->dataSource();
3141 DCHECK(ds);
3142
3143
[email protected]28685da92011-02-07 21:49:173144 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5b2011-11-29 11:36:313145
3146 const WebURLRequest& failed_request = ds->request();
3147 string16 error_description;
3148 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
3149 failed_request,
3150 error,
3151 NULL,
3152 &error_description);
3153 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3154 frame->identifier(),
3155 failed_request.url(),
3156 !frame->parent(),
3157 error.reason,
3158 error_description));
[email protected]3d9689372009-09-10 04:29:173159}
3160
[email protected]310ebd6302011-10-10 19:06:283161void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173162 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073163 DocumentState* document_state = DocumentState::FromDataSource(ds);
3164 if (document_state->finish_load_time().is_null())
3165 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413166
[email protected]676126f72011-01-15 00:03:513167 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173168
[email protected]1a55c5b2011-11-29 11:36:313169 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3170 frame->identifier(),
3171 ds->request().url(),
3172 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173173}
3174
[email protected]310ebd6302011-10-10 19:06:283175void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173176 WebFrame* frame, bool is_new_navigation) {
3177 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073178 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173179 // update the ExtraData on the datasource so that others who read the
3180 // ExtraData will get the new NavigationState. Similarly, if we did not
3181 // initiate this navigation, then we need to take care to reset any pre-
3182 // existing navigation state to a content-initiated navigation state.
3183 // DidCreateDataSource conveniently takes care of this for us.
3184 didCreateDataSource(frame, frame->dataSource());
3185
[email protected]007733c2011-11-17 00:34:073186 DocumentState* document_state =
3187 DocumentState::FromDataSource(frame->dataSource());
3188 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093189 new_state->set_was_within_same_page(true);
3190
[email protected]3d9689372009-09-10 04:29:173191 didCommitProvisionalLoad(frame, is_new_navigation);
3192
[email protected]750fcf872011-08-03 23:10:473193 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3194 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173195}
3196
[email protected]310ebd6302011-10-10 19:06:283197void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313198 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593199}
3200
[email protected]310ebd6302011-10-10 19:06:283201void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173202 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3203 // Ignore
3204}
3205
[email protected]310ebd6302011-10-10 19:06:283206void RenderViewImpl::willSendRequest(WebFrame* frame,
3207 unsigned identifier,
3208 WebURLRequest& request,
3209 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303210 WebFrame* top_frame = frame->top();
3211 if (!top_frame)
3212 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513213 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3214 WebDataSource* top_data_source = top_frame->dataSource();
3215 WebDataSource* data_source =
3216 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223217
[email protected]78d5cfe2011-02-04 08:43:223218 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:033219 GURL new_url;
3220 if (content::GetContentClient()->renderer()->WillSendRequest(
[email protected]80744782012-05-04 01:47:003221 frame, request_url, &new_url)) {
[email protected]e48869a2011-04-01 19:56:033222 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:223223 }
3224
[email protected]2905f742011-10-13 03:51:583225 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073226 DocumentState* document_state = DocumentState::FromDataSource(data_source);
3227 NavigationState* navigation_state = document_state->navigation_state();
3228 if (document_state) {
3229 if (document_state->is_cache_policy_override_set())
3230 request.setCachePolicy(document_state->cache_policy_override());
3231 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:303232 }
[email protected]8a3125a712010-08-09 18:58:513233
[email protected]ca662822012-05-11 17:53:593234 WebKit::WebReferrerPolicy referrer_policy;
3235 if (document_state && document_state->is_referrer_policy_set()) {
3236 referrer_policy = document_state->referrer_policy();
3237 document_state->clear_referrer_policy();
3238 } else {
3239 referrer_policy = frame->document().referrerPolicy();
3240 }
3241
[email protected]91043a8232011-11-04 16:41:193242 request.setExtraData(
[email protected]ca662822012-05-11 17:53:593243 new RequestExtraData(referrer_policy,
[email protected]537fbe02011-11-24 00:58:063244 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193245 frame->identifier(),
3246 frame->parent() == top_frame,
3247 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]80744782012-05-04 01:47:003248 navigation_state->allow_download(),
[email protected]4ad5d77d2011-12-03 02:00:483249 transition_type,
3250 navigation_state->transferred_request_child_id(),
3251 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573252
[email protected]007733c2011-11-17 00:34:073253 DocumentState* top_document_state =
3254 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573255 // TODO(gavinp): separate out prefetching and prerender field trials
3256 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073257 if (top_document_state &&
[email protected]925dec1c2012-05-18 05:09:003258 request.targetType() == WebURLRequest::TargetIsPrefetch)
[email protected]007733c2011-11-17 00:34:073259 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513260
[email protected]3d9689372009-09-10 04:29:173261 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133262 request.setHasUserGesture(frame->isProcessingUserGesture());
3263
[email protected]0a8db0d2011-04-13 15:15:403264 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133265 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173266}
3267
[email protected]310ebd6302011-10-10 19:06:283268void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173269 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493270
[email protected]3d9689372009-09-10 04:29:173271 // Only do this for responses that correspond to a provisional data source
3272 // of the top-most frame. If we have a provisional data source, then we
3273 // can't have any sub-resources yet, so we know that this response must
3274 // correspond to a frame load.
3275 if (!frame->provisionalDataSource() || frame->parent())
3276 return;
3277
3278 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083279 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173280 if (frame->isViewSourceModeEnabled())
3281 return;
3282
[email protected]007733c2011-11-17 00:34:073283 DocumentState* document_state =
3284 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083285 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533286
[email protected]972ebdff2010-06-10 22:59:073287 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073288 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3289 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403290 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3291 if (extra_data) {
3292 document_state->set_npn_negotiated_protocol(
3293 extra_data->npn_negotiated_protocol());
3294 }
[email protected]007733c2011-11-17 00:34:073295 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573296 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073297 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3298 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093299 // Whether or not the http status code actually corresponds to an error is
3300 // only checked when the page is done loading, if |use_error_page| is
3301 // still true.
[email protected]007733c2011-11-17 00:34:073302 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173303}
3304
[email protected]310ebd6302011-10-10 19:06:283305void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173306 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073307 DocumentState* document_state =
3308 DocumentState::FromDataSource(frame->dataSource());
3309 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173310 return;
3311
[email protected]7bfc153f2011-09-23 22:00:203312 // Do not show error page when DevTools is attached.
3313 if (devtools_agent_->IsAttached())
3314 return;
3315
[email protected]06333afe2011-02-24 14:55:093316 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073317 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083318 if (http_status_code == 404) {
3319 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413320 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173321
[email protected]b6cb3a842011-06-24 18:28:413322 const GURL& error_page_url =
3323 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093324 if (error_page_url.is_valid()) {
3325 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473326 original_error.domain = "http";
3327 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413328 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173329
[email protected]007733c2011-11-17 00:34:073330 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093331 new AltErrorPageResourceFetcher(
3332 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083333 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3334 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093335 return;
3336 }
3337 }
[email protected]3d9689372009-09-10 04:29:173338
[email protected]e6a2ce52011-10-08 01:40:133339 std::string error_domain;
3340 if (content::GetContentClient()->renderer()->HasErrorPage(
3341 http_status_code, &error_domain)) {
3342 WebURLError error;
3343 error.unreachableURL = frame->document().url();
3344 error.domain = WebString::fromUTF8(error_domain);
3345 error.reason = http_status_code;
3346
3347 LoadNavigationErrorPage(
3348 frame, frame->dataSource()->request(), error, std::string(), true);
3349 }
[email protected]3d9689372009-09-10 04:29:173350}
3351
[email protected]310ebd6302011-10-10 19:06:283352void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173353 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3354 // Ignore
3355}
3356
[email protected]310ebd6302011-10-10 19:06:283357void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173358 WebFrame* frame, const WebURLRequest& request,
3359 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003360 // The recipients of this message have no use for data: URLs: they don't
3361 // affect the page's insecure content list and are not in the disk cache. To
3362 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3363 // filter them out here.
3364 GURL url(request.url());
3365 if (url.SchemeIs("data"))
3366 return;
3367
[email protected]3d9689372009-09-10 04:29:173368 // Let the browser know we loaded a resource from the memory cache. This
3369 // message is needed to display the correct SSL indicators.
3370 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3371 routing_id_,
[email protected]84703292011-10-28 20:44:003372 url,
[email protected]70435962011-08-02 20:13:283373 response.securityInfo(),
3374 request.httpMethod().utf8(),
[email protected]6d6cfb3a2012-05-23 22:53:183375 response.mimeType().utf8(),
[email protected]70435962011-08-02 20:13:283376 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173377}
3378
[email protected]310ebd6302011-10-10 19:06:283379void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293380 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3381}
3382
[email protected]310ebd6302011-10-10 19:06:283383void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023384 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293385 Send(new ViewHostMsg_DidRunInsecureContent(
3386 routing_id_,
[email protected]92771112011-01-20 00:13:023387 origin.toString().utf8(),
3388 target));
[email protected]e3d60e5d2009-09-25 21:08:293389}
3390
[email protected]310ebd6302011-10-10 19:06:283391void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033392 webkit_glue::WebURLLoaderImpl* loader_impl =
3393 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3394 loader_impl->UpdateRoutingId(routing_id_);
3395}
3396
[email protected]310ebd6302011-10-10 19:06:283397void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173398 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3399}
3400
[email protected]310ebd6302011-10-10 19:06:283401void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3402 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583403 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283404 int world_id) {
[email protected]5bc10932011-09-21 21:03:303405 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583406 frame, context, extension_group, world_id);
3407}
3408
3409void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3410 v8::Handle<v8::Context> context,
3411 int world_id) {
3412 content::GetContentClient()->renderer()->DidCreateScriptContext(
3413 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283414}
3415
[email protected]310ebd6302011-10-10 19:06:283416void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3417 v8::Handle<v8::Context> context,
3418 int world_id) {
[email protected]5bc10932011-09-21 21:03:303419 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3420 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283421}
3422
[email protected]310ebd6302011-10-10 19:06:283423void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073424 // We don't always want to send the change messages over IPC, only if we've
3425 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3426 // message.
3427 if (!send_preferred_size_changes_ || !webview())
3428 return;
3429
[email protected]705243f2010-05-05 19:58:073430 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3431 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533432
3433 // In the presence of zoom, these sizes are still reported as if unzoomed,
3434 // so we need to adjust.
3435 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3436 size.set_width(static_cast<int>(size.width() * zoom_factor));
3437 size.set_height(static_cast<int>(size.height() * zoom_factor));
3438
[email protected]705243f2010-05-05 19:58:073439 if (size == preferred_size_)
3440 return;
[email protected]c27324b2009-11-19 22:44:293441
[email protected]705243f2010-05-05 19:58:073442 preferred_size_ = size;
3443 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3444 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173445}
3446
[email protected]273558fb2012-01-12 15:03:513447void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]7082fb942012-05-16 23:44:593448 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:403449 return;
3450
[email protected]4fb0f202012-05-30 22:44:533451#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513452 if (!p2p_socket_dispatcher_)
3453 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]273558fb2012-01-12 15:03:513454
[email protected]273558fb2012-01-12 15:03:513455 if (!media_stream_dispatcher_)
3456 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3457
[email protected]1bc65a42012-04-23 09:31:253458 if (!media_stream_impl_) {
[email protected]f3625c0b2012-05-03 09:18:283459 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory(
3460 RenderThreadImpl::current()->video_capture_impl_manager());
[email protected]273558fb2012-01-12 15:03:513461 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253462 this,
[email protected]273558fb2012-01-12 15:03:513463 media_stream_dispatcher_,
3464 p2p_socket_dispatcher_,
3465 RenderThreadImpl::current()->video_capture_impl_manager(),
3466 factory);
3467 }
[email protected]5b87e782012-02-09 18:19:323468#endif
[email protected]273558fb2012-01-12 15:03:513469}
3470
[email protected]310ebd6302011-10-10 19:06:283471void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3472 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313473 if (webview()->mainFrame() != frame)
3474 return;
3475 WebView* frameView = frame->view();
3476 if (!frameView)
3477 return;
3478
3479 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3480 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3481
3482 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3483 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3484 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3485 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3486
3487 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3488 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3489 }
3490}
3491
[email protected]310ebd6302011-10-10 19:06:283492void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313493 WebSize offset = frame->scrollOffset();
3494 WebSize minimum_offset = frame->minimumScrollOffset();
3495 WebSize maximum_offset = frame->maximumScrollOffset();
3496
3497 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3498 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3499
3500 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3501 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3502 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3503 routing_id_, is_pinned_to_left, is_pinned_to_right));
3504
3505 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3506 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3507 }
3508}
3509
[email protected]310ebd6302011-10-10 19:06:283510void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493511 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313512
3513 if (webview()->mainFrame() == frame)
3514 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:263515
3516 FOR_EACH_OBSERVER(
3517 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:313518}
3519
[email protected]310ebd6302011-10-10 19:06:283520void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313521 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493522}
3523
[email protected]ea931252012-02-15 22:01:033524void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3525 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3526}
3527
[email protected]310ebd6302011-10-10 19:06:283528void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3529 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113530 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3531 if (!count)
3532 active_match_ordinal = 0;
3533
3534 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3535 routing_id_,
3536 request_id,
3537 count,
3538 gfx::Rect(),
3539 active_match_ordinal,
3540 final_update);
3541
[email protected]8922e1f2009-10-03 05:01:263542 // If we have a message that has been queued up, then we should just replace
3543 // it. The ACK from the browser will make sure it gets sent when the browser
3544 // wants it.
3545 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263546 queued_find_reply_message_.reset(msg);
3547 } else {
3548 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113549 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263550 }
3551}
3552
[email protected]310ebd6302011-10-10 19:06:283553void RenderViewImpl::reportFindInPageSelection(int request_id,
3554 int active_match_ordinal,
3555 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263556 // Send the search result over to the browser process.
3557 Send(new ViewHostMsg_Find_Reply(routing_id_,
3558 request_id,
3559 -1,
3560 selection_rect,
3561 active_match_ordinal,
3562 false));
3563}
3564
[email protected]310ebd6302011-10-10 19:06:283565void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223566 WebFrame* frame,
3567 WebFileSystem::Type type,
3568 long long size,
[email protected]d275d7a2010-11-03 01:34:493569 bool create,
[email protected]2b06a992010-08-21 05:48:223570 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083571 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223572
[email protected]b6cb3a842011-06-24 18:28:413573 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563574 if (origin.isUnique()) {
3575 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083576 callbacks->didFail(WebKit::WebFileErrorAbort);
3577 return;
3578 }
[email protected]2b06a992010-08-21 05:48:223579
[email protected]c5a272d2010-09-27 18:37:083580 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3581 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493582 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223583}
3584
[email protected]310ebd6302011-10-10 19:06:283585void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403586 WebFrame* frame,
3587 WebStorageQuotaType type,
3588 WebStorageQuotaCallbacks* callbacks) {
3589 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413590 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563591 if (origin.isUnique()) {
3592 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403593 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3594 return;
3595 }
3596 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533597 GURL(origin.toString()),
3598 static_cast<quota::StorageType>(type),
3599 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403600}
3601
[email protected]310ebd6302011-10-10 19:06:283602void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403603 WebFrame* frame,
3604 WebStorageQuotaType type,
3605 unsigned long long requested_size,
3606 WebStorageQuotaCallbacks* callbacks) {
3607 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413608 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563609 if (origin.isUnique()) {
3610 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403611 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3612 return;
3613 }
3614 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533615 routing_id(), GURL(origin.toString()),
3616 static_cast<quota::StorageType>(type), requested_size,
3617 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403618}
3619
[email protected]8b5af492011-11-28 21:50:583620void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153621 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]3a3b75a2012-06-01 08:38:363622 webkit_glue::WebIntentServiceData data(service);
3623 if (data.title.empty())
3624 data.title = webview()->mainFrame()->document().title();
3625 bool user_gesture = frame->isProcessingUserGesture();
[email protected]8b5af492011-11-28 21:50:583626 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
[email protected]3a3b75a2012-06-01 08:38:363627 data,
3628 user_gesture));
[email protected]8b5af492011-11-28 21:50:583629}
3630
[email protected]ffc8bed2012-01-21 01:23:153631void RenderViewImpl::dispatchIntent(
3632 WebFrame* frame, const WebIntentRequest& intentRequest) {
3633 webkit_glue::WebIntentData intent_data(intentRequest.intent());
[email protected]4e1eb3392012-05-18 00:08:053634
3635 // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued()
3636 WebKit::WebMessagePortChannelArray* channels =
3637 intentRequest.intent().messagePortChannelsRelease();
3638 if (channels) {
3639 for (size_t i = 0; i < channels->size(); ++i) {
3640 WebMessagePortChannelImpl* webchannel =
3641 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
3642 intent_data.message_port_ids.push_back(webchannel->message_port_id());
3643 DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE);
3644 }
3645 delete channels;
3646 }
3647
[email protected]ffc8bed2012-01-21 01:23:153648 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583649 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153650 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583651}
3652
[email protected]f546640b2012-05-15 00:03:493653bool RenderViewImpl::willCheckAndDispatchMessageEvent(
3654 WebKit::WebFrame* source,
3655 WebKit::WebSecurityOrigin target_origin,
3656 WebKit::WebDOMMessageEvent event) {
3657 if (!is_swapped_out_)
3658 return false;
3659
3660 ViewMsg_PostMessage_Params params;
3661 params.data = event.data().toString();
3662 params.source_origin = event.origin();
3663 if (!target_origin.isNull())
3664 params.target_origin = target_origin.toString();
3665
3666 // Include the routing ID for the source frame, which the browser process
3667 // will translate into the routing ID for the equivalent frame in the target
3668 // process.
3669 // TODO(creis): Support source subframes.
3670 params.source_routing_id = MSG_ROUTING_NONE;
3671 RenderViewImpl* source_view = FromWebView(source->view());
3672 if (source_view)
3673 params.source_routing_id = source_view->routing_id();
3674
3675 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
3676 return true;
3677}
3678
[email protected]5fa3a062012-03-21 15:39:343679void RenderViewImpl::willOpenSocketStream(
3680 WebSocketStreamHandle* handle) {
3681 SocketStreamHandleData::AddToHandle(handle, routing_id_);
3682}
3683
[email protected]18d5be92011-07-25 18:00:193684// WebKit::WebPageSerializerClient implementation ------------------------------
3685
[email protected]310ebd6302011-10-10 19:06:283686void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193687 const WebURL& frame_url,
3688 const WebCString& data,
3689 WebPageSerializerClient::PageSerializationStatus status) {
3690 Send(new ViewHostMsg_SendSerializedHtmlData(
3691 routing_id(),
3692 frame_url,
3693 data.data(),
3694 static_cast<int32>(status)));
3695}
3696
[email protected]a2ef54c2011-10-10 16:20:313697// content::RenderView implementation ------------------------------------------
3698
[email protected]310ebd6302011-10-10 19:06:283699bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313700 return RenderWidget::Send(message);
3701}
3702
[email protected]82114f52012-03-20 22:53:413703int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:313704 return routing_id_;
3705}
3706
[email protected]82114f52012-03-20 22:53:413707int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:313708 return page_id_;
3709}
3710
[email protected]82114f52012-03-20 22:53:413711gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:313712 return size();
3713}
3714
[email protected]82114f52012-03-20 22:53:413715gfx::NativeViewId RenderViewImpl::GetHostWindow() const {
[email protected]a2ef54c2011-10-10 16:20:313716 return host_window();
3717}
3718
[email protected]82114f52012-03-20 22:53:413719WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313720 return webkit_preferences_;
3721}
3722
[email protected]82114f52012-03-20 22:53:413723WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313724 return webview();
3725}
3726
[email protected]82114f52012-03-20 22:53:413727WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313728 if (!webview())
3729 return WebNode();
3730 WebFrame* focused_frame = webview()->focusedFrame();
3731 if (focused_frame) {
3732 WebDocument doc = focused_frame->document();
3733 if (!doc.isNull())
3734 return doc.focusedNode();
3735 }
3736
3737 return WebNode();
3738}
3739
[email protected]82114f52012-03-20 22:53:413740WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313741 return context_menu_node_;
3742}
3743
[email protected]82114f52012-03-20 22:53:413744bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) const {
[email protected]a2ef54c2011-10-10 16:20:313745 bool is_editable_node = false;
3746 if (!node.isNull()) {
3747 if (node.isContentEditable()) {
3748 is_editable_node = true;
3749 } else if (node.isElementNode()) {
3750 is_editable_node =
3751 node.toConst<WebElement>().isTextFormControlElement();
3752 }
3753 }
3754 return is_editable_node;
3755}
3756
[email protected]468e4902012-05-23 01:49:313757void RenderViewImpl::GuestReady(PP_Instance instance) {
3758 guest_pp_instance_ = instance;
3759 if (guest_uninitialized_context_) {
[email protected]7900bfdb2012-05-24 19:31:243760 bool success = GetGuestToEmbedderChannel()->CreateGraphicsContext(
[email protected]468e4902012-05-23 01:49:313761 guest_uninitialized_context_,
3762 guest_attributes_,
3763 false,
3764 this);
3765 DCHECK(success);
[email protected]7900bfdb2012-05-24 19:31:243766 CompleteInit(host_window_);
3767 guest_uninitialized_context_ = NULL;
[email protected]468e4902012-05-23 01:49:313768 }
[email protected]468e4902012-05-23 01:49:313769}
3770
3771webkit::ppapi::WebPluginImpl* RenderViewImpl::CreateBrowserPlugin(
3772 const IPC::ChannelHandle& channel_handle,
3773 int guest_process_id,
3774 const WebKit::WebPluginParams& params) {
3775 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3776 pepper_delegate_.CreateBrowserPluginModule(channel_handle,
3777 guest_process_id));
3778 return new webkit::ppapi::WebPluginImpl(
3779 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3780}
3781
[email protected]310ebd6302011-10-10 19:06:283782WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313783 WebKit::WebFrame* frame,
3784 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:413785 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:313786 bool pepper_plugin_was_registered = false;
3787 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3788 pepper_delegate_.CreatePepperPluginModule(info,
3789 &pepper_plugin_was_registered));
3790 if (pepper_plugin_was_registered) {
3791 if (!pepper_module)
3792 return NULL;
3793 return new webkit::ppapi::WebPluginImpl(
3794 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3795 }
3796
[email protected]34b27e442012-01-20 20:07:413797#if defined(USE_AURA)
3798 return NULL;
3799#else
[email protected]a2ef54c2011-10-10 16:20:313800 return new webkit::npapi::WebPluginImpl(
3801 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413802#endif
[email protected]a2ef54c2011-10-10 16:20:313803}
3804
[email protected]310ebd6302011-10-10 19:06:283805void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3806 const string16& jscript,
3807 int id,
3808 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313809 v8::Handle<v8::Value> result;
3810 WebFrame* web_frame = GetChildFrame(frame_xpath);
3811 if (web_frame)
3812 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3813 if (notify_result) {
3814 ListValue list;
3815 if (!result.IsEmpty() && web_frame) {
3816 v8::HandleScope handle_scope;
3817 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3818 v8::Context::Scope context_scope(context);
3819 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:513820 converter.SetDateAllowed(true);
3821 converter.SetRegexpAllowed(true);
[email protected]a2ef54c2011-10-10 16:20:313822 list.Set(0, converter.FromV8Value(result, context));
3823 } else {
3824 list.Set(0, Value::CreateNullValue());
3825 }
3826 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3827 }
3828}
3829
[email protected]310ebd6302011-10-10 19:06:283830bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313831 return (!send_preferred_size_changes_ ||
3832 (disable_scrollbars_size_limit_.width() <= width ||
3833 disable_scrollbars_size_limit_.height() <= height));
3834}
3835
[email protected]82114f52012-03-20 22:53:413836int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:313837 return enabled_bindings_;
3838}
3839
[email protected]82114f52012-03-20 22:53:413840bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:313841 return send_content_state_immediately_;
3842}
3843
[email protected]82114f52012-03-20 22:53:413844float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:313845 return filtered_time_per_frame();
3846}
3847
[email protected]310ebd6302011-10-10 19:06:283848void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
[email protected]82114f52012-03-20 22:53:413849 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313850 showContextMenu(frame, data);
3851}
3852
[email protected]82114f52012-03-20 22:53:413853WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313854 return visibilityState();
3855}
3856
[email protected]310ebd6302011-10-10 19:06:283857void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3858 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313859 return runModalAlertDialog(frame, message);
3860}
3861
[email protected]310ebd6302011-10-10 19:06:283862void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313863 WebKit::WebFrame* frame,
3864 const WebKit::WebURLRequest& request,
3865 WebKit::WebNavigationPolicy policy) {
3866 loadURLExternally(frame, request, policy);
3867}
3868
3869// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513870
[email protected]310ebd6302011-10-10 19:06:283871webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533872 const FilePath& file_path,
3873 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203874 if (!PluginChannelHost::IsListening()) {
3875 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593876 return NULL;
[email protected]94752ee2012-02-10 10:38:203877 }
[email protected]f103ab72009-09-02 17:10:593878
[email protected]00c39612010-03-06 02:53:283879 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463880 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323881#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223882 return webkit::npapi::WebPluginDelegateImpl::Create(
3883 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093884#else
[email protected]7398dcc2011-09-06 21:40:323885 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223886 NOTIMPLEMENTED();
3887 return NULL;
[email protected]7b6616f2010-01-14 18:07:553888#endif
[email protected]f103ab72009-09-02 17:10:593889 }
3890
[email protected]4e0616e2010-05-28 14:55:533891 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593892}
3893
[email protected]6ac77cb2012-05-01 14:49:013894WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
3895 const FilePath& file_path) {
3896 return content::GetContentClient()->renderer()->CreatePluginReplacement(
3897 this, file_path);
3898}
3899
[email protected]310ebd6302011-10-10 19:06:283900void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033901#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273902 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593903#endif
3904}
3905
[email protected]310ebd6302011-10-10 19:06:283906void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033907#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273908 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593909#endif
3910 CleanupWindowInPluginMoves(window);
3911}
3912
[email protected]310ebd6302011-10-10 19:06:283913void RenderViewImpl::DidMovePlugin(
3914 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593915 SchedulePluginMove(move);
3916}
3917
[email protected]310ebd6302011-10-10 19:06:283918void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593919 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523920 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593921}
3922
[email protected]310ebd6302011-10-10 19:06:283923void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593924 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523925 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593926}
3927
[email protected]310ebd6302011-10-10 19:06:283928WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513929 return &cookie_jar_;
3930}
3931
[email protected]5d65fe92012-06-02 00:48:553932void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:073933 Send(new ViewHostMsg_MediaNotification(routing_id_,
3934 reinterpret_cast<int64>(player),
3935 player->hasVideo(),
3936 player->hasAudio(),
3937 true));
3938}
3939
[email protected]5d65fe92012-06-02 00:48:553940void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:073941 Send(new ViewHostMsg_MediaNotification(routing_id_,
3942 reinterpret_cast<int64>(player),
3943 player->hasVideo(),
3944 player->hasAudio(),
3945 false));
3946}
3947
[email protected]5d65fe92012-06-02 00:48:553948void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:073949 DidPause(player);
3950}
3951
[email protected]310ebd6302011-10-10 19:06:283952void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293953 if (!webview())
3954 return;
3955
[email protected]26aa0482009-09-30 16:55:273956 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:053957 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:293958}
3959
[email protected]310ebd6302011-10-10 19:06:283960void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363961 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003962 if (!frame)
3963 return;
[email protected]b781ff282011-08-20 06:19:363964
[email protected]e99ef6f2011-10-16 01:13:003965 string16 text;
3966 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:523967 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:003968
[email protected]3c8c74c2012-03-15 07:34:523969 if (pepper_delegate_.IsPluginFocused()) {
3970 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:413971 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:523972 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:003973 } else {
[email protected]3c8c74c2012-03-15 07:34:523974 size_t location, length;
3975 if (!webview()->caretOrSelectionRange(&location, &length))
3976 return;
3977
3978 range = ui::Range(location, location + length);
3979
3980 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3981 // If current focused element is editable, we will send 100 more chars
3982 // before and after selection. It is for input method surrounding text
3983 // feature.
3984 if (location > kExtraCharsBeforeAndAfterSelection)
3985 offset = location - kExtraCharsBeforeAndAfterSelection;
3986 else
3987 offset = 0;
3988 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3989 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3990 if (!webrange.isNull())
3991 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3992 } else {
3993 offset = location;
3994 text = frame->selectionAsText();
3995 // http://crbug.com/101435
3996 // In some case, frame->selectionAsText() returned text's length is not
3997 // equal to the length returned from webview()->caretOrSelectionRange().
3998 // So we have to set the range according to text.length().
3999 range.set_end(range.start() + text.length());
4000 }
[email protected]b781ff282011-08-20 06:19:364001 }
4002
[email protected]b781ff282011-08-20 06:19:364003 // Sometimes we get repeated didChangeSelection calls from webkit when
4004 // the selection hasn't actually changed. We don't want to report these
4005 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004006 if (selection_text_offset_ != offset ||
4007 selection_range_ != range ||
4008 selection_text_ != text) {
4009 selection_text_ = text;
4010 selection_text_offset_ = offset;
4011 selection_range_ = range;
4012 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4013 }
[email protected]b781ff282011-08-20 06:19:364014}
4015
[email protected]310ebd6302011-10-10 19:06:284016GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4017 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554018 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294019 // If the URL that failed was secure, then the embedding web page was not
4020 // expecting a network attacker to be able to manipulate its contents. As
4021 // we fetch alternate error pages over HTTP, we would be allowing a network
4022 // attacker to manipulate the contents of the response if we tried to use
4023 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154024 return GURL();
initial.commit09911bf2008-07-26 23:55:294025 }
4026
4027 // Grab the base URL from the browser process.
4028 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154029 return GURL();
initial.commit09911bf2008-07-26 23:55:294030
4031 // Strip query params from the failed URL.
4032 GURL::Replacements remove_params;
4033 remove_params.ClearUsername();
4034 remove_params.ClearPassword();
4035 remove_params.ClearQuery();
4036 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554037 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504038 std::string spec_to_send = url_to_send.spec();
4039 // Notify link doctor of the url truncation by sending of "?" at the end.
4040 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414041 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294042
4043 // Construct the query params to send to link doctor.
4044 std::string params(alternate_error_page_url_.query());
4045 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024046 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294047 params.append("&sourceid=chrome");
4048 params.append("&error=");
4049 switch (error_type) {
4050 case DNS_ERROR:
4051 params.append("dnserror");
4052 break;
4053
4054 case HTTP_404:
4055 params.append("http404");
4056 break;
4057
[email protected]5df266ac2008-10-15 19:50:134058 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334059 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134060 break;
4061
initial.commit09911bf2008-07-26 23:55:294062 default:
4063 NOTREACHED() << "unknown ErrorPageType";
4064 }
4065
4066 // OK, build the final url to return.
4067 GURL::Replacements link_doctor_params;
4068 link_doctor_params.SetQueryStr(params);
4069 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4070 return url;
4071}
4072
[email protected]310ebd6302011-10-10 19:06:284073GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:594074 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
4075 return GURL();
4076 else
4077 return creator_url_;
4078}
4079
[email protected]69ddf852012-02-21 23:21:314080GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4081 WebDataSource* ds = frame->dataSource();
4082 if (ds->hasUnreachableURL())
4083 return ds->unreachableURL();
4084
4085 const WebURLRequest& request = ds->request();
4086 return request.url();
4087}
4088
[email protected]310ebd6302011-10-10 19:06:284089WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:274090 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:314091 web_ui_bindings_.reset(new WebUIBindings(
4092 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:464093 }
[email protected]c50008512011-02-03 01:17:274094 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464095}
4096
[email protected]310ebd6302011-10-10 19:06:284097WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014098 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494099}
4100
[email protected]310ebd6302011-10-10 19:06:284101void RenderViewImpl::OnFind(int request_id, const string16& search_text,
4102 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274103 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494104
[email protected]872542532011-06-23 00:43:164105 // Check if the plugin still exists in the document.
4106 if (main_frame->document().isPluginDocument() &&
4107 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494108 if (options.findNext) {
4109 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014110 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494111 } else {
[email protected]afdbd142010-07-10 08:01:234112 if (GetWebPluginFromPluginDocument()->startFind(
4113 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494114 } else {
[email protected]e7c58a32010-08-13 19:47:114115 // Send "no results".
4116 Send(new ViewHostMsg_Find_Reply(routing_id_,
4117 request_id,
4118 0,
4119 gfx::Rect(),
4120 0,
4121 true));
[email protected]24a7f3c2010-03-25 08:26:494122 }
4123 }
4124 return;
4125 }
4126
[email protected]b4bb2502009-10-01 22:35:274127 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274128 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294129 WebFrame* search_frame = focused_frame; // start searching focused frame.
4130
4131 bool multi_frame = (frame_after_main != main_frame);
4132
4133 // If we have multiple frames, we don't want to wrap the search within the
4134 // frame, so we check here if we only have main_frame in the chain.
4135 bool wrap_within_frame = !multi_frame;
4136
[email protected]b3f2b912009-04-09 16:18:524137 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294138 bool result = false;
4139
[email protected]7830da3e2009-11-06 16:27:264140 // If something is selected when we start searching it means we cannot just
4141 // increment the current match ordinal; we need to re-generate it.
4142 WebRange current_selection = focused_frame->selectionRange();
4143
initial.commit09911bf2008-07-26 23:55:294144 do {
[email protected]dd7daa82009-08-10 05:46:454145 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594146 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294147
4148 if (!result) {
4149 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224150 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294151
4152 // Find the next frame, but skip the invisible ones.
4153 do {
4154 // What is the next frame to search? (we might be going backwards). Note
4155 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594156 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274157 search_frame->traverseNext(true) :
4158 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454159 } while (!search_frame->hasVisibleContent() &&
4160 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294161
[email protected]884db412008-11-24 23:46:504162 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224163 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294164
4165 // If we have multiple frames and we have wrapped back around to the
4166 // focused frame, we need to search it once more allowing wrap within
4167 // the frame, otherwise it will report 'no match' if the focused frame has
4168 // reported matches, but no frames after the focused_frame contain a
4169 // match for the search word(s).
4170 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454171 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594172 request_id, search_text, options, true, // Force wrapping.
4173 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294174 }
4175 }
4176
[email protected]26aa0482009-09-30 16:55:274177 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294178 } while (!result && search_frame != focused_frame);
4179
[email protected]7830da3e2009-11-06 16:27:264180 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294181 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454182 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294183 } else {
4184 // If nothing is found, set result to "0 of 0", otherwise, set it to
4185 // "-1 of 1" to indicate that we found at least one item, but we don't know
4186 // yet what is active.
4187 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4188 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294189
[email protected]4f3dc372009-02-24 00:10:294190 // If we find no matches then this will be our last status update.
4191 // Otherwise the scoping effort will send more results.
4192 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294193
[email protected]4f3dc372009-02-24 00:10:294194 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404195 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594196 request_id,
[email protected]4f3dc372009-02-24 00:10:294197 match_count,
4198 selection_rect,
4199 ordinal,
4200 final_status_update));
initial.commit09911bf2008-07-26 23:55:294201
initial.commit09911bf2008-07-26 23:55:294202 // Scoping effort begins, starting with the mainframe.
4203 search_frame = main_frame;
4204
[email protected]dd7daa82009-08-10 05:46:454205 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294206
4207 do {
4208 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454209 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294210
4211 // We don't start another scoping effort unless at least one match has
4212 // been found.
4213 if (result) {
4214 // Start new scoping request. If the scoping function determines that it
4215 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454216 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594217 search_text,
4218 options,
initial.commit09911bf2008-07-26 23:55:294219 true); // reset the tickmarks
4220 }
4221
4222 // Iterate to the next frame. The frame will not necessarily scope, for
4223 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274224 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294225 } while (search_frame != main_frame);
4226 }
4227}
4228
[email protected]815dd9872011-11-23 18:40:304229void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494230 WebView* view = webview();
4231 if (!view)
4232 return;
4233
4234 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164235 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014236 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494237 return;
4238 }
4239
[email protected]815dd9872011-11-23 18:40:304240 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494241 if (clear_selection)
4242 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4243
4244 WebFrame* frame = view->mainFrame();
4245 while (frame) {
4246 frame->stopFinding(clear_selection);
4247 frame = frame->traverseNext(false);
4248 }
4249
[email protected]815dd9872011-11-23 18:40:304250 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494251 WebFrame* focused_frame = view->focusedFrame();
4252 if (focused_frame) {
4253 WebDocument doc = focused_frame->document();
4254 if (!doc.isNull()) {
4255 WebNode node = doc.focusedNode();
4256 if (!node.isNull())
4257 node.simulateClick();
4258 }
4259 }
4260 }
4261}
4262
[email protected]310ebd6302011-10-10 19:06:284263void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:494264 // Check if there is any queued up request waiting to be sent.
4265 if (queued_find_reply_message_.get()) {
4266 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424267 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494268 }
4269}
4270
[email protected]54087fe2011-10-28 22:02:484271void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514272 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4273 return;
4274
[email protected]258d31122010-05-09 10:59:414275 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104276
[email protected]b75b8292010-10-01 07:28:254277 double old_zoom_level = webview()->zoomLevel();
4278 double zoom_level;
[email protected]54087fe2011-10-28 22:02:484279 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254280 zoom_level = 0;
4281 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4282 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484283 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254284 } else {
4285 // Either the user hit the zoom factor limit and thus the zoom level is now
4286 // not a whole number, or a plugin changed it to a custom value. We want
4287 // to go to the next whole number so that the user can always get back to
4288 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484289 if ((old_zoom_level > 1 && zoom > 0) ||
4290 (old_zoom_level < 1 && zoom < 0)) {
4291 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254292 } else {
4293 // We're going towards 100%, so first go to the next whole number.
4294 zoom_level = static_cast<int>(old_zoom_level);
4295 }
4296 }
[email protected]b75b8292010-10-01 07:28:254297 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414298 zoomLevelChanged();
4299}
4300
4301void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
4302 int zoom_center_x, int zoom_center_y) {
4303 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4304 kScalingIncrementForGesture);
4305}
4306
4307void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
4308 int zoom_center_x,
4309 int zoom_center_y,
4310 float scaling_increment) {
4311 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4312 return;
4313
[email protected]c514d6372011-08-16 22:54:444314 double old_page_scale_factor = webview()->pageScaleFactor();
4315 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:484316 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444317 page_scale_factor = 1.0;
4318 } else {
4319 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414320 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444321 }
[email protected]47578fa02011-11-02 19:34:414322 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094323 webview()->setPageScaleFactor(page_scale_factor,
4324 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414325 }
[email protected]40bd6582009-12-04 23:49:514326}
4327
[email protected]310ebd6302011-10-10 19:06:284328void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174329 webview()->hidePopups();
4330 webview()->setZoomLevel(false, zoom_level);
4331 zoomLevelChanged();
4332}
4333
[email protected]310ebd6302011-10-10 19:06:284334void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4335 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544336 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294337}
4338
[email protected]310ebd6302011-10-10 19:06:284339void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274340 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294341}
4342
[email protected]310ebd6302011-10-10 19:06:284343void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274344 WebString no_encoding;
4345 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184346}
4347
[email protected]310ebd6302011-10-10 19:06:284348WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454349 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274350 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454351
4352 // xpath string can represent a frame deep down the tree (across multiple
4353 // frame DOMs).
4354 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4355 // should break into 2 xpaths
4356 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414357 std::vector<string16> xpaths;
4358 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454359
[email protected]26aa0482009-09-30 16:55:274360 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414361 for (std::vector<string16>::const_iterator i = xpaths.begin();
4362 frame && i != xpaths.end(); ++i) {
4363 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294364 }
4365
[email protected]dd7daa82009-08-10 05:46:454366 return frame;
initial.commit09911bf2008-07-26 23:55:294367}
4368
[email protected]310ebd6302011-10-10 19:06:284369void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4370 const string16& jscript,
4371 int id,
4372 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:534373 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294374}
4375
[email protected]f546640b2012-05-15 00:03:494376void RenderViewImpl::OnPostMessageEvent(
4377 const ViewMsg_PostMessage_Params& params) {
4378 // TODO(creis): Support sending to subframes.
4379 WebFrame *frame = webview()->mainFrame();
4380
4381 // Find the source frame if it exists.
4382 // TODO(creis): Support source subframes.
4383 WebFrame* source_frame = NULL;
4384 if (params.source_routing_id != MSG_ROUTING_NONE) {
4385 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
4386 if (source_view)
4387 source_frame = source_view->webview()->mainFrame();
4388 }
4389
4390 // Create an event with the message. The final parameter to initMessageEvent
4391 // is the last event ID, which is not used with postMessage.
4392 WebDOMEvent event = frame->document().createEvent("MessageEvent");
4393 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
4394 msg_event.initMessageEvent("message",
4395 // |canBubble| and |cancellable| are always false
4396 false, false,
4397 WebSerializedScriptValue::fromString(params.data),
4398 params.source_origin, source_frame, "");
4399
4400 // We must pass in the target_origin to do the security check on this side,
4401 // since it may have changed since the original postMessage call was made.
4402 WebSecurityOrigin target_origin;
4403 if (!params.target_origin.empty()) {
4404 target_origin =
4405 WebSecurityOrigin::createFromString(WebString(params.target_origin));
4406 }
4407 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
4408}
4409
[email protected]310ebd6302011-10-10 19:06:284410void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4411 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414412 WebFrame* frame = GetChildFrame(frame_xpath);
4413 if (!frame)
[email protected]216813952011-05-19 22:21:264414 return;
[email protected]ae461542009-06-19 19:03:414415
[email protected]01cf589c2011-07-28 18:04:034416 frame->document().insertUserStyleSheet(
4417 WebString::fromUTF8(css),
4418 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484419}
4420
[email protected]310ebd6302011-10-10 19:06:284421void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094422 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:044423
4424 // Keep track of the total bindings accumulated in this process.
4425 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:294426}
4427
[email protected]310ebd6302011-10-10 19:06:284428void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4429 const std::string& value) {
[email protected]808bda52012-03-09 22:43:324430 if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI)
4431 GetWebUIBindings()->SetProperty(name, value);
4432 else
4433 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:294434}
4435
[email protected]310ebd6302011-10-10 19:06:284436void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4437 const gfx::Point& client_point,
4438 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:424439 WebDragOperationsMask ops,
4440 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:554441 WebDragOperation operation = webview()->dragTargetDragEnter(
4442 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554443 client_point,
4444 screen_point,
[email protected]1f2230b2012-05-17 23:43:424445 ops,
4446 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:554447
4448 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4449}
4450
[email protected]310ebd6302011-10-10 19:06:284451void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4452 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:424453 WebDragOperationsMask ops,
4454 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:554455 WebDragOperation operation = webview()->dragTargetDragOver(
4456 client_point,
4457 screen_point,
[email protected]1f2230b2012-05-17 23:43:424458 ops,
4459 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:554460
4461 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4462}
4463
[email protected]310ebd6302011-10-10 19:06:284464void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554465 webview()->dragTargetDragLeave();
4466}
4467
[email protected]310ebd6302011-10-10 19:06:284468void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:424469 const gfx::Point& screen_point,
4470 int key_modifiers) {
4471 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:574472
4473 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554474}
4475
[email protected]310ebd6302011-10-10 19:06:284476void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4477 const gfx::Point& screen_point,
4478 bool ended,
4479 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034480 if (ended) {
[email protected]26aa0482009-09-30 16:55:274481 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204482 } else {
4483 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034484 }
initial.commit09911bf2008-07-26 23:55:294485}
4486
[email protected]310ebd6302011-10-10 19:06:284487void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274488 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294489}
4490
[email protected]310ebd6302011-10-10 19:06:284491void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594492 webkit_preferences_ = prefs;
4493 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294494}
4495
[email protected]310ebd6302011-10-10 19:06:284496void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294497 alternate_error_page_url_ = url;
4498}
4499
[email protected]310ebd6302011-10-10 19:06:284500void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514501 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084502 unsigned action) {
4503 if (custom_context.is_pepper_menu)
4504 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4505 else
4506 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584507 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4508 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334509}
4510
[email protected]310ebd6302011-10-10 19:06:284511void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514512 int id,
4513 const std::vector<FilePath>& paths) {
4514 if (!enumeration_completions_[id])
4515 return;
4516
4517 WebVector<WebString> ws_file_names(paths.size());
4518 for (size_t i = 0; i < paths.size(); ++i)
4519 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4520
4521 enumeration_completions_[id]->didChooseFile(ws_file_names);
4522 enumeration_completions_.erase(id);
4523}
4524
[email protected]fb11b6a42012-03-14 07:25:124525void RenderViewImpl::OnFileChooserResponse(
4526 const std::vector<content::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:364527 // This could happen if we navigated to a different page before the user
4528 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474529 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364530 return;
4531
[email protected]b5188522012-03-15 00:18:044532 // Convert Chrome's SelectedFileInfo list to WebKit's.
4533 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
4534 files.size());
4535 for (size_t i = 0; i < files.size(); ++i) {
4536 WebFileChooserCompletion::SelectedFileInfo selected_file;
4537 selected_file.path = webkit_glue::FilePathToWebString(files[i].path);
4538 selected_file.displayName = webkit_glue::FilePathStringToWebString(
4539 files[i].display_name);
4540 selected_files[i] = selected_file;
4541 }
[email protected]a1128322009-10-06 18:38:464542
[email protected]cdaf8d02010-03-30 19:52:474543 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:044544 file_chooser_completions_.front()->completion->didChooseFile(
4545 selected_files);
[email protected]cdaf8d02010-03-30 19:52:474546 file_chooser_completions_.pop_front();
4547
4548 // If there are more pending file chooser requests, schedule one now.
4549 if (!file_chooser_completions_.empty()) {
4550 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4551 file_chooser_completions_.front()->params));
4552 }
initial.commit09911bf2008-07-26 23:55:294553}
4554
[email protected]244ac1892011-12-02 17:04:474555void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4556 const gfx::Size& max_size) {
4557 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4558 if (!webview())
4559 return;
[email protected]61e2b3cc2012-03-02 16:13:344560 webview()->enableAutoResizeMode(min_size, max_size);
4561}
4562
4563void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
4564 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4565 if (!webview())
4566 return;
4567 webview()->disableAutoResizeMode();
4568
4569 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:474570}
4571
[email protected]2bf834f2011-11-17 20:02:214572void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244573 if (send_preferred_size_changes_)
4574 return;
[email protected]9fb325e2010-05-06 18:23:244575 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394576
[email protected]d812fd12011-05-27 23:05:074577 // Start off with an initial preferred size notification (in case
4578 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594579 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084580}
4581
[email protected]310ebd6302011-10-10 19:06:284582void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104583 const gfx::Size& disable_scrollbar_size_limit) {
4584 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4585}
4586
[email protected]310ebd6302011-10-10 19:06:284587void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314588 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504589 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514590 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374591 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:224592#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414593 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4594 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464595 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]f78452f2012-05-15 02:07:524596 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344597 renderer_prefs.thumb_inactive_color,
4598 renderer_prefs.thumb_active_color,
4599 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554600#endif
[email protected]93623c5d2009-12-10 21:40:324601
[email protected]a13283cc2012-04-05 00:21:224602#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:104603 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:224604#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:324605 webview()->setScrollbarColors(
4606 renderer_prefs.thumb_inactive_color,
4607 renderer_prefs.thumb_active_color,
4608 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554609#endif
[email protected]644d77e2010-01-27 01:03:104610 webview()->setSelectionColors(
4611 renderer_prefs.active_selection_bg_color,
4612 renderer_prefs.active_selection_fg_color,
4613 renderer_prefs.inactive_selection_bg_color,
4614 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464615 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104616 }
[email protected]7a74e102009-09-03 00:16:564617#endif
[email protected]d299d972012-03-23 02:26:554618
[email protected]d051d9a2011-12-10 02:02:504619 // If the zoom level for this page matches the old zoom default, and this
4620 // is not a plugin, update the zoom level to match the new default.
4621 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4622 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4623 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4624 zoomLevelChanged();
4625 }
[email protected]80d96fa2009-06-10 22:34:514626}
4627
[email protected]310ebd6302011-10-10 19:06:284628void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4629 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284630 if (webview())
4631 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564632}
4633
[email protected]77829642012-05-15 14:47:174634void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
4635 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
4636}
4637
[email protected]81375e872012-01-11 21:40:364638void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4639 const WebPluginAction& action) {
4640 if (webview())
4641 webview()->performPluginAction(action, location);
4642}
4643
[email protected]310ebd6302011-10-10 19:06:284644void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194645 const GURL& page_url) {
4646 // Prepare list to storage all savable resource links.
4647 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:464648 std::vector<GURL> referrer_urls_list;
4649 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:194650 std::vector<GURL> frames_list;
4651 webkit_glue::SavableResourcesResult result(&resources_list,
[email protected]c2d986512012-05-12 00:22:464652 &referrer_urls_list,
4653 &referrer_policies_list,
[email protected]18d5be92011-07-25 18:00:194654 &frames_list);
4655
[email protected]c2d986512012-05-12 00:22:464656 // webkit/ doesn't know about content::Referrer.
[email protected]18d5be92011-07-25 18:00:194657 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4658 webview(),
4659 page_url,
4660 &result,
[email protected]1de7a172012-05-28 18:36:434661 const_cast<const char**>(content::GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:194662 // If something is wrong when collecting all savable resource links,
4663 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:464664 referrer_urls_list.clear();
4665 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:194666 resources_list.clear();
4667 frames_list.clear();
4668 }
4669
[email protected]c2d986512012-05-12 00:22:464670 std::vector<content::Referrer> referrers_list;
4671 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
4672 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
4673 referrers_list.push_back(
4674 content::Referrer(referrer_urls_list[i], referrer_policies_list[i]));
4675 }
4676
[email protected]18d5be92011-07-25 18:00:194677 // Send result of all savable resource links to embedder.
4678 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4679 resources_list,
4680 referrers_list,
4681 frames_list));
4682}
4683
[email protected]310ebd6302011-10-10 19:06:284684void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194685 const std::vector<GURL>& links,
4686 const std::vector<FilePath>& local_paths,
4687 const FilePath& local_directory_name) {
4688
4689 // Convert std::vector of GURLs to WebVector<WebURL>
4690 WebVector<WebURL> weburl_links(links);
4691
4692 // Convert std::vector of std::strings to WebVector<WebString>
4693 WebVector<WebString> webstring_paths(local_paths.size());
4694 for (size_t i = 0; i < local_paths.size(); i++)
4695 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4696
4697 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4698 webstring_paths,
4699 webkit_glue::FilePathToWebString(
4700 local_directory_name));
4701}
4702
[email protected]310ebd6302011-10-10 19:06:284703void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:124704 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:274705 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:124706 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
4707 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
4708 before_unload_start_time,
4709 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:294710}
4711
[email protected]310ebd6302011-10-10 19:06:284712void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:314713 // Ensure that no other in-progress navigation continues.
4714 OnStop();
4715
[email protected]73eb2602012-02-09 19:50:554716 // Only run unload if we're not swapped out yet, but send the ack either way.
4717 if (!is_swapped_out_) {
4718 // Swap this RenderView out so the tab can navigate to a page rendered by a
4719 // different process. This involves running the unload handler and clearing
4720 // the page. Once WasSwappedOut is called, we also allow this process to
4721 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154722
[email protected]73eb2602012-02-09 19:50:554723 // Send an UpdateState message before we get swapped out.
4724 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154725
[email protected]73eb2602012-02-09 19:50:554726 // Synchronously run the unload handler before sending the ACK.
4727 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154728
[email protected]73eb2602012-02-09 19:50:554729 // Swap out and stop sending any IPC messages that are not ACKs.
4730 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154731
[email protected]285f4bb82012-04-17 15:57:284732 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:554733 // run a second time, thanks to a check in FrameLoader::stopLoading.
4734 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:284735 // beforeunload handler. For now, we just run it a second time silently.
[email protected]14392a52012-05-02 20:28:444736 NavigateToSwappedOutURL();
[email protected]961541a92012-06-01 21:15:284737
4738 // Let WebKit know that this view is hidden so it can drop resources and
4739 // stop compositing.
4740 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:554741 }
[email protected]992db4c2011-05-12 15:37:154742
4743 // Just echo back the params in the ACK.
4744 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4745}
4746
[email protected]14392a52012-05-02 20:28:444747void RenderViewImpl::NavigateToSwappedOutURL() {
4748 // We use loadRequest instead of loadHTMLString because the former commits
4749 // synchronously. Otherwise a new navigation can interrupt the navigation
4750 // to content::kSwappedOutURL. If that happens to be to the page we had been
4751 // showing, then WebKit will never send a commit and we'll be left spinning.
4752 GURL swappedOutURL(content::kSwappedOutURL);
4753 WebURLRequest request(swappedOutURL);
4754 webview()->mainFrame()->loadRequest(request);
4755}
4756
[email protected]310ebd6302011-10-10 19:06:284757void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374758 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294759 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4760 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4761 // in the onunload handler from appearing. For now, we're bypassing that and
4762 // calling the FrameLoader's CloseURL method directly. This should be
4763 // revisited to avoid having two ways to close a page. Having a single way
4764 // to close that can run onunload is also useful for fixing
4765 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274766 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294767
[email protected]992db4c2011-05-12 15:37:154768 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294769}
4770
[email protected]310ebd6302011-10-10 19:06:284771void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024772#if defined(USE_AURA)
4773 // Aura doesn't care if we switch themes.
4774#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:524775 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464776 if (webview())
4777 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574778#else // defined(OS_WIN)
4779 // TODO(port): we don't support theming on non-Windows platforms yet
4780 NOTIMPLEMENTED();
4781#endif
initial.commit09911bf2008-07-26 23:55:294782}
4783
[email protected]310ebd6302011-10-10 19:06:284784void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084785 if (decrement_shared_popup_at_destruction_)
4786 shared_popup_counter_->data--;
4787 shared_popup_counter_ = new SharedRenderViewCounter(0);
4788 decrement_shared_popup_at_destruction_ = false;
4789}
4790
[email protected]310ebd6302011-10-10 19:06:284791bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4792 const WebURLError& error,
4793 bool replace) {
[email protected]15d79e12009-08-02 19:23:454794 // We only show alternate error pages in the main frame. They are
4795 // intended to assist the user when navigating, so there is not much
4796 // value in showing them for failed subframes. Ideally, we would be
4797 // able to use the TYPED transition type for this, but that flag is
4798 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454799 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454800 return false;
4801
4802 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374803 // connection failure.
[email protected]15d79e12009-08-02 19:23:454804 int ec = error.reason;
4805 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4806 ec != net::ERR_CONNECTION_FAILED &&
4807 ec != net::ERR_CONNECTION_REFUSED &&
4808 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:414809 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:454810 return false;
[email protected]82114f52012-03-20 22:53:414811 }
[email protected]15d79e12009-08-02 19:23:454812
4813 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554814 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454815 if (!error_page_url.is_valid())
4816 return false;
4817
4818 // Load an empty page first so there is an immediate response to the error,
4819 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454820 frame->loadHTMLString(std::string(),
[email protected]285f4bb82012-04-17 15:57:284821 GURL(content::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454822 error.unreachableURL,
4823 replace);
4824
4825 // Now, create a fetcher for the error page and associate it with the data
4826 // source we just created via the LoadHTMLString call. That way if another
4827 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074828 DocumentState* document_state =
4829 DocumentState::FromDataSource(frame->provisionalDataSource());
4830 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454831 new AltErrorPageResourceFetcher(
4832 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084833 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4834 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454835 return true;
4836}
4837
[email protected]310ebd6302011-10-10 19:06:284838void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4839 const WebURLError& original_error,
4840 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454841 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094842 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554843 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094844 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454845}
4846
[email protected]310ebd6302011-10-10 19:06:284847void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004848 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474849 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004850}
4851
[email protected]310ebd6302011-10-10 19:06:284852void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094853 const gfx::Rect& resizer_rect,
4854 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104855 if (webview()) {
[email protected]7ddea9802012-02-22 23:08:054856 // This setting has no effect if fixed layout is not enabled.
[email protected]43d9d782012-03-01 15:40:094857 if (webkit_preferences_.default_device_scale_factor)
[email protected]7ddea9802012-02-22 23:08:054858 webview()->settings()->setLayoutFallbackWidth(
[email protected]43d9d782012-03-01 15:40:094859 new_size.width() / webkit_preferences_.default_device_scale_factor);
[email protected]a72a1fa2010-05-03 22:18:474860 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104861 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204862 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314863 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104864 }
[email protected]dd6afca2011-08-13 03:44:314865 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104866 }
4867
[email protected]ee41e7d22011-10-14 19:34:094868 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004869}
[email protected]0aa477bd2009-03-23 22:21:434870
[email protected]29ed96a2012-02-04 18:12:164871void RenderViewImpl::WillInitiatePaint() {
4872 // Notify the pepper plugins that we're about to paint.
4873 pepper_delegate_.ViewWillInitiatePaint();
4874}
4875
[email protected]310ebd6302011-10-10 19:06:284876void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164877 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014878 pepper_delegate_.ViewInitiatedPaint();
[email protected]7900bfdb2012-05-24 19:31:244879 if (GetGuestToEmbedderChannel())
4880 GetGuestToEmbedderChannel()->IssueSwapBuffers(guest_graphics_resource());
[email protected]00c39612010-03-06 02:53:284881}
4882
[email protected]310ebd6302011-10-10 19:06:284883void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284884 // Notify any pepper plugins that we painted. This will call into the plugin,
4885 // and we it may ask to close itself as a result. This will, in turn, modify
4886 // our set, possibly invalidating the iterator. So we iterate on a copy that
4887 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014888 pepper_delegate_.ViewFlushedPaint();
4889
[email protected]5b1dec8c2012-02-07 04:35:384890 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4891 // See crbug.com/112921.
4892 if (!webview())
4893 return;
4894
[email protected]00c39612010-03-06 02:53:284895 WebFrame* main_frame = webview()->mainFrame();
4896
4897 // If we have a provisional frame we are between the start and commit stages
4898 // of loading and we don't want to save stats.
4899 if (!main_frame->provisionalDataSource()) {
4900 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074901 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284902
[email protected]05c8e502010-08-15 15:13:524903 // TODO(jar): The following code should all be inside a method, probably in
4904 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284905 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074906 if (document_state->first_paint_time().is_null()) {
4907 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284908 }
[email protected]007733c2011-11-17 00:34:074909 if (document_state->first_paint_after_load_time().is_null() &&
4910 !document_state->finish_load_time().is_null()) {
4911 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284912 }
4913 }
4914}
4915
[email protected]310ebd6302011-10-10 19:06:284916void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084917 RenderWidget::OnSwapBuffersPosted();
4918}
4919
[email protected]310ebd6302011-10-10 19:06:284920void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244921 RenderWidget::OnSwapBuffersComplete();
4922}
4923
[email protected]310ebd6302011-10-10 19:06:284924void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244925 RenderWidget::OnSwapBuffersAborted();
4926}
4927
[email protected]310ebd6302011-10-10 19:06:284928webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154929 const gfx::Rect& paint_bounds,
4930 TransportDIB** dib,
4931 gfx::Rect* location,
4932 gfx::Rect* clip) {
4933 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4934 paint_bounds, dib, location, clip);
4935}
4936
[email protected]310ebd6302011-10-10 19:06:284937gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074938 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434939 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524940}
4941
[email protected]310ebd6302011-10-10 19:06:284942void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164943 if (webview())
[email protected]26aa0482009-09-30 16:55:274944 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164945}
4946
[email protected]310ebd6302011-10-10 19:06:284947void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144948 if (webview())
[email protected]b4bb2502009-10-01 22:35:274949 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144950
4951 SetBackground(background);
4952}
4953
[email protected]310ebd6302011-10-10 19:06:284954void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344955 if (webview())
[email protected]b4bb2502009-10-01 22:35:274956 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264957
4958#if defined(OS_MACOSX)
4959 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4960 for (plugin_it = plugin_delegates_.begin();
4961 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4962 (*plugin_it)->SetWindowFocus(active);
4963 }
4964#endif
[email protected]8c66c5a2009-07-22 17:26:344965}
4966
[email protected]7a17bac02012-03-07 21:58:124967void RenderViewImpl::OnSetNavigationStartTime(
4968 const base::TimeTicks& browser_navigation_start) {
4969 if (!webview())
4970 return;
4971
4972 // Only the initial navigation can be a cross-renderer navigation. If we've
4973 // already navigated away from that page, we can ignore this message.
4974 if (page_id_ != -1)
4975 return;
4976
4977 // browser_navigation_start is likely before this process existed, so we can't
4978 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
4979 // ensure we don't report a bogus value in the future.
4980 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
4981 browser_navigation_start);
4982 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
4983 (navigation_start - base::TimeTicks()).InSecondsF());
4984}
4985
[email protected]6ce7abc52010-02-02 18:40:144986#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284987void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144988 // Inform plugins that their container has changed visibility.
4989 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4990 for (plugin_it = plugin_delegates_.begin();
4991 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4992 (*plugin_it)->SetContainerVisibility(visible);
4993 }
4994}
[email protected]1e6e3c992010-02-08 15:52:134995
[email protected]310ebd6302011-10-10 19:06:284996void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4997 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134998 // Inform plugins that their window's frame has changed.
4999 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5000 for (plugin_it = plugin_delegates_.begin();
5001 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5002 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5003 }
5004}
[email protected]935d63d2010-10-15 23:31:555005
[email protected]310ebd6302011-10-10 19:06:285006void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5007 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135008 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555009 // applies to it or not, so inform all the delegates.
5010 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5011 for (plugin_it = plugin_delegates_.begin();
5012 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135013 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555014 }
5015}
[email protected]6ce7abc52010-02-02 18:40:145016#endif // OS_MACOSX
5017
[email protected]310ebd6302011-10-10 19:06:285018void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:485019 const EditCommands& edit_commands) {
5020 edit_commands_ = edit_commands;
5021}
5022
[email protected]310ebd6302011-10-10 19:06:285023void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595024 // We need to grab a pointer to the doomed WebView before we destroy it.
5025 WebView* doomed = webview();
5026 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495027 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595028}
5029
[email protected]310ebd6302011-10-10 19:06:285030void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:485031 edit_commands_.clear();
5032}
5033
[email protected]310ebd6302011-10-10 19:06:285034bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:115035 pepper_delegate_.WillHandleMouseEvent();
5036
5037 // If the mouse is locked, only the current owner of the mouse lock can
5038 // process mouse events.
5039 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375040}
5041
[email protected]2b942c332012-04-25 16:26:265042void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515043 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065044}
5045
[email protected]310ebd6302011-10-10 19:06:285046void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245047 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5048}
5049
[email protected]310ebd6302011-10-10 19:06:285050void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435051 RenderWidget::OnWasHidden();
5052
[email protected]2d7b82c2012-06-01 05:57:505053#if defined(OS_ANDROID)
5054 // Inform WebMediaPlayerManagerAndroid to release all media player resources.
5055 media_player_manager_->ReleaseMediaResources();
5056#endif
5057
[email protected]a6939ca42011-02-18 17:58:075058 if (webview()) {
5059 webview()->settings()->setMinimumTimerInterval(
5060 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445061 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075062 }
5063
[email protected]204f1df2012-01-04 20:21:135064 // Inform PPAPI plugins that their page is no longer visible.
5065 pepper_delegate_.PageVisibilityChanged(false);
5066
[email protected]a6939ca42011-02-18 17:58:075067#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135068 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435069 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5070 for (plugin_it = plugin_delegates_.begin();
5071 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5072 (*plugin_it)->SetContainerVisibility(false);
5073 }
[email protected]a6939ca42011-02-18 17:58:075074#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435075}
5076
[email protected]310ebd6302011-10-10 19:06:285077void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:435078 RenderWidget::OnWasRestored(needs_repainting);
5079
[email protected]a6939ca42011-02-18 17:58:075080 if (webview()) {
5081 webview()->settings()->setMinimumTimerInterval(
5082 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445083 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075084 }
5085
[email protected]204f1df2012-01-04 20:21:135086 // Inform PPAPI plugins that their page is visible.
5087 pepper_delegate_.PageVisibilityChanged(true);
5088
[email protected]a6939ca42011-02-18 17:58:075089#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135090 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435091 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5092 for (plugin_it = plugin_delegates_.begin();
5093 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5094 (*plugin_it)->SetContainerVisibility(true);
5095 }
[email protected]784ea1ab2010-09-18 00:02:345096#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075097}
[email protected]1e6e3c992010-02-08 15:52:135098
[email protected]310ebd6302011-10-10 19:06:285099bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:385100 if (WebWidgetHandlesCompositorScheduling())
5101 return false;
5102
[email protected]05a980d7a2012-02-07 22:16:425103 if (queried_for_swapbuffers_complete_callback_)
5104 return context_has_swapbuffers_complete_callback_;
5105
5106 queried_for_swapbuffers_complete_callback_ = true;
5107
[email protected]65225772011-05-12 21:10:245108 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:425109 if (context && context->makeContextCurrent()) {
5110 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
5111 context_has_swapbuffers_complete_callback_ =
5112 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
5113 != std::string::npos;
5114 }
5115
5116 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:245117}
5118
[email protected]310ebd6302011-10-10 19:06:285119void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135120 RenderWidget::OnSetFocus(enable);
5121
[email protected]7d3c02c2010-05-05 23:10:315122 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075123 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135124 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5125 for (plugin_it = plugin_delegates_.begin();
5126 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345127#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315128 // RenderWidget's call to setFocus can cause the underlying webview's
5129 // activation state to change just like a call to setIsActive.
5130 if (enable)
5131 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345132#endif
[email protected]7d3c02c2010-05-05 23:10:315133 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135134 }
[email protected]589621b2010-09-23 22:01:075135
5136 // Notify all Pepper plugins.
5137 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135138 }
5139}
[email protected]941e4552010-02-01 21:23:435140
[email protected]310ebd6302011-10-10 19:06:285141void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:005142 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:505143 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575144}
5145
[email protected]73bf95812011-10-12 11:38:325146void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:005147 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:325148}
5149
[email protected]3f783362011-10-21 22:40:505150void RenderViewImpl::PpapiPluginCaretPositionChanged() {
5151 UpdateSelectionBounds();
5152}
5153
[email protected]b25b3ee2012-01-13 05:19:545154bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
5155 if (!pepper_delegate_.IsPluginFocused())
5156 return false;
5157 *rect = pepper_delegate_.GetCaretBounds();
5158 return true;
5159}
5160
[email protected]397c23962012-05-21 07:09:325161void RenderViewImpl::SimulateImeSetComposition(
5162 const string16& text,
5163 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5164 int selection_start,
5165 int selection_end) {
5166 OnImeSetComposition(text, underlines, selection_start, selection_end);
5167}
5168
5169void RenderViewImpl::SimulateImeConfirmComposition(
5170 const string16& text,
5171 const ui::Range& replacement_range) {
5172 OnImeConfirmComposition(text, replacement_range);
5173}
5174
[email protected]73bf95812011-10-12 11:38:325175void RenderViewImpl::PpapiPluginCancelComposition() {
5176 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
5177 ui::Range range(ui::Range::InvalidRange());
5178 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
5179}
5180
[email protected]3c8c74c2012-03-15 07:34:525181void RenderViewImpl::PpapiPluginSelectionChanged() {
5182 SyncSelectionIfRequired();
5183}
5184
[email protected]310ebd6302011-10-10 19:06:285185void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575186 const string16& text,
5187 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5188 int selection_start,
5189 int selection_end) {
[email protected]73bf95812011-10-12 11:38:325190 if (pepper_delegate_.IsPluginFocused()) {
5191 // When a PPAPI plugin has focus, we bypass WebKit.
5192 pepper_delegate_.OnImeSetComposition(text,
5193 underlines,
5194 selection_start,
5195 selection_end);
5196 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235197#if defined(OS_WIN)
5198 // When a plug-in has focus, we create platform-specific IME data used by
5199 // our IME emulator and send it directly to the focused plug-in, i.e. we
5200 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5201 // instance ID is the same one as the specified ID.)
5202 if (focused_plugin_id_ >= 0) {
5203 std::vector<int> clauses;
5204 std::vector<int> target;
5205 for (size_t i = 0; i < underlines.size(); ++i) {
5206 clauses.push_back(underlines[i].startOffset);
5207 clauses.push_back(underlines[i].endOffset);
5208 if (underlines[i].thick) {
5209 target.clear();
5210 target.push_back(underlines[i].startOffset);
5211 target.push_back(underlines[i].endOffset);
5212 }
5213 }
5214 std::set<WebPluginDelegateProxy*>::iterator it;
5215 for (it = plugin_delegates_.begin();
5216 it != plugin_delegates_.end(); ++it) {
5217 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5218 focused_plugin_id_);
5219 }
5220 return;
5221 }
5222#endif
[email protected]56ea1a62011-05-30 07:05:575223 RenderWidget::OnImeSetComposition(text,
5224 underlines,
5225 selection_start,
5226 selection_end);
5227 }
5228}
5229
[email protected]4de6d1692011-10-12 08:45:445230void RenderViewImpl::OnImeConfirmComposition(
5231 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:575232 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325233 // When a PPAPI plugin has focus, we bypass WebKit.
5234 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:575235 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235236#if defined(OS_WIN)
5237 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5238 // plug-ins. When we send IME text directly to plug-ins, we should not send
5239 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:445240 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:235241 if (focused_plugin_id_ >= 0) {
5242 std::set<WebPluginDelegateProxy*>::iterator it;
5243 for (it = plugin_delegates_.begin();
5244 it != plugin_delegates_.end(); ++it) {
5245 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5246 }
5247 return;
5248 }
5249#endif
[email protected]ebd28ac2011-10-13 18:49:055250 if (replacement_range.IsValid() && webview()) {
5251 // Select the text in |replacement_range|, it will then be replaced by
5252 // text added by the call to RenderWidget::OnImeConfirmComposition().
5253 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:165254 WebRange webrange = WebRange::fromDocumentRange(
5255 frame, replacement_range.start(), replacement_range.length());
5256 if (!webrange.isNull())
5257 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:055258 }
5259 }
[email protected]4de6d1692011-10-12 08:45:445260 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:575261 }
5262}
5263
[email protected]310ebd6302011-10-10 19:06:285264ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:325265 return pepper_delegate_.IsPluginFocused() ?
5266 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
5267}
5268
[email protected]3f783362011-10-21 22:40:505269void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
5270 if (pepper_delegate_.IsPluginFocused()) {
5271 // TODO(kinaba) http://crbug.com/101101
5272 // Current Pepper IME API does not handle selection bounds. So we simply
5273 // use the caret position as an empty range for now. It will be updated
5274 // after Pepper API equips features related to surrounding text retrieval.
5275 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
5276 *start = caret;
5277 *end = caret;
5278 return;
5279 }
5280 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455281}
5282
[email protected]310ebd6302011-10-10 19:06:285283bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:325284 return pepper_delegate_.IsPluginFocused() ?
5285 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:575286}
5287
[email protected]e6ae0f6c2011-10-04 10:39:235288#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:285289void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:235290 if (focused)
5291 focused_plugin_id_ = plugin_id;
5292 else
5293 focused_plugin_id_ = -1;
5294}
5295#endif
5296
[email protected]43f28f832010-02-03 02:28:485297#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285298void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:415299 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:135300}
5301
[email protected]310ebd6302011-10-10 19:06:285302void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:135303 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555304 // This message can be sent during event-handling, and needs to be delivered
5305 // within that context.
5306 msg->set_unblock(true);
5307 Send(msg);
5308}
5309
[email protected]310ebd6302011-10-10 19:06:285310gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235311 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:515312 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:485313 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235314 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115315 if (window) {
5316 fake_plugin_window_handles_.insert(window);
5317 }
[email protected]43f28f832010-02-03 02:28:485318 return window;
5319}
5320
[email protected]310ebd6302011-10-10 19:06:285321void RenderViewImpl::DestroyFakePluginWindowHandle(
5322 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115323 if (window && fake_plugin_window_handles_.find(window) !=
5324 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485325 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115326 fake_plugin_window_handles_.erase(window);
5327 }
[email protected]43f28f832010-02-03 02:28:485328}
5329
[email protected]310ebd6302011-10-10 19:06:285330void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
5331 gfx::PluginWindowHandle window,
5332 int32 width,
5333 int32 height,
5334 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:335335 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485336 routing_id(), window, width, height, io_surface_identifier));
5337}
5338
[email protected]310ebd6302011-10-10 19:06:285339void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335340 gfx::PluginWindowHandle window,
5341 int32 width,
5342 int32 height,
5343 TransportDIB::Handle transport_dib) {
5344 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075345 routing_id(), window, width, height, transport_dib));
5346}
5347
[email protected]310ebd6302011-10-10 19:06:285348TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335349 size_t size) {
[email protected]1aef98132010-02-23 18:00:075350 TransportDIB::Handle dib_handle;
5351 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385352 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075353 return dib_handle;
5354 // Return an invalid handle if Send() fails.
5355 return TransportDIB::DefaultHandleValue();
5356}
5357
[email protected]310ebd6302011-10-10 19:06:285358void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
5359 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075360 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5361}
5362
[email protected]310ebd6302011-10-10 19:06:285363void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325364 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:145365 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325366 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:485367}
[email protected]82114f52012-03-20 22:53:415368#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:285369
[email protected]310ebd6302011-10-10 19:06:285370bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:235371 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:475372 WebFileChooserCompletion* completion) {
5373 static const size_t kMaximumPendingFileChooseRequests = 4;
5374 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5375 // This sanity check prevents too many file choose requests from getting
5376 // queued which could DoS the user. Getting these is most likely a
5377 // programming error (there are many ways to DoS the user so it's not
5378 // considered a "real" security check), either in JS requesting many file
5379 // choosers to pop up, or in a plugin.
5380 //
5381 // TODO(brettw) we might possibly want to require a user gesture to open
5382 // a file picker, which will address this issue in a better way.
5383 return false;
5384 }
5385
5386 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5387 new PendingFileChooser(params, completion)));
5388 if (file_chooser_completions_.size() == 1) {
5389 // Actually show the browse dialog when this is the first request.
5390 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5391 }
5392 return true;
5393}
5394
[email protected]310ebd6302011-10-10 19:06:285395WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515396 if (!geolocation_dispatcher_)
5397 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5398 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255399}
[email protected]61c9f032010-03-31 23:04:195400
[email protected]310ebd6302011-10-10 19:06:285401WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:115402 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:225403#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:025404 if (!input_tag_speech_dispatcher_)
5405 input_tag_speech_dispatcher_ =
5406 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:225407#endif
[email protected]c52b2892012-03-07 11:01:025408 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:115409}
5410
[email protected]64d09222012-05-25 10:10:345411WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
5412#if defined(ENABLE_INPUT_SPEECH)
5413 if (!speech_recognition_dispatcher_)
5414 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
5415#endif
5416 return speech_recognition_dispatcher_;
5417}
5418
[email protected]310ebd6302011-10-10 19:06:285419WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515420 if (!device_orientation_dispatcher_)
5421 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5422 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535423}
5424
[email protected]310ebd6302011-10-10 19:06:285425void RenderViewImpl::zoomLimitsChanged(double minimum_level,
5426 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:255427 // For now, don't remember plugin zoom values. We don't want to mix them with
5428 // normal web content (i.e. a fixed layout plugin would usually want them
5429 // different).
5430 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5431
[email protected]b75b8292010-10-01 07:28:255432 int minimum_percent = static_cast<int>(
5433 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5434 int maximum_percent = static_cast<int>(
5435 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255436
5437 Send(new ViewHostMsg_UpdateZoomLimits(
5438 routing_id_, minimum_percent, maximum_percent, remember));
5439}
5440
[email protected]310ebd6302011-10-10 19:06:285441void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:255442 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:085443 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:265444
5445 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
5446
[email protected]b75b8292010-10-01 07:28:255447 // Tell the browser which url got zoomed so it can update the menu and the
5448 // saved values if necessary
5449 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:085450 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:415451 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:255452}
5453
[email protected]310ebd6302011-10-10 19:06:285454void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
5455 const WebString& base_url,
5456 const WebString& url,
5457 const WebString& title) {
[email protected]3a3b75a2012-06-01 08:38:365458 bool user_gesture = (webview()->focusedFrame() &&
5459 webview()->focusedFrame()->isProcessingUserGesture());
[email protected]a6d36cc2011-02-23 00:39:485460 GURL base(base_url);
5461 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
5462 if (base.GetOrigin() != absolute_url.GetOrigin()) {
5463 return;
5464 }
[email protected]f1a29a02011-10-06 23:08:445465 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
5466 UTF16ToUTF8(scheme),
5467 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:365468 title,
5469 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:485470}
5471
[email protected]310ebd6302011-10-10 19:06:285472WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:445473 WebKit::WebPageVisibilityState current_state = is_hidden() ?
5474 WebKit::WebPageVisibilityStateHidden :
5475 WebKit::WebPageVisibilityStateVisible;
5476 WebKit::WebPageVisibilityState override_state = current_state;
5477 if (content::GetContentClient()->renderer()->
5478 ShouldOverridePageVisibilityState(this,
5479 &override_state))
5480 return override_state;
5481 return current_state;
[email protected]94dec932011-05-26 20:04:215482}
5483
[email protected]273558fb2012-01-12 15:03:515484WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:515485 EnsureMediaStreamImpl();
5486 return media_stream_impl_;
5487}
5488
[email protected]310ebd6302011-10-10 19:06:285489void RenderViewImpl::OnAsyncFileOpened(
5490 base::PlatformFileError error_code,
5491 IPC::PlatformFileForTransit file_for_transit,
5492 int message_id) {
[email protected]27a9ef32010-09-10 04:06:245493 pepper_delegate_.OnAsyncFileOpened(
5494 error_code,
5495 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5496 message_id);
5497}
[email protected]caf706f2010-10-26 17:54:085498
[email protected]310ebd6302011-10-10 19:06:285499void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:475500 int request_id,
[email protected]d54305072011-06-22 20:58:435501 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:475502 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
[email protected]2b657fd2011-04-18 16:00:475503 handle);
[email protected]eb415bf0e2011-04-14 02:45:425504}
5505
[email protected]caf706f2010-10-26 17:54:085506#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285507void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155508 if (external_popup_menu_ == NULL) {
5509 // Crash reports from the field indicate that we can be notified with a
5510 // NULL external popup menu (we probably get notified twice).
5511 // If you hit this please file a bug against jcivelli and include the page
5512 // and steps to repro.
5513 NOTREACHED();
5514 return;
5515 }
[email protected]caf706f2010-10-26 17:54:085516 external_popup_menu_->DidSelectItem(selected_index);
5517 external_popup_menu_.reset();
5518}
5519#endif
[email protected]bb461532010-11-26 21:50:235520
[email protected]24d2b172012-05-26 00:54:125521#if defined(OS_ANDROID)
5522void RenderViewImpl::OnSelectPopupMenuItems(
5523 bool canceled,
5524 const std::vector<int>& selected_indices) {
5525 // It is possible to receive more than one of these calls if the user presses
5526 // a select faster than it takes for the show-select-popup IPC message to make
5527 // it to the browser UI thread. Ignore the extra-messages.
5528 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
5529 if (!external_popup_menu_.get())
5530 return;
5531
5532 external_popup_menu_->DidSelectItems(canceled, selected_indices);
5533 external_popup_menu_.reset();
5534}
5535#endif
5536
[email protected]310ebd6302011-10-10 19:06:285537void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515538 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085539 if (custom_context.is_pepper_menu)
5540 pepper_delegate_.OnContextMenuClosed(custom_context);
5541 else
5542 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105543}
[email protected]5a7b15a2011-08-22 22:48:185544
[email protected]310ebd6302011-10-10 19:06:285545void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185546 if (!webview())
5547 return;
5548 WebFrame* main_frame = webview()->mainFrame();
5549 if (!main_frame)
5550 return;
5551 main_frame->enableViewSourceMode(true);
5552}
[email protected]67bfb83f2011-09-22 03:36:375553
[email protected]310ebd6302011-10-10 19:06:285554bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085555 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405556}
[email protected]7f3c7af2011-10-20 22:52:515557
[email protected]64d0e192011-12-09 14:44:205558void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:315559 DCHECK(!java_bridge_dispatcher_);
[email protected]464750f2011-10-24 23:16:185560#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7e9c5bb02012-05-14 13:58:315561 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]464750f2011-10-24 23:16:185562#endif
[email protected]7f3c7af2011-10-20 22:52:515563}