blob: 86c2c291af5a711866d4190eec406d008daac383 [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
[email protected]5d4e36d2013-02-15 15:18:2010#include "base/auto_reset.h"
[email protected]6e806822011-11-19 01:51:0811#include "base/bind.h"
12#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5014#include "base/compiler_specific.h"
[email protected]2132d6b2013-06-05 00:15:4315#include "base/debug/alias.h"
[email protected]e7ca2892012-09-01 00:52:1516#include "base/debug/trace_event.h"
[email protected]728c2ee2013-06-25 04:01:0717#include "base/files/file_path.h"
[email protected]b1cf3372011-04-20 21:28:1018#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4919#include "base/lazy_instance.h"
[email protected]cffd7522012-10-23 19:10:5820#include "base/memory/scoped_ptr.h"
[email protected]7ccb7072013-06-10 20:56:2821#include "base/message_loop/message_loop_proxy.h"
[email protected]835d7c82010-10-14 04:38:3822#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2823#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5124#include "base/process_util.h"
[email protected]21aa99682013-06-11 07:17:0125#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2426#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4927#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0128#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1429#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0030#include "base/strings/utf_string_conversions.h"
[email protected]abb522162013-06-28 01:54:1631#include "base/time/time.h"
[email protected]8e4f44952013-06-17 23:58:2732#include "content/child/appcache_dispatcher.h"
[email protected]10208ea2013-06-06 20:08:0333#include "content/child/child_thread.h"
34#include "content/child/fileapi/file_system_dispatcher.h"
[email protected]c7199a6e2013-06-04 12:56:0135#include "content/child/fileapi/webfilesystem_callback_adapters.h"
[email protected]29e2fb42013-07-19 01:13:4736#include "content/child/npapi/webplugin_delegate_impl.h"
[email protected]10208ea2013-06-06 20:08:0337#include "content/child/quota_dispatcher.h"
[email protected]541b7b02013-06-07 00:59:3438#include "content/child/request_extra_data.h"
[email protected]10208ea2013-06-06 20:08:0339#include "content/child/webmessageportchannel_impl.h"
[email protected]127dd582011-03-16 21:32:1040#include "content/common/clipboard_messages.h"
[email protected]37666cf2011-03-13 21:51:4241#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5542#include "content/common/drag_messages.h"
[email protected]c26ad882012-02-07 06:41:2043#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1544#include "content/common/input_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5145#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1046#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0047#include "content/common/pepper_plugin_registry.h"
[email protected]5fa3a062012-03-21 15:39:3448#include "content/common/socket_stream_handle_data.h"
[email protected]e4495212012-12-06 03:09:1249#include "content/common/ssl_status_serialization.h"
[email protected]778574e2011-03-21 22:03:5050#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2151#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0452#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4853#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2954#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5155#include "content/public/common/context_menu_params.h"
[email protected]dc293a72013-07-01 11:11:2256#include "content/public/common/drop_data.h"
[email protected]41225fe2013-03-29 05:32:0257#include "content/public/common/favicon_url.h"
[email protected]8caadeb2011-11-22 02:45:2358#include "content/public/common/file_chooser_params.h"
[email protected]e4495212012-12-06 03:09:1259#include "content/public/common/ssl_status.h"
[email protected]818915cd2012-11-20 13:14:1160#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0361#include "content/public/common/url_constants.h"
[email protected]3b366ae2013-05-17 21:16:5862#include "content/public/common/url_utils.h"
[email protected]d344114c2011-10-01 01:24:3463#include "content/public/renderer/content_renderer_client.h"
[email protected]97f58132012-11-15 20:41:3264#include "content/public/renderer/context_menu_client.h"
[email protected]007733c2011-11-17 00:34:0765#include "content/public/renderer/document_state.h"
[email protected]691aa2f2013-05-28 22:52:0466#include "content/public/renderer/history_item_serialization.h"
[email protected]82ddba1c2011-10-04 00:15:3267#include "content/public/renderer/navigation_state.h"
[email protected]1ecbe862012-10-05 01:29:1468#include "content/public/renderer/password_form_conversion_utils.h"
[email protected]3a034ebb2011-10-03 19:19:4469#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3670#include "content/public/renderer/render_view_visitor.h"
[email protected]4e4646a52013-02-08 07:23:4171#include "content/renderer/accessibility/renderer_accessibility.h"
72#include "content/renderer/accessibility/renderer_accessibility_complete.h"
73#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
[email protected]e6e56752012-08-10 00:46:0674#include "content/renderer/browser_plugin/browser_plugin.h"
75#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]fb325d122012-11-20 23:58:0576#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
[email protected]3175fea2013-05-16 10:57:4877#include "content/renderer/context_menu_params_builder.h"
[email protected]230b7ef2011-03-16 22:30:1978#include "content/renderer/device_orientation_dispatcher.h"
[email protected]70019152012-12-19 11:44:1979#include "content/renderer/devtools/devtools_agent.h"
[email protected]f9526d12012-10-18 01:55:0380#include "content/renderer/disambiguation_popup_helper.h"
[email protected]766a7082012-02-03 23:39:1581#include "content/renderer/dom_automation_controller.h"
[email protected]1910fe82012-05-10 00:04:1082#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]dc293a72013-07-01 11:11:2283#include "content/renderer/drop_data_builder.h"
[email protected]55722152011-03-22 01:33:5384#include "content/renderer/external_popup_menu.h"
[email protected]f8c700ba2013-05-14 08:25:4985#include "content/renderer/fetchers/alt_error_page_resource_fetcher.h"
[email protected]230b7ef2011-03-16 22:30:1986#include "content/renderer/geolocation_dispatcher.h"
[email protected]ea5f70a2013-03-07 12:30:3687#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ba91a792013-02-06 09:48:2888#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]1784b2f2011-11-24 10:53:4889#include "content/renderer/idle_user_detector.h"
[email protected]41225fe2013-03-29 05:32:0290#include "content/renderer/image_loading_helper.h"
[email protected]66fca5bc2013-05-23 06:58:2991#include "content/renderer/ime_event_guard.h"
[email protected]c52b2892012-03-07 11:01:0292#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]92d457802013-04-01 19:18:4993#include "content/renderer/internal_document_state_data.h"
[email protected]07161902011-11-11 09:57:4294#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0295#include "content/renderer/load_progress_tracker.h"
[email protected]4a914882013-01-10 00:43:4896#include "content/renderer/media/audio_device_factory.h"
97#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]273558fb2012-01-12 15:03:5198#include "content/renderer/media/media_stream_dependency_factory.h"
99#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:40100#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:40101#include "content/renderer/media/render_media_log.h"
[email protected]ccee4862012-10-03 18:34:26102#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]6392d982013-04-16 16:59:22103#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]5e35a8d2013-07-10 19:37:21104#include "content/renderer/media/webmediaplayer_impl.h"
105#include "content/renderer/media/webmediaplayer_ms.h"
106#include "content/renderer/media/webmediaplayer_params.h"
[email protected]4a19be92011-09-22 14:25:02107#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:19108#include "content/renderer/notification_provider.h"
[email protected]6d17f6392012-12-05 05:24:54109#include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
[email protected]227692c52013-05-31 22:43:04110#include "content/renderer/render_frame_impl.h"
[email protected]8704f89b2011-04-15 00:30:05111#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:44112#include "content/renderer/render_thread_impl.h"
[email protected]8d41d7612012-11-14 20:32:19113#include "content/renderer/render_view_impl_params.h"
[email protected]89054502012-06-03 10:29:24114#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:44115#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]b18583c2012-12-18 06:55:27116#include "content/renderer/renderer_date_time_picker.h"
[email protected]663bd9e2011-03-21 01:07:01117#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:20118#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]12a936d2013-05-15 04:55:49119#include "content/renderer/savable_resources.h"
[email protected]64d09222012-05-25 10:10:34120#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]27c521a2013-05-29 20:44:32121#include "content/renderer/stats_collection_controller.h"
122#include "content/renderer/stats_collection_observer.h"
[email protected]86a7d3c2011-09-12 16:45:32123#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19124#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:21125#include "content/renderer/web_ui_extension.h"
126#include "content/renderer/web_ui_extension_data.h"
[email protected]6f516082011-03-17 19:15:35127#include "content/renderer/webplugin_delegate_proxy.h"
[email protected]29e2fb42013-07-19 01:13:47128#include "content/renderer/webplugin_impl.h"
[email protected]6f516082011-03-17 19:15:35129#include "content/renderer/websharedworker_proxy.h"
[email protected]f5961142013-04-17 23:09:42130#include "media/audio/audio_output_device.h"
[email protected]4a914882013-01-10 00:43:48131#include "media/base/audio_renderer_mixer_input.h"
[email protected]f8db8132010-12-03 00:27:49132#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41133#include "media/base/media_switches.h"
[email protected]37136d162012-04-09 23:39:19134#include "media/filters/audio_renderer_impl.h"
[email protected]b9a407e2013-07-24 07:30:02135#include "media/filters/gpu_video_decoder_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36136#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29137#include "net/base/escape.h"
138#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09139#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04140#include "net/http/http_util.h"
[email protected]d0fcff72013-07-23 02:45:43141#include "third_party/WebKit/public/platform/WebCString.h"
142#include "third_party/WebKit/public/platform/WebDragData.h"
143#include "third_party/WebKit/public/platform/WebFileSystemType.h"
144#include "third_party/WebKit/public/platform/WebHTTPBody.h"
145#include "third_party/WebKit/public/platform/WebImage.h"
146#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
147#include "third_party/WebKit/public/platform/WebPoint.h"
148#include "third_party/WebKit/public/platform/WebRect.h"
149#include "third_party/WebKit/public/platform/WebSize.h"
150#include "third_party/WebKit/public/platform/WebSocketStreamHandle.h"
151#include "third_party/WebKit/public/platform/WebString.h"
152#include "third_party/WebKit/public/platform/WebURL.h"
153#include "third_party/WebKit/public/platform/WebURLError.h"
154#include "third_party/WebKit/public/platform/WebURLRequest.h"
155#include "third_party/WebKit/public/platform/WebURLResponse.h"
156#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]2255a9332013-06-17 05:12:31157#include "third_party/WebKit/public/web/WebAccessibilityObject.h"
158#include "third_party/WebKit/public/web/WebColorName.h"
159#include "third_party/WebKit/public/web/WebDOMEvent.h"
160#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
161#include "third_party/WebKit/public/web/WebDataSource.h"
162#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
163#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
164#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
165#include "third_party/WebKit/public/web/WebDocument.h"
166#include "third_party/WebKit/public/web/WebElement.h"
167#include "third_party/WebKit/public/web/WebFileChooserParams.h"
168#include "third_party/WebKit/public/web/WebFileSystemCallbacks.h"
169#include "third_party/WebKit/public/web/WebFindOptions.h"
170#include "third_party/WebKit/public/web/WebFormControlElement.h"
171#include "third_party/WebKit/public/web/WebFormElement.h"
172#include "third_party/WebKit/public/web/WebFrame.h"
173#include "third_party/WebKit/public/web/WebHelperPlugin.h"
174#include "third_party/WebKit/public/web/WebHistoryItem.h"
175#include "third_party/WebKit/public/web/WebInputElement.h"
176#include "third_party/WebKit/public/web/WebInputEvent.h"
177#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
178#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
179#include "third_party/WebKit/public/web/WebNodeList.h"
180#include "third_party/WebKit/public/web/WebPageSerializer.h"
181#include "third_party/WebKit/public/web/WebPlugin.h"
182#include "third_party/WebKit/public/web/WebPluginAction.h"
183#include "third_party/WebKit/public/web/WebPluginContainer.h"
184#include "third_party/WebKit/public/web/WebPluginDocument.h"
185#include "third_party/WebKit/public/web/WebPluginParams.h"
186#include "third_party/WebKit/public/web/WebRange.h"
187#include "third_party/WebKit/public/web/WebScriptSource.h"
188#include "third_party/WebKit/public/web/WebSearchableFormData.h"
189#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
190#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
191#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
192#include "third_party/WebKit/public/web/WebSettings.h"
193#include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h"
194#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
195#include "third_party/WebKit/public/web/WebUserMediaClient.h"
196#include "third_party/WebKit/public/web/WebView.h"
197#include "third_party/WebKit/public/web/WebWindowFeatures.h"
198#include "third_party/WebKit/public/web/default/WebRenderTheme.h"
[email protected]1400e6dc2013-04-27 02:36:27199#include "ui/base/ui_base_switches_util.h"
[email protected]08397d52011-02-05 01:53:38200#include "ui/gfx/native_widget_types.h"
201#include "ui/gfx/point.h"
202#include "ui/gfx/rect.h"
[email protected]70221f02013-01-31 22:17:07203#include "ui/gfx/rect_conversions.h"
[email protected]f9526d12012-10-18 01:55:03204#include "ui/gfx/size_conversions.h"
[email protected]4344a3c2013-01-17 23:49:20205#include "ui/shell_dialogs/selected_file_info.h"
[email protected]c4a9e932011-03-05 04:05:55206#include "v8/include/v8.h"
[email protected]d0fcff72013-07-23 02:45:43207#include "webkit/child/weburlresponse_extradata_impl.h"
[email protected]3caf2cb62013-06-04 00:31:33208#include "webkit/common/dom_storage/dom_storage_types.h"
initial.commit09911bf2008-07-26 23:55:29209#include "webkit/glue/webkit_glue.h"
[email protected]d5b2fdf2013-06-05 09:36:55210#include "webkit/renderer/appcache/web_application_cache_host_impl.h"
[email protected]fab55e72013-05-31 07:06:18211#include "webkit/renderer/webpreferences_renderer.h"
initial.commit09911bf2008-07-26 23:55:29212
[email protected]25fb9b32012-04-27 03:21:55213#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25214#include <cpu-features.h>
215
[email protected]276e8a322013-01-24 01:50:11216#include "content/common/android/device_telephony_info.h"
[email protected]a45c46e2013-03-07 01:04:46217#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]20657a82012-08-21 20:23:03218#include "content/renderer/android/address_detector.h"
219#include "content/renderer/android/content_detector.h"
220#include "content/renderer/android/email_detector.h"
221#include "content/renderer/android/phone_number_detector.h"
[email protected]bc427442013-07-13 02:53:08222#include "content/renderer/media/android/renderer_media_player_manager.h"
[email protected]be580992013-06-22 14:32:44223#include "content/renderer/media/android/stream_texture_factory_android.h"
224#include "content/renderer/media/android/webmediaplayer_android.h"
[email protected]be580992013-06-22 14:32:44225#include "content/renderer/media/android/webmediaplayer_proxy_android.h"
[email protected]c277d3c2013-07-15 21:49:37226#include "skia/ext/platform_canvas.h"
[email protected]5c30b5e02013-05-30 03:46:08227#include "third_party/WebKit/public/platform/WebFloatPoint.h"
228#include "third_party/WebKit/public/platform/WebFloatRect.h"
[email protected]d0fcff72013-07-23 02:45:43229#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31230#include "ui/gfx/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40231
232#if defined(GOOGLE_TV)
233#include "content/renderer/media/rtc_video_decoder_bridge_tv.h"
234#include "content/renderer/media/rtc_video_decoder_factory_tv.h"
235#endif
236
[email protected]25fb9b32012-04-27 03:21:55237#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57238// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57239// * theming
[email protected]990e6222012-11-16 13:31:18240#include "ui/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03241#elif defined(USE_X11)
[email protected]990e6222012-11-16 13:31:18242#include "ui/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33243#elif defined(OS_MACOSX)
244#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57245#endif
246
[email protected]9892b472010-09-16 00:23:42247using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08248using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21249using WebKit::WebApplicationCacheHost;
250using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26251using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41252using WebKit::WebColor;
253using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59254using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44255using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51256using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55257using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28258using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00259using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49260using WebKit::WebDOMEvent;
261using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58262using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25263using WebKit::WebDragOperation;
264using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51265using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51266using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08267using WebKit::WebExternalPopupMenu;
268using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47269using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22270using WebKit::WebFileSystem;
271using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49272using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59273using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48274using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45275using WebKit::WebFrame;
[email protected]3306f262012-09-21 19:20:42276using WebKit::WebGestureEvent;
[email protected]ca948a22009-06-25 19:36:17277using WebKit::WebHistoryItem;
[email protected]132e281a2012-07-31 18:32:44278using WebKit::WebHTTPBody;
[email protected]42054a252011-05-17 18:02:13279using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41280using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50281using WebKit::WebInputElement;
[email protected]3306f262012-09-21 19:20:42282using WebKit::WebInputEvent;
[email protected]3d9689372009-09-10 04:29:17283using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28284using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17285using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26286using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28287using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28288using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51289using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19290using WebKit::WebPageSerializer;
291using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48292using WebKit::WebPeerConnection00Handler;
293using WebKit::WebPeerConnection00HandlerClient;
294using WebKit::WebPeerConnectionHandler;
295using WebKit::WebPeerConnectionHandlerClient;
[email protected]81375e872012-01-11 21:40:36296using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40297using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49298using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09299using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52300using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59301using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51302using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52303using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15304using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40305using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35306using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29307using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17308using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49309using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59310using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42311using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02312using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34313using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34314using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40315using WebKit::WebStorageQuotaCallbacks;
316using WebKit::WebStorageQuotaError;
317using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28318using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51319using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52320using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24321using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28322using WebKit::WebURL;
323using WebKit::WebURLError;
324using WebKit::WebURLRequest;
325using WebKit::WebURLResponse;
[email protected]af15bf22013-03-08 01:18:17326using WebKit::WebUserGestureIndicator;
[email protected]4873c7d2009-07-16 06:36:28327using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03328using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28329using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26330using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26331using appcache::WebApplicationCacheHostImpl;
332using base::Time;
333using base::TimeDelta;
[email protected]e9ff79c2012-10-19 21:31:26334
[email protected]b9fd01ba2012-02-28 01:50:40335using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33336
[email protected]20657a82012-08-21 20:23:03337#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03338using WebKit::WebContentDetectionResult;
[email protected]59363fc92012-09-05 03:46:31339using WebKit::WebFloatPoint;
340using WebKit::WebFloatRect;
[email protected]20657a82012-08-21 20:23:03341using WebKit::WebHitTestResult;
342#endif
343
[email protected]e9ff79c2012-10-19 21:31:26344namespace content {
345
initial.commit09911bf2008-07-26 23:55:29346//-----------------------------------------------------------------------------
347
[email protected]310ebd6302011-10-10 19:06:28348typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49349static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]058561b2012-12-03 06:48:22350typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap;
351static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map =
352 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02353
[email protected]882daa92009-11-05 16:31:31354// Time, in seconds, we delay before sending content state changes (such as form
355// state and scroll position) to the browser. We delay sending changes to avoid
356// spamming the browser.
357// To avoid having tab/session restore require sending a message to get the
358// current content state during tab closing we use a shorter timeout for the
359// foreground renderer. This means there is a small window of time from which
360// content state is modified and not sent to session restore, but this is
361// better than having to wake up all renderers during shutdown.
362static const int kDelaySecondsForContentStateSyncHidden = 5;
363static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29364
[email protected]e99ef6f2011-10-16 01:13:00365static const size_t kExtraCharsBeforeAndAfterSelection = 100;
366
[email protected]0aa55312008-10-17 21:53:08367// The maximum number of popups that can be spawned from one page.
368static const int kMaximumNumberOfUnacknowledgedPopups = 25;
369
[email protected]c514d6372011-08-16 22:54:44370static const float kScalingIncrement = 0.1f;
371
[email protected]47578fa02011-11-02 19:34:41372static const float kScalingIncrementForGesture = 0.01f;
373
[email protected]20657a82012-08-21 20:23:03374#if defined(OS_ANDROID)
375// Delay between tapping in content and launching the associated android intent.
376// Used to allow users see what has been recognized as content.
377static const size_t kContentIntentDelayMilliseconds = 700;
378#endif
379
[email protected]8d41d7612012-11-14 20:32:19380static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
381 NULL;
382
[email protected]726985e22009-06-18 21:09:28383static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
[email protected]bf692cd2012-11-14 19:10:02384 // Replace any occurrences of swappedout:// with about:blank.
[email protected]081dc522013-05-15 04:59:20385 const WebURL& blank_url = GURL(kAboutBlankURL);
[email protected]726985e22009-06-18 21:09:28386 WebVector<WebURL> urls;
387 ds->redirectChain(urls);
388 result->reserve(urls.size());
[email protected]bf692cd2012-11-14 19:10:02389 for (size_t i = 0; i < urls.size(); ++i) {
390 if (urls[i] != GURL(kSwappedOutURL))
391 result->push_back(urls[i]);
392 else
393 result->push_back(blank_url);
394 }
[email protected]726985e22009-06-18 21:09:28395}
396
[email protected]e20b88d2013-04-09 15:28:37397// If |data_source| is non-null and has an InternalDocumentStateData associated
398// with it, the AltErrorPageResourceFetcher is reset.
[email protected]6a8f5112011-05-13 16:38:44399static void StopAltErrorPageFetcher(WebDataSource* data_source) {
400 if (data_source) {
[email protected]e20b88d2013-04-09 15:28:37401 InternalDocumentStateData* internal_data =
402 InternalDocumentStateData::FromDataSource(data_source);
403 if (internal_data)
404 internal_data->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44405 }
406}
407
[email protected]007733c2011-11-17 00:34:07408static bool IsReload(const ViewMsg_Navigate_Params& params) {
409 return
410 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
[email protected]7c16976c2012-08-04 02:38:23411 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
412 params.navigation_type ==
413 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07414}
415
[email protected]e507045d2013-07-24 15:23:44416// static
417WebReferrerPolicy RenderViewImpl::GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59418 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15419 const WebURLRequest& request) {
420 return request.extraData() ?
421 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59422 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15423}
424
[email protected]e507045d2013-07-24 15:23:44425// static
426Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56427 WebFrame* frame,
428 const WebURLRequest& request) {
429 return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
430 GetReferrerPolicyFromRequest(frame, request));
431}
432
[email protected]e507045d2013-07-24 15:23:44433// static
434WebURLResponseExtraDataImpl* RenderViewImpl::GetExtraDataFromResponse(
[email protected]b9fd01ba2012-02-28 01:50:40435 const WebURLResponse& response) {
436 return static_cast<WebURLResponseExtraDataImpl*>(
437 response.extraData());
438}
439
[email protected]2149cc622012-02-14 01:12:12440NOINLINE static void CrashIntentionally() {
441 // NOTE(shess): Crash directly rather than using NOTREACHED() so
442 // that the signature is easier to triage in crash reports.
443 volatile int* zero = NULL;
444 *zero = 0;
445}
446
[email protected]2132d6b2013-06-05 00:15:43447#if defined(ADDRESS_SANITIZER)
448NOINLINE static void MaybeTriggerAsanError(const GURL& url) {
449 // NOTE(rogerm): We intentionally perform an invalid heap access here in
450 // order to trigger an Address Sanitizer (ASAN) error report.
451 static const char kCrashDomain[] = "crash";
452 static const char kHeapOverflow[] = "/heap-overflow";
453 static const char kHeapUnderflow[] = "/heap-underflow";
454 static const char kUseAfterFree[] = "/use-after-free";
455 static const int kArraySize = 5;
456
457 if (!url.DomainIs(kCrashDomain, sizeof(kCrashDomain) - 1))
458 return;
459
460 if (!url.has_path())
461 return;
462
463 scoped_ptr<int[]> array(new int[kArraySize]);
464 std::string crash_type(url.path());
465 int dummy = 0;
466 if (crash_type == kHeapOverflow) {
467 dummy = array[kArraySize];
468 } else if (crash_type == kHeapUnderflow ) {
469 dummy = array[-1];
470 } else if (crash_type == kUseAfterFree) {
471 int* dangling = array.get();
472 array.reset();
473 dummy = dangling[kArraySize / 2];
474 }
475
476 // Make sure the assignments to the dummy value aren't optimized away.
477 base::debug::Alias(&dummy);
478}
479#endif // ADDRESS_SANITIZER
480
[email protected]8bf1048012012-02-08 01:22:18481static void MaybeHandleDebugURL(const GURL& url) {
482 if (!url.SchemeIs(chrome::kChromeUIScheme))
483 return;
[email protected]f8a6d732013-03-02 22:46:03484 if (url == GURL(kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12485 CrashIntentionally();
[email protected]f8a6d732013-03-02 22:46:03486 } else if (url == GURL(kChromeUIKillURL)) {
[email protected]8bf1048012012-02-08 01:22:18487 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
[email protected]f8a6d732013-03-02 22:46:03488 } else if (url == GURL(kChromeUIHangURL)) {
[email protected]8bf1048012012-02-08 01:22:18489 for (;;) {
490 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
491 }
[email protected]50f86bc2012-11-01 19:59:13492 } else if (url == GURL(kChromeUIShorthangURL)) {
[email protected]8bf1048012012-02-08 01:22:18493 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
494 }
[email protected]2132d6b2013-06-05 00:15:43495
496#if defined(ADDRESS_SANITIZER)
497 MaybeTriggerAsanError(url);
498#endif // ADDRESS_SANITIZER
[email protected]8bf1048012012-02-08 01:22:18499}
500
[email protected]fd3238af2012-05-22 18:55:30501// Returns false unless this is a top-level navigation.
502static bool IsTopLevelNavigation(WebFrame* frame) {
503 return frame->parent() == NULL;
504}
505
506// Returns false unless this is a top-level navigation that crosses origins.
507static bool IsNonLocalTopLevelNavigation(const GURL& url,
508 WebFrame* frame,
[email protected]140a5882013-07-23 19:30:33509 WebNavigationType type,
510 bool is_form_post) {
[email protected]fd3238af2012-05-22 18:55:30511 if (!IsTopLevelNavigation(frame))
512 return false;
513
514 // Navigations initiated within Webkit are not sent out to the external host
515 // in the following cases.
516 // 1. The url scheme is not http/https
517 // 2. The origin of the url and the opener is the same in which case the
518 // opener relationship is maintained.
519 // 3. Reloads/form submits/back forward navigations
520 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
521 return false;
522
[email protected]fd3238af2012-05-22 18:55:30523 if (type != WebKit::WebNavigationTypeReload &&
[email protected]140a5882013-07-23 19:30:33524 type != WebKit::WebNavigationTypeBackForward && !is_form_post) {
[email protected]fd3238af2012-05-22 18:55:30525 // The opener relationship between the new window and the parent allows the
526 // new window to script the parent and vice versa. This is not allowed if
527 // the origins of the two domains are different. This can be treated as a
528 // top level navigation and routed back to the host.
529 WebKit::WebFrame* opener = frame->opener();
[email protected]140a5882013-07-23 19:30:33530 if (!opener)
[email protected]fd3238af2012-05-22 18:55:30531 return true;
[email protected]fd3238af2012-05-22 18:55:30532
533 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
534 return true;
535 }
536 return false;
537}
538
[email protected]38761452012-10-18 16:31:59539static void NotifyTimezoneChange(WebKit::WebFrame* frame) {
540 v8::HandleScope handle_scope;
541 v8::Context::Scope context_scope(frame->mainWorldScriptContext());
542 v8::Date::DateTimeConfigurationChangeNotification();
543 WebKit::WebFrame* child = frame->firstChild();
544 for (; child; child = child->nextSibling())
545 NotifyTimezoneChange(child);
546}
547
[email protected]48861e22013-01-09 00:27:32548static WindowOpenDisposition NavigationPolicyToDisposition(
549 WebNavigationPolicy policy) {
550 switch (policy) {
551 case WebKit::WebNavigationPolicyIgnore:
552 return IGNORE_ACTION;
553 case WebKit::WebNavigationPolicyDownload:
554 return SAVE_TO_DISK;
555 case WebKit::WebNavigationPolicyCurrentTab:
556 return CURRENT_TAB;
557 case WebKit::WebNavigationPolicyNewBackgroundTab:
558 return NEW_BACKGROUND_TAB;
559 case WebKit::WebNavigationPolicyNewForegroundTab:
560 return NEW_FOREGROUND_TAB;
561 case WebKit::WebNavigationPolicyNewWindow:
562 return NEW_WINDOW;
563 case WebKit::WebNavigationPolicyNewPopup:
564 return NEW_POPUP;
565 default:
566 NOTREACHED() << "Unexpected WebNavigationPolicy";
567 return IGNORE_ACTION;
568 }
569}
570
[email protected]d8221b22013-05-23 05:35:43571// Returns true if the device scale is high enough that losing subpixel
572// antialiasing won't have a noticeable effect on text quality.
573static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
574#if defined(OS_ANDROID)
575 // On Android, we never have subpixel antialiasing.
576 return true;
577#else
578 return device_scale_factor > 1.5f;
579#endif
580
581}
582
[email protected]fb854192013-02-06 01:30:04583static bool ShouldUseFixedPositionCompositing(float device_scale_factor) {
584 // Compositing for fixed-position elements is dependent on
[email protected]d8221b22013-05-23 05:35:43585 // device_scale_factor if no flag is set. http://crbug.com/172738
[email protected]fb854192013-02-06 01:30:04586 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
587
588 if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition))
589 return false;
590
591 if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition))
592 return true;
593
[email protected]d8221b22013-05-23 05:35:43594 return DeviceScaleEnsuresTextQuality(device_scale_factor);
595}
596
[email protected]c162ced82013-06-29 01:24:53597static bool ShouldUseAcceleratedCompositingForOverflowScroll(
598 float device_scale_factor) {
599 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
600
601 if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll))
602 return true;
603
604 return DeviceScaleEnsuresTextQuality(device_scale_factor);
605}
606
[email protected]d8221b22013-05-23 05:35:43607static bool ShouldUseTransitionCompositing(float device_scale_factor) {
608 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
609
610 if (command_line.HasSwitch(switches::kDisableCompositingForTransition))
611 return false;
612
613 if (command_line.HasSwitch(switches::kEnableCompositingForTransition))
[email protected]fb854192013-02-06 01:30:04614 return true;
615
[email protected]9a7f6e12013-06-11 07:05:13616 // TODO(ajuma): Re-enable this by default for high-DPI once the problem
617 // of excessive layer promotion caused by overlap has been addressed.
618 // http://crbug.com/178119.
619 return false;
[email protected]fb854192013-02-06 01:30:04620}
621
[email protected]06fc4d3b2013-07-08 21:07:24622static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) {
623 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
624
625 if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground))
626 return false;
627
628 if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground))
629 return true;
630
631 return DeviceScaleEnsuresTextQuality(device_scale_factor);
632}
633
[email protected]41225fe2013-03-29 05:32:02634static FaviconURL::IconType ToFaviconType(WebKit::WebIconURL::Type type) {
635 switch (type) {
636 case WebKit::WebIconURL::TypeFavicon:
637 return FaviconURL::FAVICON;
638 case WebKit::WebIconURL::TypeTouch:
639 return FaviconURL::TOUCH_ICON;
640 case WebKit::WebIconURL::TypeTouchPrecomposed:
641 return FaviconURL::TOUCH_PRECOMPOSED_ICON;
642 case WebKit::WebIconURL::TypeInvalid:
643 return FaviconURL::INVALID_ICON;
644 }
645 return FaviconURL::INVALID_ICON;
646}
647
initial.commit09911bf2008-07-26 23:55:29648///////////////////////////////////////////////////////////////////////////////
649
[email protected]310ebd6302011-10-10 19:06:28650struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26651 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47652 : params(p),
653 completion(c) {
654 }
[email protected]e9ff79c2012-10-19 21:31:26655 FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47656 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
657};
658
[email protected]217690d2012-01-27 07:33:11659namespace {
660
661class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
662 public:
[email protected]82114f52012-03-20 22:53:41663 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11664 : webwidget_(webwidget) {}
665
666 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
667 if (succeeded)
668 webwidget_->didAcquirePointerLock();
669 else
670 webwidget_->didNotAcquirePointerLock();
671 }
672
673 virtual void OnMouseLockLost() OVERRIDE {
674 webwidget_->didLosePointerLock();
675 }
676
677 virtual bool HandleMouseLockedInputEvent(
678 const WebKit::WebMouseEvent &event) OVERRIDE {
679 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
680 return false;
681 }
682
683 private:
684 WebKit::WebWidget* webwidget_;
685};
686
[email protected]86cd9472012-02-03 19:51:05687int64 ExtractPostId(const WebHistoryItem& item) {
688 if (item.isNull())
689 return -1;
690
691 if (item.httpBody().isNull())
692 return -1;
693
694 return item.httpBody().identifier();
695}
696
[email protected]41225fe2013-03-29 05:32:02697bool TouchEnabled() {
698// Based on the definition of chrome::kEnableTouchIcon.
699#if defined(OS_ANDROID)
700 return true;
701#else
702 return false;
703#endif
704}
705
[email protected]dc293a72013-07-01 11:11:22706WebDragData DropDataToWebDragData(const DropData& drop_data) {
[email protected]c10680312013-05-31 15:22:05707 std::vector<WebDragData::Item> item_list;
708
709 // These fields are currently unused when dragging into WebKit.
710 DCHECK(drop_data.download_metadata.empty());
711 DCHECK(drop_data.file_contents.empty());
712 DCHECK(drop_data.file_description_filename.empty());
713
714 if (!drop_data.text.is_null()) {
715 WebDragData::Item item;
716 item.storageType = WebDragData::Item::StorageTypeString;
717 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
718 item.stringData = drop_data.text.string();
719 item_list.push_back(item);
720 }
721
722 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
723 // meaningful to write an empty URL to the clipboard?
724 if (!drop_data.url.is_empty()) {
725 WebDragData::Item item;
726 item.storageType = WebDragData::Item::StorageTypeString;
727 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
728 item.stringData = WebString::fromUTF8(drop_data.url.spec());
729 item.title = drop_data.url_title;
730 item_list.push_back(item);
731 }
732
733 if (!drop_data.html.is_null()) {
734 WebDragData::Item item;
735 item.storageType = WebDragData::Item::StorageTypeString;
736 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
737 item.stringData = drop_data.html.string();
738 item.baseURL = drop_data.html_base_url;
739 item_list.push_back(item);
740 }
741
[email protected]dc293a72013-07-01 11:11:22742 for (std::vector<DropData::FileInfo>::const_iterator it =
[email protected]c10680312013-05-31 15:22:05743 drop_data.filenames.begin();
744 it != drop_data.filenames.end();
745 ++it) {
746 WebDragData::Item item;
747 item.storageType = WebDragData::Item::StorageTypeFilename;
748 item.filenameData = it->path;
749 item.displayNameData = it->display_name;
750 item_list.push_back(item);
751 }
752
753 for (std::map<base::string16, base::string16>::const_iterator it =
754 drop_data.custom_data.begin();
755 it != drop_data.custom_data.end();
756 ++it) {
757 WebDragData::Item item;
758 item.storageType = WebDragData::Item::StorageTypeString;
759 item.stringType = it->first;
760 item.stringData = it->second;
761 item_list.push_back(item);
762 }
763
764 WebDragData result;
765 result.initialize();
766 result.setItems(item_list);
767 result.setFilesystemId(drop_data.filesystem_id);
768 return result;
769}
770
[email protected]217690d2012-01-27 07:33:11771} // namespace
772
[email protected]8d41d7612012-11-14 20:32:19773RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
774 : RenderWidget(WebKit::WebPopupTypeNone,
775 params->screen_info,
776 params->swapped_out),
777 webkit_preferences_(params->webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02778 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09779 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02780 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24781 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21782 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02783 opened_by_user_gesture_(true),
784 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24785 page_id_(-1),
786 last_page_id_sent_to_browser_(-1),
[email protected]8d41d7612012-11-14 20:32:19787 next_page_id_(params->next_page_id),
[email protected]3cc72b12010-03-18 23:03:00788 history_list_offset_(-1),
789 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02790 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55791 selection_text_offset_(0),
[email protected]e017c9c2013-02-20 13:44:52792 selection_range_(ui::Range::InvalidRange()),
[email protected]bbc8856d2013-06-14 10:37:04793#if defined(OS_ANDROID)
794 top_controls_constraints_(cc::BOTH),
795#endif
[email protected]dd6afca2011-08-13 03:44:31796 cached_is_main_frame_pinned_to_left_(false),
797 cached_is_main_frame_pinned_to_right_(false),
798 cached_has_main_frame_horizontal_scrollbar_(false),
799 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]69e797f2013-04-30 01:10:22800 cookie_jar_(this),
[email protected]8a67aa352013-02-20 02:58:29801 notification_provider_(NULL),
[email protected]676126f72011-01-15 00:03:51802 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02803 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34804 speech_recognition_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51805 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51806 media_stream_dispatcher_(NULL),
[email protected]fb325d122012-11-20 23:58:05807 browser_plugin_manager_(NULL),
[email protected]c3bdce152013-07-10 04:56:34808 media_stream_client_(NULL),
809 web_user_media_client_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41810 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43811 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32812 renderer_accessibility_(NULL),
[email protected]7e9c5bb02012-05-14 13:58:31813 java_bridge_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11814 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03815#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:47816 body_background_color_(SK_ColorWHITE),
[email protected]20657a82012-08-21 20:23:03817 expected_content_intent_id_(0),
[email protected]780fc8242012-09-19 20:28:52818 media_player_proxy_(NULL),
[email protected]a7564272013-04-19 14:24:46819#endif
820#if defined(OS_WIN)
821 focused_plugin_id_(-1),
822#endif
[email protected]8a67aa352013-02-20 02:58:29823 enumeration_completion_id_(0),
[email protected]a7564272013-04-19 14:24:46824#if defined(OS_ANDROID)
[email protected]69e797f2013-04-30 01:10:22825 load_progress_tracker_(new LoadProgressTracker(this)),
[email protected]20657a82012-08-21 20:23:03826#endif
[email protected]8d41d7612012-11-14 20:32:19827 session_storage_namespace_id_(params->session_storage_namespace_id),
[email protected]8a67aa352013-02-20 02:58:29828 decrement_shared_popup_at_destruction_(false),
[email protected]ef5e98e2011-12-06 09:49:18829 handling_select_range_(false),
[email protected]c9bc8f12012-12-15 22:20:09830 next_snapshot_id_(0),
[email protected]f56c7872013-06-18 12:31:57831 allow_partial_swap_(params->allow_partial_swap),
[email protected]a14ddcd2013-06-21 22:53:03832 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) {
[email protected]075366912013-02-18 07:13:24833}
834
835void RenderViewImpl::Initialize(RenderViewImplParams* params) {
[email protected]2f61bdd2013-07-02 18:38:47836 RenderFrameImpl* main_frame = RenderFrameImpl::Create(
837 this, params->main_frame_routing_id);
838 main_render_frame_.reset(main_frame);
[email protected]227692c52013-05-31 22:43:04839
[email protected]6d17f6392012-12-05 05:24:54840#if defined(ENABLE_PLUGINS)
841 pepper_helper_.reset(new PepperPluginDelegateImpl(this));
842#else
843 pepper_helper_.reset(new RenderViewPepperHelper());
844#endif
[email protected]8d41d7612012-11-14 20:32:19845 routing_id_ = params->routing_id;
846 surface_id_ = params->surface_id;
847 if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created)
848 opener_id_ = params->opener_id;
[email protected]676126f72011-01-15 00:03:51849
[email protected]74ce1ad2011-12-16 21:51:46850 // Ensure we start with a valid next_page_id_ from the browser.
851 DCHECK_GE(next_page_id_, 0);
852
[email protected]21b3a6ae2011-11-30 00:45:29853#if defined(ENABLE_NOTIFICATIONS)
854 notification_provider_ = new NotificationProvider(this);
855#else
856 notification_provider_ = NULL;
857#endif
858
[email protected]11fee2332011-03-29 20:36:35859 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11860 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35861
[email protected]20657a82012-08-21 20:23:03862 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
863
[email protected]27c521a2013-05-29 20:44:32864 if (command_line.HasSwitch(switches::kStatsCollectionController))
865 stats_collection_observer_.reset(new StatsCollectionObserver(this));
866
[email protected]20657a82012-08-21 20:23:03867#if defined(OS_ANDROID)
[email protected]276e8a322013-01-24 01:50:11868 content::DeviceTelephonyInfo device_info;
[email protected]20657a82012-08-21 20:23:03869
870 const std::string region_code =
871 command_line.HasSwitch(switches::kNetworkCountryIso)
872 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
[email protected]276e8a322013-01-24 01:50:11873 : device_info.GetNetworkCountryIso();
[email protected]20657a82012-08-21 20:23:03874 content_detectors_.push_back(linked_ptr<ContentDetector>(
875 new AddressDetector()));
876 content_detectors_.push_back(linked_ptr<ContentDetector>(
877 new PhoneNumberDetector(region_code)));
878 content_detectors_.push_back(linked_ptr<ContentDetector>(
879 new EmailDetector()));
880#endif
881
[email protected]8d41d7612012-11-14 20:32:19882 if (params->counter) {
883 shared_popup_counter_ = params->counter;
[email protected]14392a52012-05-02 20:28:44884 // Only count this if it isn't swapped out upon creation.
[email protected]8d41d7612012-11-14 20:32:19885 if (!params->swapped_out)
[email protected]14392a52012-05-02 20:28:44886 shared_popup_counter_->data++;
[email protected]676126f72011-01-15 00:03:51887 decrement_shared_popup_at_destruction_ = true;
888 } else {
889 shared_popup_counter_ = new SharedRenderViewCounter(0);
890 decrement_shared_popup_at_destruction_ = false;
891 }
892
[email protected]380244092011-10-07 17:26:27893 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51894 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47895 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51896 AddRef();
897
898 // If this is a popup, we must wait for the CreatingNew_ACK message before
899 // completing initialization. Otherwise, we can finish it now.
[email protected]6cd7c6b2012-10-25 03:26:23900 if (opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51901 did_show_ = true;
[email protected]fc4404d2012-11-07 19:53:30902 CompleteInit();
[email protected]676126f72011-01-15 00:03:51903 }
904
[email protected]34c61bd52011-05-02 19:38:33905 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]058561b2012-12-03 06:48:22906 g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this));
[email protected]60051ec2012-06-08 22:40:57907 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]fb854192013-02-06 01:30:04908 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
909 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]c162ced82013-06-29 01:24:53910 webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
911 ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:43912 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
913 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]06fc4d3b2013-07-08 21:07:24914 webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled(
915 ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:04916
[email protected]3184f90b2013-05-01 18:17:53917 webkit_glue::ApplyWebPreferences(webkit_preferences_, webview());
[email protected]2f61bdd2013-07-02 18:38:47918 webview()->initializeMainFrame(main_render_frame_.get());
[email protected]edbea622012-11-28 20:39:38919
[email protected]1400e6dc2013-04-27 02:36:27920 if (switches::IsTouchDragDropEnabled())
[email protected]edbea622012-11-28 20:39:38921 webview()->settings()->setTouchDragDropEnabled(true);
922
[email protected]1400e6dc2013-04-27 02:36:27923 if (switches::IsTouchEditingEnabled())
[email protected]47822262013-04-23 17:22:36924 webview()->settings()->setTouchEditingEnabled(true);
925
[email protected]8d41d7612012-11-14 20:32:19926 if (!params->frame_name.empty())
927 webview()->mainFrame()->setName(params->frame_name);
[email protected]34c61bd52011-05-02 19:38:33928
[email protected]8d41d7612012-11-14 20:32:19929 OnSetRendererPrefs(params->renderer_prefs);
[email protected]34c61bd52011-05-02 19:38:33930
[email protected]4fb0f202012-05-30 22:44:53931#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02932 if (!media_stream_dispatcher_)
933 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32934#endif
[email protected]735873d2012-01-25 23:31:02935
[email protected]8f6a3b852011-07-19 16:48:56936 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32937#if defined(OS_MACOSX)
938 new TextInputClientObserver(this);
939#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56940
[email protected]2d7b82c2012-06-01 05:57:50941#if defined(OS_ANDROID)
[email protected]bc427442013-07-13 02:53:08942 media_player_manager_.reset(new RendererMediaPlayerManager());
[email protected]2d7b82c2012-06-01 05:57:50943#endif
944
[email protected]217690d2012-01-27 07:33:11945 // The next group of objects all implement RenderViewObserver, so are deleted
946 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41947 devtools_agent_ = new DevToolsAgent(this);
[email protected]6e89eb72013-07-23 13:28:22948 if (RenderWidgetCompositor* rwc = compositor()) {
949 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
950 }
[email protected]89054502012-06-03 10:29:24951 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]41225fe2013-03-29 05:32:02952 new ImageLoadingHelper(this);
[email protected]063afcb2011-09-29 07:54:32953
[email protected]2a84f9d2012-06-05 21:50:43954 // Create renderer_accessibility_ if needed.
[email protected]8d41d7612012-11-14 20:32:19955 OnSetAccessibilityMode(params->accessibility_mode);
[email protected]2a84f9d2012-06-05 21:50:43956
[email protected]1784b2f2011-11-24 10:53:48957 new IdleUserDetector(this);
958
[email protected]766a7082012-02-03 23:39:15959 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:26960 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]27c521a2013-05-29 20:44:32961 if (command_line.HasSwitch(switches::kStatsCollectionController))
962 enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
[email protected]766a7082012-02-03 23:39:15963
[email protected]5b52cd2f712012-03-28 02:12:48964 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05965
[email protected]e9ff79c2012-10-19 21:31:26966 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44967
968 // If we have an opener_id but we weren't created by a renderer, then
969 // it's the browser asking us to set our opener to another RenderView.
[email protected]8d41d7612012-11-14 20:32:19970 if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) {
971 RenderViewImpl* opener_view = FromRoutingID(params->opener_id);
[email protected]f546640b2012-05-15 00:03:49972 if (opener_view)
973 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44974 }
975
976 // If we are initially swapped out, navigate to kSwappedOutURL.
977 // This ensures we are in a unique origin that others cannot script.
978 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:37979 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29980}
981
[email protected]310ebd6302011-10-10 19:06:28982RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03983 history_page_ids_.clear();
984
[email protected]0aa55312008-10-17 21:53:08985 if (decrement_shared_popup_at_destruction_)
986 shared_popup_counter_->data--;
987
[email protected]91a2aea2013-07-08 23:14:39988 base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_);
989
[email protected]a1128322009-10-06 18:38:46990 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47991 while (!file_chooser_completions_.empty()) {
992 if (file_chooser_completions_.front()->completion) {
993 file_chooser_completions_.front()->completion->didChooseFile(
994 WebVector<WebString>());
995 }
996 file_chooser_completions_.pop_front();
997 }
[email protected]a1128322009-10-06 18:38:46998
[email protected]8ed1d3f2013-02-20 11:45:55999#if defined(OS_ANDROID)
1000 // The date/time picker client is both a scoped_ptr member of this class and
1001 // a RenderViewObserver. Reset it to prevent double deletion.
1002 date_time_picker_client_.reset();
1003#endif
1004
[email protected]60c42a8c72009-10-09 04:08:591005#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:221006 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:491007 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:591008 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
1009 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:221010 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
1011 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
1012 it != routing_id_views->end(); ++it)
1013 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:591014#endif
[email protected]676126f72011-01-15 00:03:511015
[email protected]310ebd6302011-10-10 19:06:281016 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:511017 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:591018}
1019
1020/*static*/
[email protected]310ebd6302011-10-10 19:06:281021RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:311022 ViewMap* views = g_view_map.Pointer();
1023 ViewMap::iterator it = views->find(webview);
1024 return it == views->end() ? NULL : it->second;
1025}
1026
1027/*static*/
[email protected]e9ff79c2012-10-19 21:31:261028RenderView* RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:281029 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:311030}
1031
1032/*static*/
[email protected]640e303c2012-12-05 01:36:071033RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) {
1034 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
1035 RoutingIDViewMap::iterator it = views->find(routing_id);
1036 return it == views->end() ? NULL : it->second;
1037}
1038
1039/*static*/
1040RenderView* RenderView::FromRoutingID(int routing_id) {
1041 return RenderViewImpl::FromRoutingID(routing_id);
1042}
1043
1044/*static*/
[email protected]e9ff79c2012-10-19 21:31:261045void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:491046 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:591047 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
1048 if (!visitor->Visit(it->second))
1049 return;
1050 }
1051}
1052
1053/*static*/
[email protected]310ebd6302011-10-10 19:06:281054RenderViewImpl* RenderViewImpl::Create(
[email protected]0aa55312008-10-17 21:53:081055 int32 opener_id,
[email protected]e9ff79c2012-10-19 21:31:261056 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:081057 const WebPreferences& webkit_prefs,
1058 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:341059 int32 routing_id,
[email protected]227692c52013-05-31 22:43:041060 int32 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561061 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:261062 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461063 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:441064 bool is_renderer_created,
1065 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:411066 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:041067 const WebKit::WebScreenInfo& screen_info,
[email protected]34bb3ac2013-03-08 02:41:281068 AccessibilityMode accessibility_mode,
1069 bool allow_partial_swap) {
initial.commit09911bf2008-07-26 23:55:291070 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]8d41d7612012-11-14 20:32:191071 RenderViewImplParams params(
[email protected]676126f72011-01-15 00:03:511072 opener_id,
1073 renderer_prefs,
1074 webkit_prefs,
1075 counter,
1076 routing_id,
[email protected]227692c52013-05-31 22:43:041077 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561078 surface_id,
[email protected]676126f72011-01-15 00:03:511079 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461080 frame_name,
[email protected]14392a52012-05-02 20:28:441081 is_renderer_created,
1082 swapped_out,
[email protected]6fd35b72012-03-01 19:46:411083 next_page_id,
[email protected]842f10652012-06-06 01:54:041084 screen_info,
[email protected]34bb3ac2013-03-08 02:41:281085 accessibility_mode,
1086 allow_partial_swap);
[email protected]075366912013-02-18 07:13:241087 RenderViewImpl* render_view = NULL;
[email protected]8d41d7612012-11-14 20:32:191088 if (g_create_render_view_impl)
[email protected]075366912013-02-18 07:13:241089 render_view = g_create_render_view_impl(&params);
1090 else
1091 render_view = new RenderViewImpl(&params);
1092 render_view->Initialize(&params);
1093 return render_view;
[email protected]8d41d7612012-11-14 20:32:191094}
1095
1096// static
1097void RenderViewImpl::InstallCreateHook(
1098 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) {
1099 CHECK(!g_create_render_view_impl);
1100 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291101}
1102
[email protected]310ebd6302011-10-10 19:06:281103void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511104 observers_.AddObserver(observer);
1105}
1106
[email protected]310ebd6302011-10-10 19:06:281107void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1108 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511109 observers_.RemoveObserver(observer);
1110}
1111
[email protected]310ebd6302011-10-10 19:06:281112WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:261113 return static_cast<WebKit::WebView*>(webwidget());
1114}
1115
[email protected]c42de732013-02-16 06:26:311116void RenderViewImpl::PluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:421117 base::ProcessId plugin_pid) {
1118 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path, plugin_pid));
initial.commit09911bf2008-07-26 23:55:291119}
1120
[email protected]310ebd6302011-10-10 19:06:281121void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261122 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:301123 // If the renderer is visible, set initial visibility and focus state.
1124 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:341125#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:301126 delegate->SetContainerVisibility(true);
1127 if (webview() && webview()->isActive())
1128 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:341129#endif
[email protected]49232292010-09-03 19:07:301130 }
[email protected]784ea1ab2010-09-18 00:02:341131 // Plugins start assuming the content has focus (so that they work in
1132 // environments where RenderView isn't hosting them), so we always have to
1133 // set the initial state. See webplugin_delegate_impl.h for details.
1134 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:261135}
1136
[email protected]310ebd6302011-10-10 19:06:281137void RenderViewImpl::UnregisterPluginDelegate(
1138 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261139 plugin_delegates_.erase(delegate);
1140}
[email protected]d8fd6fa2010-02-01 15:54:261141
[email protected]310ebd6302011-10-10 19:06:281142bool RenderViewImpl::GetPluginInfo(const GURL& url,
1143 const GURL& page_url,
1144 const std::string& mime_type,
[email protected]d7bd3e52013-07-21 04:29:201145 WebPluginInfo* plugin_info,
[email protected]310ebd6302011-10-10 19:06:281146 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:081147 bool found = false;
1148 Send(new ViewHostMsg_GetPluginInfo(
1149 routing_id_, url, page_url, mime_type, &found, plugin_info,
1150 actual_mime_type));
1151 return found;
1152}
1153
[email protected]7a1ec28a2012-03-28 21:10:241154void RenderViewImpl::TransferActiveWheelFlingAnimation(
1155 const WebKit::WebActiveWheelFlingParameters& params) {
1156 if (webview())
1157 webview()->transferActiveWheelFlingAnimation(params);
1158}
1159
[email protected]8fe8f742012-06-14 00:36:081160bool RenderViewImpl::HasIMETextFocus() {
1161 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
1162}
1163
[email protected]310ebd6302011-10-10 19:06:281164bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:271165 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:271166 if (main_frame)
[email protected]e9ff79c2012-10-19 21:31:261167 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:261168
[email protected]676126f72011-01-15 00:03:511169 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
1170 RenderViewObserver* observer;
1171 while ((observer = it.GetNext()) != NULL)
1172 if (observer->OnMessageReceived(message))
1173 return true;
[email protected]b2abac72009-02-26 12:39:281174
[email protected]a95986a82010-12-24 06:19:281175 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:401176 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:281177 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
[email protected]c084330e02013-04-27 01:08:151178 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy)
1179 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut)
1180 IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete)
1181 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
1182 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
1183 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste)
1184 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
1185 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo)
1186 IPC_MESSAGE_HANDLER(InputMsg_Replace, OnReplace)
1187 IPC_MESSAGE_HANDLER(InputMsg_ReplaceMisspelling, OnReplaceMisspelling)
1188 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
1189 OnScrollFocusedEditableNodeIntoRect)
1190 IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll)
1191 IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange)
1192 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
1193 OnSetEditCommandsForNextKeyEvent)
1194 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo)
1195 IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect)
initial.commit09911bf2008-07-26 23:55:291196 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
1197 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:561198 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
[email protected]25bcc8f2013-01-09 02:49:251199 IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName)
[email protected]45a599062012-09-07 20:09:061200 IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets,
1201 OnSetEditableSelectionOffsets)
1202 IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText,
1203 OnSetCompositionFromExistingText)
1204 IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete,
1205 OnExtendSelectionAndDelete)
initial.commit09911bf2008-07-26 23:55:291206 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
1207 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491208 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:171209 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:171210 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:411211 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:541212 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1213 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291214 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181215 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1216 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:291217 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:491218 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:481219 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:551220 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1221 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1222 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1223 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
1224 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
1225 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1226 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:451227 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291228 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291229 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1230 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]38761452012-10-18 16:31:591231 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone)
initial.commit09911bf2008-07-26 23:55:291232 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:511233 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1234 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291235 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:041236 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:151237 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:291238 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1239 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:081240 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1241 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:001242 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:161243 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141244 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251245 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1246 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471247 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341248 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101249 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1250 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511251 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561252 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:171253 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
1254 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:361255 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341256 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]a0c7153e2009-12-09 14:36:331257 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1258 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:241259 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:421260 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
1261 OnPpapiBrokerChannelCreated)
[email protected]d8415ad92012-08-23 14:40:501262 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
1263 OnPpapiBrokerPermissionResult)
[email protected]18d5be92011-07-25 18:00:191264 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1265 OnGetAllSavableResourceLinksForCurrentPage)
1266 IPC_MESSAGE_HANDLER(
1267 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1268 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]521b2482011-01-15 00:10:101269 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]47822262013-04-23 17:22:361270 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]f0557932011-01-25 20:20:511271 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:191272 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
1273 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:181274 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]c7654a232013-06-12 21:04:441275#if defined(OS_ANDROID)
[email protected]7f3c7af2011-10-20 22:52:511276 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]da816272013-05-15 21:31:171277#endif
[email protected]2a84f9d2012-06-05 21:50:431278 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]7cc78902012-12-06 02:32:261279 IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener)
[email protected]55750b32012-09-21 14:05:031280#if defined(OS_ANDROID)
[email protected]c084330e02013-04-27 01:08:151281 IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult,
[email protected]55750b32012-09-21 14:05:031282 OnActivateNearestFindResult)
1283 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
1284 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
[email protected]9b7d11e2012-10-08 19:24:141285 IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView,
1286 OnUndoScrollFocusedEditableNodeIntoRect)
[email protected]452b4a92013-03-28 21:24:381287 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState,
1288 OnUpdateTopControlsState)
[email protected]55750b32012-09-21 14:05:031289#elif defined(OS_MACOSX)
[email protected]c084330e02013-04-27 01:08:151290 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]55750b32012-09-21 14:05:031291 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1292 OnPluginImeCompositionCompleted)
1293 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1294 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1295 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1296 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1297#endif
[email protected]f9526d12012-10-18 01:55:031298 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB,
1299 OnReleaseDisambiguationPopupDIB)
[email protected]c9bc8f12012-12-15 22:20:091300 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted,
1301 OnWindowSnapshotCompleted)
[email protected]9e1ad4b2011-08-14 16:49:191302
initial.commit09911bf2008-07-26 23:55:291303 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281304 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291305 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401306
1307 if (!msg_is_ok) {
1308 // The message had a handler, but its deserialization failed.
1309 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281310 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401311 }
1312
[email protected]a95986a82010-12-24 06:19:281313 return handled;
initial.commit09911bf2008-07-26 23:55:291314}
1315
[email protected]310ebd6302011-10-10 19:06:281316void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:181317 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291318 if (!webview())
1319 return;
1320
[email protected]440a0e52011-09-13 17:38:581321 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1322
[email protected]007733c2011-11-17 00:34:071323 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031324
1325 // If this is a stale back/forward (due to a recent navigation the browser
1326 // didn't know about), ignore it.
1327 if (IsBackForwardToStaleEntry(params, is_reload))
1328 return;
1329
[email protected]992db4c2011-05-12 15:37:151330 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281331 if (is_swapped_out_) {
1332 // We marked the view as hidden when swapping the view out, so be sure to
1333 // reset the visibility state before navigating to the new URL.
1334 webview()->setVisibilityState(visibilityState(), false);
[email protected]890b06ca2012-12-13 21:07:361335
1336 // If this is an attempt to reload while we are swapped out, we should not
1337 // reload swappedout://, but the previous page, which is stored in
1338 // params.state. Setting is_reload to false will treat this like a back
1339 // navigation to accomplish that.
1340 is_reload = false;
1341
[email protected]0b059022013-07-03 22:50:091342 // We refresh timezone when a view is swapped in since timezone
1343 // can get out of sync when the system timezone is updated while
1344 // the view is swapped out.
1345 NotifyTimezoneChange(webview()->mainFrame());
1346
[email protected]992db4c2011-05-12 15:37:151347 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281348 }
[email protected]992db4c2011-05-12 15:37:151349
[email protected]60d6cca2013-04-30 08:47:131350 if (params.should_clear_history_list) {
1351 CHECK_EQ(params.pending_history_list_offset, -1);
1352 CHECK_EQ(params.current_history_list_offset, -1);
1353 CHECK_EQ(params.current_history_list_length, 0);
1354 }
[email protected]3cc72b12010-03-18 23:03:001355 history_list_offset_ = params.current_history_list_offset;
1356 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031357 if (history_list_length_ >= 0)
1358 history_page_ids_.resize(history_list_length_, -1);
1359 if (params.pending_history_list_offset >= 0 &&
1360 params.pending_history_list_offset < history_list_length_)
1361 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001362
[email protected]e9ff79c2012-10-19 21:31:261363 GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291364
[email protected]3027cf02013-01-24 08:16:581365 WebFrame* frame = webview()->mainFrame();
1366 if (!params.frame_to_navigate.empty()) {
1367 frame = webview()->findFrameByName(
1368 WebString::fromUTF8(params.frame_to_navigate));
1369 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate;
1370 }
1371
1372 if (is_reload && frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291373 // We cannot reload if we do not have any history state. This happens, for
1374 // example, when recovering from a crash. Our workaround here is a bit of
1375 // a hack since it means that reload after a crashed tab does not cause an
1376 // end-to-end cache validation.
1377 is_reload = false;
1378 }
1379
[email protected]3d2fd592012-11-30 02:05:501380 pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params));
[email protected]48a5c772011-04-18 23:50:501381
[email protected]04d3c6e2009-05-22 17:00:131382 // If we are reloading, then WebKit will use the history state of the current
1383 // page, so we should just ignore any given history state. Otherwise, if we
1384 // have history state, then we need to navigate to it, which corresponds to a
1385 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551386 if (is_reload) {
[email protected]7c16976c2012-08-04 02:38:231387 bool reload_original_url =
1388 (params.navigation_type ==
1389 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]ecbf10d2010-02-18 13:03:291390 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021391 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]7c16976c2012-08-04 02:38:231392
1393 if (reload_original_url)
[email protected]3027cf02013-01-24 08:16:581394 frame->reloadWithOverrideURL(params.url, true);
[email protected]7c16976c2012-08-04 02:38:231395 else
[email protected]3027cf02013-01-24 08:16:581396 frame->reload(ignore_cache);
[email protected]691aa2f2013-05-28 22:52:041397 } else if (params.page_state.IsValid()) {
[email protected]04d3c6e2009-05-22 17:00:131398 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581399 DCHECK_NE(params.page_id, -1);
[email protected]691aa2f2013-05-28 22:52:041400 WebHistoryItem item = PageStateToHistoryItem(params.page_state);
[email protected]bf692cd2012-11-14 19:10:021401 if (!item.isNull()) {
1402 // Ensure we didn't save the swapped out URL in UpdateState, since the
1403 // browser should never be telling us to navigate to swappedout://.
1404 CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL));
[email protected]3027cf02013-01-24 08:16:581405 frame->loadHistoryItem(item);
[email protected]bf692cd2012-11-14 19:10:021406 }
[email protected]d1ef81d2012-07-24 11:39:361407 } else if (!params.base_url_for_data_url.is_empty()) {
1408 // A loadData request with a specified base URL.
1409 std::string mime_type, charset, data;
1410 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
[email protected]3027cf02013-01-24 08:16:581411 frame->loadData(
[email protected]d1ef81d2012-07-24 11:39:361412 WebData(data.c_str(), data.length()),
1413 WebString::fromUTF8(mime_type),
1414 WebString::fromUTF8(charset),
1415 params.base_url_for_data_url,
1416 params.history_url_for_data_url,
1417 false);
1418 } else {
1419 CHECK(false) <<
1420 "Invalid URL passed: " << params.url.possibly_invalid_spec();
1421 }
[email protected]04d3c6e2009-05-22 17:00:131422 } else {
1423 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281424 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291425
[email protected]e6f546c32009-07-01 17:12:551426 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231427 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131428
[email protected]3027cf02013-01-24 08:16:581429 if (frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551430 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131431
[email protected]445e1042011-12-03 21:03:151432 if (params.referrer.url.is_valid()) {
1433 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1434 params.referrer.policy,
1435 params.url,
1436 WebString::fromUTF8(params.referrer.url.spec()));
1437 if (!referrer.isEmpty())
1438 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281439 }
[email protected]04d3c6e2009-05-22 17:00:131440
[email protected]52c68652010-12-07 17:47:041441 if (!params.extra_headers.empty()) {
1442 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1443 params.extra_headers.end(), "\n");
1444 i.GetNext(); ) {
1445 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1446 WebString::fromUTF8(i.values()));
1447 }
1448 }
[email protected]132e281a2012-07-31 18:32:441449
1450 if (params.is_post) {
1451 request.setHTTPMethod(WebString::fromUTF8("POST"));
1452
1453 // Set post data.
1454 WebHTTPBody http_body;
1455 http_body.initialize();
1456 http_body.appendData(WebData(
1457 reinterpret_cast<const char*>(
1458 &params.browser_initiated_post_data.front()),
1459 params.browser_initiated_post_data.size()));
1460 request.setHTTPBody(http_body);
1461 }
1462
[email protected]3027cf02013-01-24 08:16:581463 frame->loadRequest(request);
[email protected]198a95d62013-04-11 00:44:211464
1465 // If this is a cross-process navigation, the browser process will send
1466 // along the proper navigation start value.
1467 if (!params.browser_navigation_start.is_null() &&
1468 frame->provisionalDataSource()) {
1469 // browser_navigation_start is likely before this process existed, so we
1470 // can't use InterProcessTimeTicksConverter. Instead, the best we can do
1471 // is just ensure we don't report a bogus value in the future.
1472 base::TimeTicks navigation_start = std::min(
1473 base::TimeTicks::Now(), params.browser_navigation_start);
1474 double navigation_start_seconds =
1475 (navigation_start - base::TimeTicks()).InSecondsF();
1476 frame->provisionalDataSource()->setNavigationStartTime(
1477 navigation_start_seconds);
1478 }
[email protected]c0588052008-10-27 23:01:501479 }
1480
[email protected]77f17a82009-05-21 04:42:541481 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071482 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291483}
1484
[email protected]310ebd6302011-10-10 19:06:281485bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031486 const ViewMsg_Navigate_Params& params,
1487 bool is_reload) {
1488 // Make sure this isn't a back/forward to an entry we have already cropped
1489 // or replaced from our history, before the browser knew about it. If so,
1490 // a new navigation has committed in the mean time, and we can ignore this.
[email protected]691aa2f2013-05-28 22:52:041491 bool is_back_forward = !is_reload && params.page_state.IsValid();
[email protected]d466b8a2011-07-15 21:48:031492
1493 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1494 // restoring from a previous session. We'll update our state in OnNavigate.
1495 if (!is_back_forward || history_list_length_ <= 0)
1496 return false;
1497
1498 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1499
1500 // Check for whether the forward history has been cropped due to a recent
1501 // navigation the browser didn't know about.
1502 if (params.pending_history_list_offset >= history_list_length_)
1503 return true;
1504
1505 // Check for whether this entry has been replaced with a new one.
1506 int expected_page_id =
1507 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441508 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1509 if (params.page_id < expected_page_id)
1510 return true;
1511
1512 // Otherwise we've removed an earlier entry and should have shifted all
1513 // entries left. For now, it's ok to lazily update the list.
1514 // TODO(creis): Notify all live renderers when we remove entries from
1515 // the front of the list, so that we don't hit this case.
1516 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1517 }
[email protected]d466b8a2011-07-15 21:48:031518
1519 return false;
1520}
1521
initial.commit09911bf2008-07-26 23:55:291522// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281523void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441524 if (webview()) {
1525 WebFrame* main_frame = webview()->mainFrame();
1526 // Stop the alt error page fetcher. If we let it continue it may complete
1527 // and cause RenderViewHostManager to swap to this RenderView, even though
1528 // it may no longer be active.
1529 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1530 StopAltErrorPageFetcher(main_frame->dataSource());
1531 main_frame->stopLoading();
1532 }
initial.commit09911bf2008-07-26 23:55:291533}
1534
[email protected]ecbf10d2010-02-18 13:03:291535// Reload current focused frame.
1536// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281537void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291538 if (webview() && webview()->focusedFrame()) {
1539 // We always obey the cache (ignore_cache=false) here.
1540 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1541 // a cache-ignoring reload of the frame.
1542 webview()->focusedFrame()->reload(false);
1543 }
[email protected]1dda4022010-01-28 18:24:561544}
1545
[email protected]310ebd6302011-10-10 19:06:281546void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271547 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291548}
1549
[email protected]310ebd6302011-10-10 19:06:281550void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291551 // Check if there is a targeturl waiting to be sent.
1552 if (target_url_status_ == TARGET_PENDING) {
1553 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1554 pending_target_url_));
1555 }
1556
1557 target_url_status_ = TARGET_NONE;
1558}
1559
[email protected]310ebd6302011-10-10 19:06:281560void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291561 if (!webview())
1562 return;
1563
[email protected]5d4e36d2013-02-15 15:18:201564 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101565 WebNode current_node = context_menu_node_.isNull() ?
1566 GetFocusedNode() : context_menu_node_;
[email protected]f6b1856b2011-06-29 22:02:531567 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
[email protected]6dd17a8a2013-05-01 05:50:101568 current_node);
initial.commit09911bf2008-07-26 23:55:291569}
1570
[email protected]c084330e02013-04-27 01:08:151571void RenderViewImpl::OnCut() {
[email protected]a954bf72009-09-12 07:30:351572 if (!webview())
1573 return;
1574
[email protected]c084330e02013-04-27 01:08:151575 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101576 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"),
1577 GetFocusedNode());
[email protected]a954bf72009-09-12 07:30:351578}
[email protected]c084330e02013-04-27 01:08:151579
1580void RenderViewImpl::OnDelete() {
1581 if (!webview())
1582 return;
1583
[email protected]6dd17a8a2013-05-01 05:50:101584 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"),
1585 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151586}
1587
1588void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1589 const std::string& value) {
1590 if (!webview() || !webview()->focusedFrame())
1591 return;
1592
1593 webview()->focusedFrame()->executeCommand(
1594 WebString::fromUTF8(name), WebString::fromUTF8(value));
1595}
1596
1597void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1598 if (!webview())
1599 return;
1600
1601 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_));
1602
1603 webview()->focusedFrame()->moveCaretSelectionTowardsWindowPoint(point);
1604}
[email protected]a954bf72009-09-12 07:30:351605
[email protected]310ebd6302011-10-10 19:06:281606void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291607 if (!webview())
1608 return;
1609
[email protected]5d4e36d2013-02-15 15:18:201610 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101611 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"),
1612 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291613}
1614
[email protected]44bf7002011-10-16 02:46:151615void RenderViewImpl::OnPasteAndMatchStyle() {
1616 if (!webview())
1617 return;
1618
[email protected]5d4e36d2013-02-15 15:18:201619 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]44bf7002011-10-16 02:46:151620 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101621 WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode());
[email protected]44bf7002011-10-16 02:46:151622}
1623
[email protected]c084330e02013-04-27 01:08:151624void RenderViewImpl::OnRedo() {
1625 if (!webview())
1626 return;
1627
[email protected]6dd17a8a2013-05-01 05:50:101628 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"),
1629 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151630}
1631
[email protected]310ebd6302011-10-10 19:06:281632void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291633 if (!webview())
1634 return;
1635
[email protected]1ff7a032010-02-03 02:46:031636 WebFrame* frame = webview()->focusedFrame();
1637 if (!frame->hasSelection())
1638 frame->selectWordAroundCaret();
[email protected]2365c642013-02-12 19:16:471639
[email protected]1ff7a032010-02-03 02:46:031640 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291641}
1642
[email protected]2365c642013-02-12 19:16:471643void RenderViewImpl::OnReplaceMisspelling(const string16& text) {
1644 if (!webview())
1645 return;
1646
1647 WebFrame* frame = webview()->focusedFrame();
1648 if (!frame->hasSelection())
1649 return;
1650
1651 frame->replaceMisspelledRange(text);
1652}
1653
[email protected]c084330e02013-04-27 01:08:151654void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1655 const gfx::Rect& rect) {
1656 WebKit::WebNode node = GetFocusedNode();
1657 if (!node.isNull()) {
1658 if (IsEditableNode(node)) {
1659 webview()->saveScrollAndScaleState();
1660 webview()->scrollFocusedNodeIntoRect(rect);
1661 }
1662 }
[email protected]25bcc8f2013-01-09 02:49:251663}
1664
[email protected]310ebd6302011-10-10 19:06:281665void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291666 if (!webview())
1667 return;
1668
[email protected]5d4e36d2013-02-15 15:18:201669 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]26aa0482009-09-30 16:55:271670 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101671 WebString::fromUTF8("SelectAll"), GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291672}
1673
[email protected]c084330e02013-04-27 01:08:151674void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1675 const gfx::Point& end) {
1676 if (!webview())
1677 return;
1678
1679 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1680
1681 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1682 webview()->focusedFrame()->selectRange(start, end);
1683}
1684
1685void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1686 const EditCommands& edit_commands) {
1687 edit_commands_ = edit_commands;
1688}
1689
1690void RenderViewImpl::OnUndo() {
1691 if (!webview())
1692 return;
1693
[email protected]6dd17a8a2013-05-01 05:50:101694 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"),
1695 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151696}
1697
[email protected]45a599062012-09-07 20:09:061698void RenderViewImpl::OnUnselect() {
1699 if (!webview())
1700 return;
1701
[email protected]5d4e36d2013-02-15 15:18:201702 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101703 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
1704 GetFocusedNode());
[email protected]45a599062012-09-07 20:09:061705}
1706
[email protected]c084330e02013-04-27 01:08:151707#if defined(OS_MACOSX)
1708void RenderViewImpl::OnCopyToFindPboard() {
1709 if (!webview())
1710 return;
1711
1712 // Since the find pasteboard supports only plain text, this can be simpler
1713 // than the |OnCopy()| case.
1714 WebFrame* frame = webview()->focusedFrame();
1715 if (frame->hasSelection()) {
1716 string16 selection = frame->selectionAsText();
1717 RenderThread::Get()->Send(
1718 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
1719 }
1720}
1721#endif
1722
1723void RenderViewImpl::OnSetName(const std::string& name) {
1724 if (!webview())
1725 return;
1726
1727 webview()->mainFrame()->setName(WebString::fromUTF8(name));
1728}
1729
[email protected]45a599062012-09-07 20:09:061730void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) {
[email protected]5d4e36d2013-02-15 15:18:201731 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]66fca5bc2013-05-23 06:58:291732 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061733 webview()->setEditableSelectionOffsets(start, end);
1734}
1735
1736void RenderViewImpl::OnSetCompositionFromExistingText(
1737 int start, int end,
1738 const std::vector<WebKit::WebCompositionUnderline>& underlines) {
1739 if (!webview())
1740 return;
[email protected]66fca5bc2013-05-23 06:58:291741 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061742 webview()->setCompositionFromExistingText(start, end, underlines);
1743}
1744
1745void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) {
1746 if (!webview())
1747 return;
[email protected]66fca5bc2013-05-23 06:58:291748 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061749 webview()->extendSelectionAndDelete(before, after);
1750}
1751
[email protected]310ebd6302011-10-10 19:06:281752void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1753 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441754 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191755 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441756 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191757
1758 // Generate the new list.
1759 std::vector<int32> new_history_page_ids(history_length, -1);
1760 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1761 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1762 continue;
1763 new_history_page_ids.push_back(history_page_ids_[i]);
1764 }
1765 new_history_page_ids.swap(history_page_ids_);
1766
1767 // Update indexes.
1768 history_list_length_ = history_page_ids_.size();
1769 history_list_offset_ = history_list_length_ - 1;
1770}
1771
1772
[email protected]310ebd6302011-10-10 19:06:281773void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291774 if (!webview())
1775 return;
[email protected]26aa0482009-09-30 16:55:271776 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291777}
1778
[email protected]54ca3ca892011-06-07 21:14:541779#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281780void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331781 if (!webview())
1782 return;
1783 if (in_live_resize)
1784 webview()->willStartLiveResize();
1785 else
1786 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541787}
1788#endif
1789
[email protected]9b7d11e2012-10-08 19:24:141790#if defined(OS_ANDROID)
1791void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1792 const WebNode node = GetFocusedNode();
1793 if (!node.isNull() && IsEditableNode(node))
1794 webview()->restoreScrollAndScaleState();
1795}
1796#endif
1797
initial.commit09911bf2008-07-26 23:55:291798///////////////////////////////////////////////////////////////////////////////
1799
1800// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281801void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451802 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291803 DCHECK(ds);
1804
[email protected]726985e22009-06-18 21:09:281805 const WebURLRequest& request = ds->request();
1806 const WebURLRequest& original_request = ds->originalRequest();
1807 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291808
[email protected]007733c2011-11-17 00:34:071809 DocumentState* document_state = DocumentState::FromDataSource(ds);
1810 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:371811 InternalDocumentStateData* internal_data =
1812 InternalDocumentStateData::FromDocumentState(document_state);
initial.commit09911bf2008-07-26 23:55:291813
1814 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281815 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291816 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051817 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291818 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071819 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191820 params.socket_address.set_host(response.remoteIPAddress().utf8());
1821 params.socket_address.set_port(response.remotePort());
[email protected]e07ddafe2013-03-05 21:03:361822 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
1823 if (extra_data) {
1824 params.was_fetched_via_proxy = extra_data->was_fetched_via_proxy();
1825 }
[email protected]af15bed2010-08-25 21:12:091826 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e20b88d2013-04-09 15:28:371827 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291828
1829 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311830 params.url = GetLoadingUrl(frame);
[email protected]809be032013-03-19 01:56:561831 DCHECK(!is_swapped_out_ || params.url == GURL(kSwappedOutURL));
initial.commit09911bf2008-07-26 23:55:291832
[email protected]5f9b8712011-11-23 08:55:571833 if (frame->document().baseURL() != params.url)
1834 params.base_url = frame->document().baseURL();
1835
[email protected]726985e22009-06-18 21:09:281836 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241837 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041838 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291839
[email protected]e20b88d2013-04-09 15:28:371840 params.searchable_form_url = internal_data->searchable_form_url();
1841 params.searchable_form_encoding = internal_data->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291842
[email protected]e20b88d2013-04-09 15:28:371843 const PasswordForm* password_form_data = document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291844 if (password_form_data)
1845 params.password_form = *password_form_data;
1846
1847 params.gesture = navigation_gesture_;
1848 navigation_gesture_ = NavigationGestureUnknown;
1849
[email protected]0f38dc4552011-02-25 11:24:001850 // Make navigation state a part of the FrameNavigate message so that commited
1851 // entry had it at all times.
[email protected]691aa2f2013-05-28 22:52:041852 WebHistoryItem item = frame->currentHistoryItem();
1853 if (item.isNull()) {
1854 item.initialize();
1855 item.setURLString(request.url().spec().utf16());
[email protected]0f38dc4552011-02-25 11:24:001856 }
[email protected]691aa2f2013-05-28 22:52:041857 params.page_state = HistoryItemToPageState(item);
[email protected]0f38dc4552011-02-25 11:24:001858
[email protected]dd7daa82009-08-10 05:46:451859 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291860 // Top-level navigation.
1861
[email protected]d00a7972012-08-07 06:09:581862 // Reset the zoom limits in case a plugin had changed them previously. This
1863 // will also call us back which will cause us to send a message to
1864 // update WebContentsImpl.
1865 webview()->zoomLimitsChanged(
[email protected]e9ff79c2012-10-19 21:31:261866 WebView::zoomFactorToZoomLevel(kMinimumZoomFactor),
1867 WebView::zoomFactorToZoomLevel(kMaximumZoomFactor));
[email protected]d00a7972012-08-07 06:09:581868
[email protected]b75b8292010-10-01 07:28:251869 // Set zoom level, but don't do it for full-page plugin since they don't use
1870 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011871 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541872 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251873 if (webview()->mainFrame()->document().isPluginDocument()) {
1874 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251875 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251876 } else {
1877 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251878 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251879 }
1880
[email protected]f85f0702010-01-30 09:31:011881 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511882 // This zoom level was merely recorded transiently for this load. We can
1883 // erase it now. If at some point we reload this page, the browser will
1884 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011885 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511886 }
1887
initial.commit09911bf2008-07-26 23:55:291888 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551889 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291890
[email protected]daa8c58e2009-06-15 17:21:101891 params.transition = navigation_state->transition_type();
[email protected]e9ff79c2012-10-19 21:31:261892 if (!PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291893 // If the main frame does a load, it should not be reported as a subframe
1894 // navigation. This can occur in the following case:
1895 // 1. You're on a site with frames.
1896 // 2. You do a subframe navigation. This is stored with transition type
1897 // MANUAL_SUBFRAME.
1898 // 3. You navigate to some non-frame site, say, google.com.
1899 // 4. You navigate back to the page from step 2. Since it was initially
1900 // MANUAL_SUBFRAME, it will be that same transition type here.
1901 // We don't want that, because any navigation that changes the toplevel
1902 // frame should be tracked as a toplevel navigation (this allows us to
1903 // update the URL bar, etc).
[email protected]e9ff79c2012-10-19 21:31:261904 params.transition = PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291905 }
1906
initial.commit09911bf2008-07-26 23:55:291907 // If we have a valid consumed client redirect source,
1908 // the page contained a client redirect (meta refresh, document.loc...),
1909 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151910 if (completed_client_redirect_src_.url.is_valid()) {
1911 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291912 params.referrer = completed_client_redirect_src_;
[email protected]e9ff79c2012-10-19 21:31:261913 params.transition = static_cast<PageTransition>(
1914 params.transition | PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291915 } else {
1916 // Bug 654101: the referrer will be empty on https->http transitions. It
1917 // would be nice if we could get the real referrer from somewhere.
[email protected]44e55b012013-07-23 14:21:561918 params.referrer = GetReferrerFromRequest(frame, original_request);
initial.commit09911bf2008-07-26 23:55:291919 }
1920
[email protected]726985e22009-06-18 21:09:281921 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051922 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291923 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051924 params.post_id = ExtractPostId(item);
1925 }
initial.commit09911bf2008-07-26 23:55:291926
[email protected]bf70edce2012-06-20 22:32:221927 // Send the user agent override back.
[email protected]e20b88d2013-04-09 15:28:371928 params.is_overriding_user_agent = internal_data->is_overriding_user_agent();
[email protected]bf70edce2012-06-20 22:32:221929
[email protected]7c16976c2012-08-04 02:38:231930 // Track the URL of the original request.
1931 params.original_request_url = original_request.url();
1932
[email protected]60d6cca2013-04-30 08:47:131933 params.history_list_was_cleared =
1934 navigation_state->history_list_was_cleared();
1935
[email protected]c2a797d2009-09-21 16:46:321936 // Save some histogram data so we can compute the average memory used per
1937 // page load of the glyphs.
1938 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1939 webkit_glue::GetGlyphPageCount());
1940
[email protected]15cf526b2010-02-12 06:33:491941 // This message needs to be sent before any of allowScripts(),
1942 // allowImages(), allowPlugins() is called for the new page, so that when
1943 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1944 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291945 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1946 } else {
1947 // Subframe navigation: the type depends on whether this navigation
1948 // generated a new session history entry. When they do generate a session
1949 // history entry, it means the user initiated the navigation and we should
1950 // mark it as such. This test checks if this is the first time UpdateURL
1951 // has been called since WillNavigateToURL was called to initiate the load.
1952 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]e9ff79c2012-10-19 21:31:261953 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291954 else
[email protected]e9ff79c2012-10-19 21:31:261955 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291956
[email protected]60d6cca2013-04-30 08:47:131957 DCHECK(!navigation_state->history_list_was_cleared());
1958 params.history_list_was_cleared = false;
1959
initial.commit09911bf2008-07-26 23:55:291960 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1961 }
1962
1963 last_page_id_sent_to_browser_ =
1964 std::max(last_page_id_sent_to_browser_, page_id_);
1965
1966 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101967 // we don't want the transition type to persist. Just clear it.
[email protected]e9ff79c2012-10-19 21:31:261968 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291969}
1970
1971// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281972void RenderViewImpl::UpdateTitle(WebFrame* frame,
1973 const string16& title,
1974 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461975 // Ignore all but top level navigations.
1976 if (frame->parent())
1977 return;
1978
[email protected]91a2aea2013-07-08 23:14:391979 base::debug::TraceLog::GetInstance()->UpdateProcessLabel(
1980 routing_id_, UTF16ToUTF8(title));
1981
[email protected]e9ff79c2012-10-19 21:31:261982 string16 shortened_title = title.substr(0, kMaxTitleChars);
[email protected]a49e10b2011-08-01 23:57:461983 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1984 title_direction));
initial.commit09911bf2008-07-26 23:55:291985}
1986
[email protected]310ebd6302011-10-10 19:06:281987void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1988 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291989 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271990 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291991 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301992 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291993 last_encoding_name_ = encoding_name;
1994
[email protected]e38f40152008-09-12 23:08:301995 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291996 }
1997}
1998
[email protected]e15f680732010-11-23 22:30:201999// Sends the last committed session history state to the browser so it will be
2000// saved before we navigate to a new page. This must be called *before* the
2001// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:282002void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:292003 // If we have a valid page ID at this point, then it corresponds to the page
2004 // we are navigating away from. Otherwise, this is the first navigation, so
2005 // there is no past session history to record.
2006 if (page_id_ == -1)
2007 return;
2008
[email protected]ca948a22009-06-25 19:36:172009 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:272010 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:052011 SendUpdateState(item);
2012}
2013
2014void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:172015 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292016 return;
[email protected]ca948a22009-06-25 19:36:172017
[email protected]e9ff79c2012-10-19 21:31:262018 // Don't send state updates for kSwappedOutURL.
2019 if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:052020 return;
2021
[email protected]ca948a22009-06-25 19:36:172022 Send(new ViewHostMsg_UpdateState(
[email protected]691aa2f2013-05-28 22:52:042023 routing_id_, page_id_, HistoryItemToPageState(item)));
initial.commit09911bf2008-07-26 23:55:292024}
2025
[email protected]310ebd6302011-10-10 19:06:282026void RenderViewImpl::OpenURL(WebFrame* frame,
2027 const GURL& url,
[email protected]445e1042011-12-03 21:03:152028 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:282029 WebNavigationPolicy policy) {
[email protected]e2caa032012-11-15 23:29:182030 ViewHostMsg_OpenURL_Params params;
2031 params.url = url;
2032 params.referrer = referrer;
2033 params.disposition = NavigationPolicyToDisposition(policy);
2034 params.frame_id = frame->identifier();
[email protected]b4c09692012-12-13 19:15:462035 WebDataSource* ds = frame->provisionalDataSource();
2036 if (ds) {
[email protected]866fa2cc2013-07-22 22:19:522037 params.should_replace_current_entry = ds->replacesCurrentHistoryItem();
[email protected]b4c09692012-12-13 19:15:462038 } else {
[email protected]866fa2cc2013-07-22 22:19:522039 params.should_replace_current_entry = false;
[email protected]b4c09692012-12-13 19:15:462040 }
[email protected]e7f2e7c2013-07-15 09:41:302041 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:412042 if (GetContentClient()->renderer()->AllowPopup())
2043 params.user_gesture = true;
[email protected]e7f2e7c2013-07-15 09:41:302044
2045 if (policy == WebKit::WebNavigationPolicyNewBackgroundTab ||
2046 policy == WebKit::WebNavigationPolicyNewForegroundTab ||
2047 policy == WebKit::WebNavigationPolicyNewWindow ||
2048 policy == WebKit::WebNavigationPolicyNewPopup) {
2049 WebUserGestureIndicator::consumeUserGesture();
2050 }
[email protected]e2caa032012-11-15 23:29:182051
2052 Send(new ViewHostMsg_OpenURL(routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172053}
2054
[email protected]79dbc662009-09-04 05:42:512055// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:292056
[email protected]310ebd6302011-10-10 19:06:282057void RenderViewImpl::LoadNavigationErrorPage(
2058 WebFrame* frame,
2059 const WebURLRequest& failed_request,
2060 const WebURLError& error,
2061 const std::string& html,
2062 bool replace) {
[email protected]d7b175e2011-10-11 15:31:582063 std::string alt_html;
2064 const std::string* error_html;
2065
2066 if (!html.empty()) {
2067 error_html = &html;
2068 } else {
[email protected]e9ff79c2012-10-19 21:31:262069 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:532070 frame, failed_request, error, &alt_html, NULL);
[email protected]d7b175e2011-10-11 15:31:582071 error_html = &alt_html;
2072 }
2073
2074 frame->loadHTMLString(*error_html,
[email protected]e9ff79c2012-10-19 21:31:262075 GURL(kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:252076 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:552077 replace);
initial.commit09911bf2008-07-26 23:55:292078}
2079
[email protected]e9ff79c2012-10-19 21:31:262080bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:282081 const string16& message,
2082 const string16& default_value,
2083 const GURL& frame_url,
2084 string16* result) {
initial.commit09911bf2008-07-26 23:55:292085 bool success = false;
[email protected]4f5ce842011-05-27 19:34:412086 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:292087 if (!result)
2088 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:292089
[email protected]12636df2009-09-28 22:32:212090 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
2091 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:292092 return success;
2093}
2094
[email protected]310ebd6302011-10-10 19:06:282095bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:572096 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
2097 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
2098 // it is particularly important that we do not call willEnterModalLoop as
2099 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:442100 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2101 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:572102
2103 message->EnableMessagePumping(); // Runs a nested message loop.
2104 return Send(message);
2105}
2106
[email protected]c9bc8f12012-12-15 22:20:092107void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) {
2108 int id = next_snapshot_id_++;
2109 pending_snapshots_.insert(std::make_pair(id, callback));
2110 Send(new ViewHostMsg_GetWindowSnapshot(routing_id_, id));
2111}
2112
2113void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id,
2114 const gfx::Size& size, const std::vector<unsigned char>& png) {
2115 PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id);
2116 DCHECK(it != pending_snapshots_.end());
2117 it->second.Run(size, png);
2118 pending_snapshots_.erase(it);
2119}
2120
[email protected]48c9cf2d2009-09-16 16:47:522121// WebKit::WebViewClient ------------------------------------------------------
2122
[email protected]916dfb62012-03-05 03:39:372123WebView* RenderViewImpl::createView(
2124 WebFrame* creator,
2125 const WebURLRequest& request,
2126 const WebWindowFeatures& features,
2127 const WebString& frame_name,
2128 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:522129 // Check to make sure we aren't overloading on popups.
2130 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2131 return NULL;
2132
[email protected]8ab04652010-06-12 02:47:262133 ViewHostMsg_CreateWindow_Params params;
2134 params.opener_id = routing_id_;
[email protected]af15bf22013-03-08 01:18:172135 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:412136 if (GetContentClient()->renderer()->AllowPopup())
2137 params.user_gesture = true;
[email protected]8ab04652010-06-12 02:47:262138 params.window_container_type = WindowFeaturesToContainerType(features);
2139 params.session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:212140 if (frame_name != "_blank")
2141 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112142 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:412143 params.opener_url = creator->document().url();
[email protected]7f48b712013-01-25 01:48:302144 GURL security_url(creator->document().securityOrigin().toString().utf8());
2145 if (!security_url.is_valid())
2146 security_url = GURL();
2147 params.opener_security_origin = security_url;
[email protected]f92ce2b2012-03-06 18:02:592148 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
2149 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]44e55b012013-07-23 14:21:562150 if (!request.isNull()) {
[email protected]41e65502011-01-21 09:29:112151 params.target_url = request.url();
[email protected]44e55b012013-07-23 14:21:562152 params.referrer = GetReferrerFromRequest(creator, request);
2153 }
[email protected]453c1b22013-07-23 09:31:482154 params.features = features;
[email protected]8ab04652010-06-12 02:47:262155
[email protected]48c9cf2d2009-09-16 16:47:522156 int32 routing_id = MSG_ROUTING_NONE;
[email protected]227692c52013-05-31 22:43:042157 int32 main_frame_routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:562158 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:342159 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:522160
[email protected]380244092011-10-07 17:26:272161 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:262162 new ViewHostMsg_CreateWindow(params,
2163 &routing_id,
[email protected]227692c52013-05-31 22:43:042164 &main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562165 &surface_id,
[email protected]8ab04652010-06-12 02:47:262166 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212167 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522168 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522169
[email protected]af15bf22013-03-08 01:18:172170 WebUserGestureIndicator::consumeUserGesture();
[email protected]c59262422012-11-30 21:20:522171
[email protected]3184f90b2013-05-01 18:17:532172 WebPreferences transferred_preferences = webkit_preferences_;
[email protected]9115d5f2013-03-24 04:37:412173
2174 // Unless accelerated compositing has been explicitly disabled from the
2175 // command line (e.g. via the blacklist or about:flags) re-enable it for
2176 // new views that get spawned by this view. This gets around the issue that
2177 // background extension pages disable accelerated compositing via web prefs
2178 // but can themselves spawn a visible render view which should be allowed
2179 // use gpu acceleration.
2180 if (!webkit_preferences_.accelerated_compositing_enabled) {
2181 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2182 if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
2183 transferred_preferences.accelerated_compositing_enabled = true;
2184 }
2185
[email protected]310ebd6302011-10-10 19:06:282186 RenderViewImpl* view = RenderViewImpl::Create(
[email protected]310ebd6302011-10-10 19:06:282187 routing_id_,
2188 renderer_preferences_,
[email protected]9115d5f2013-03-24 04:37:412189 transferred_preferences,
[email protected]fc72bb12013-06-02 21:13:462190 shared_popup_counter_.get(),
[email protected]310ebd6302011-10-10 19:06:282191 routing_id,
[email protected]227692c52013-05-31 22:43:042192 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562193 surface_id,
[email protected]310ebd6302011-10-10 19:06:282194 cloned_session_storage_namespace_id,
[email protected]5cef23d2013-02-27 13:11:212195 string16(), // WebCore will take care of setting the correct name.
[email protected]14392a52012-05-02 20:28:442196 true,
2197 false,
[email protected]6fd35b72012-03-01 19:46:412198 1,
[email protected]842f10652012-06-06 01:54:042199 screen_info_,
[email protected]34bb3ac2013-03-08 02:41:282200 accessibility_mode_,
2201 allow_partial_swap_);
[email protected]8ab04652010-06-12 02:47:262202 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522203
[email protected]007a848b2009-10-26 15:55:462204 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:592205 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:462206
[email protected]48c9cf2d2009-09-16 16:47:522207 // Copy over the alternate error page URL so we can have alt error pages in
2208 // the new render view (we don't need the browser to send the URL back down).
2209 view->alternate_error_page_url_ = alternate_error_page_url_;
2210
2211 return view->webview();
2212}
2213
[email protected]310ebd6302011-10-10 19:06:282214WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:412215 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:042216 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:522217 return widget->webwidget();
2218}
2219
[email protected]310ebd6302011-10-10 19:06:282220WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:082221 const WebPopupMenuInfo& popup_menu_info,
2222 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:272223 // An IPC message is sent to the browser to build and display the actual
2224 // popup. The user could have time to click a different select by the time
2225 // the popup is shown. In that case external_popup_menu_ is non NULL.
2226 // By returning NULL in that case, we instruct WebKit to cancel that new
2227 // popup. So from the user perspective, only the first one will show, and
2228 // will have to close the first one before another one can be shown.
[email protected]59383c782013-04-17 16:43:272229 if (external_popup_menu_)
[email protected]8de2f882012-05-30 00:32:272230 return NULL;
[email protected]caf706f2010-10-26 17:54:082231 external_popup_menu_.reset(
2232 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2233 return external_popup_menu_.get();
2234}
2235
[email protected]310ebd6302011-10-10 19:06:282236RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:522237 webkit::ppapi::PluginInstance* plugin) {
[email protected]ebd71962012-12-20 02:56:552238#if defined(ENABLE_PLUGINS)
[email protected]d91233b7e2011-03-29 20:33:532239 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:422240 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:412241 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:532242 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]bee6eb72012-07-26 03:47:322243 routing_id_, plugin, active_url, screen_info_);
[email protected]79c7bed2010-09-14 22:28:392244 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:562245 return widget;
[email protected]ebd71962012-12-20 02:56:552246#else // defined(ENABLE_PLUGINS)
2247 NOTREACHED() << "CreatePepperFullscreenContainer: plugins disabled";
2248 return NULL;
2249#endif
[email protected]79c7bed2010-09-14 22:28:392250}
2251
[email protected]23367482013-06-27 21:06:542252WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() {
[email protected]b928936b2012-04-13 01:16:162253 CHECK(session_storage_namespace_id_ !=
2254 dom_storage::kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:102255 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342256}
2257
[email protected]310ebd6302011-10-10 19:06:282258void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:522259 const WebConsoleMessage& message, const WebString& source_name,
2260 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:082261 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:512262 switch (message.level) {
[email protected]80ac8942013-01-30 22:53:222263 case WebConsoleMessage::LevelDebug:
[email protected]d09df4b2011-04-11 19:01:082264 log_severity = logging::LOG_VERBOSE;
2265 break;
2266 case WebConsoleMessage::LevelLog:
2267 log_severity = logging::LOG_INFO;
2268 break;
2269 case WebConsoleMessage::LevelWarning:
2270 log_severity = logging::LOG_WARNING;
2271 break;
2272 case WebConsoleMessage::LevelError:
2273 log_severity = logging::LOG_ERROR;
2274 break;
2275 default:
2276 NOTREACHED();
2277 }
2278
[email protected]48c9cf2d2009-09-16 16:47:522279 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:082280 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:312281 message.text,
[email protected]48c9cf2d2009-09-16 16:47:522282 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:312283 source_name));
[email protected]48c9cf2d2009-09-16 16:47:522284}
2285
[email protected]310ebd6302011-10-10 19:06:282286void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:112287 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2288 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:522289}
2290
[email protected]310ebd6302011-10-10 19:06:282291WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512292 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022293}
2294
[email protected]310ebd6302011-10-10 19:06:282295bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:122296 const WebString& path,
2297 WebFileChooserCompletion* chooser_completion) {
2298 int id = enumeration_completion_id_++;
2299 enumeration_completions_[id] = chooser_completion;
2300 return Send(new ViewHostMsg_EnumerateDirectory(
2301 routing_id_,
2302 id,
[email protected]728c2ee2013-06-25 04:01:072303 base::FilePath::FromUTF16Unsafe(path)));
[email protected]8a58c1c2011-04-19 18:40:122304}
2305
[email protected]4b1146bc2012-07-10 18:46:032306void RenderViewImpl::initializeHelperPluginWebFrame(
2307 WebKit::WebHelperPlugin* plugin) {
[email protected]2f61bdd2013-07-02 18:38:472308 plugin->initializeFrame(main_render_frame_.get());
[email protected]4b1146bc2012-07-10 18:46:032309}
2310
[email protected]310ebd6302011-10-10 19:06:282311void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522312 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:142313 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:522314 return;
2315 }
2316
2317 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:522318
2319 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:312320
2321 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:522322}
2323
[email protected]310ebd6302011-10-10 19:06:282324void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522325 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:142326 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:522327 return;
2328 }
2329
2330 is_loading_ = false;
2331
2332 // NOTE: For now we're doing the safest thing, and sending out notification
2333 // when done loading. This currently isn't an issue as the favicon is only
2334 // displayed when done loading. Ideally we would send notification when
2335 // finished parsing the head, but webkit doesn't support that yet.
2336 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:522337 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2338
[email protected]90109412010-12-15 17:14:242339 if (load_progress_tracker_ != NULL)
2340 load_progress_tracker_->DidStopLoading();
2341
[email protected]41225fe2013-03-29 05:32:022342 DidStopLoadingIcons();
2343
[email protected]93b9d692011-04-13 00:44:312344 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:522345}
2346
[email protected]310ebd6302011-10-10 19:06:282347void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
2348 double load_progress) {
[email protected]90109412010-12-15 17:14:242349 if (load_progress_tracker_ != NULL)
2350 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2351}
2352
[email protected]550b0c92013-02-04 05:09:152353void RenderViewImpl::didCancelCompositionOnSelectionChange() {
2354 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2355}
2356
[email protected]310ebd6302011-10-10 19:06:282357void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:082358 if (!handling_input_event_ && !handling_select_range_)
[email protected]5d4e36d2013-02-15 15:18:202359 return;
[email protected]d4cff272011-05-02 15:46:012360
[email protected]fca52022012-04-03 17:00:502361 if (is_empty_selection)
2362 selection_text_.clear();
2363
[email protected]b781ff282011-08-20 06:19:362364 SyncSelectionIfRequired();
[email protected]cb9e2632013-06-18 11:26:472365 UpdateTextInputType();
2366#if defined(OS_ANDROID)
[email protected]5d4e36d2013-02-15 15:18:202367 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]cb9e2632013-06-18 11:26:472368#endif
[email protected]04fc9482009-09-18 22:13:032369}
2370
[email protected]310ebd6302011-10-10 19:06:282371void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122372 const std::string& name = UTF16ToUTF8(command_name);
2373 if (StartsWithASCII(name, "Move", true) ||
2374 StartsWithASCII(name, "Insert", true) ||
2375 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032376 return;
[email protected]f1a29a02011-10-06 23:08:442377 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:032378}
2379
[email protected]310ebd6302011-10-10 19:06:282380bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:102381 if (edit_commands_.empty())
2382 return false;
2383
[email protected]26aa0482009-09-30 16:55:272384 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102385 if (!frame)
2386 return false;
2387
2388 EditCommands::iterator it = edit_commands_.begin();
2389 EditCommands::iterator end = edit_commands_.end();
2390
[email protected]507b33ea2009-09-29 03:56:512391 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102392 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332393 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2394 // key (but it's the exception). Once one edit command is not executed, it
2395 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102396 if (!frame->executeCommand(WebString::fromUTF8(it->name),
[email protected]b77fac52013-06-01 01:03:462397 WebString::fromUTF8(it->value),
2398 GetFocusedNode()))
[email protected]b2528b72009-09-24 06:57:102399 break;
[email protected]507b33ea2009-09-29 03:56:512400 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102401 }
2402
[email protected]507b33ea2009-09-29 03:56:512403 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102404}
2405
[email protected]da8543762012-03-20 08:52:202406WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
2407 WebKit::WebColorChooserClient* client,
2408 const WebKit::WebColor& initial_color) {
2409 RendererWebColorChooserImpl* color_chooser =
2410 new RendererWebColorChooserImpl(this, client);
2411 color_chooser->Open(static_cast<SkColor>(initial_color));
2412 return color_chooser;
2413}
2414
[email protected]310ebd6302011-10-10 19:06:282415bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:352416 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472417 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352418 // Do not open the file dialog in a hidden RenderView.
2419 if (is_hidden())
2420 return false;
[email protected]e9ff79c2012-10-19 21:31:262421 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262422 if (params.directory)
[email protected]e9ff79c2012-10-19 21:31:262423 ipc_params.mode = FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:262424 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:262425 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502426 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:262427 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262428 else
[email protected]e9ff79c2012-10-19 21:31:262429 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472430 ipc_params.title = params.title;
2431 ipc_params.default_file_name =
[email protected]728c2ee2013-06-25 04:01:072432 base::FilePath::FromUTF16Unsafe(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322433 ipc_params.accept_types.reserve(params.acceptTypes.size());
2434 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2435 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]2fdf2352012-11-01 19:23:022436#if defined(OS_ANDROID)
[email protected]b7b4beb2013-07-09 14:06:502437 ipc_params.capture = params.useMediaCapture;
[email protected]2fdf2352012-11-01 19:23:022438#endif
[email protected]cdaf8d02010-03-30 19:52:472439
2440 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462441}
2442
[email protected]269f86d2011-12-07 02:43:472443void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2444 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262445 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412446 message,
2447 string16(),
[email protected]b6cb3a842011-06-24 18:28:412448 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522449 NULL);
2450}
2451
[email protected]269f86d2011-12-07 02:43:472452bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2453 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262454 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412455 message,
2456 string16(),
[email protected]b6cb3a842011-06-24 18:28:412457 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522458 NULL);
2459}
2460
[email protected]269f86d2011-12-07 02:43:472461bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2462 const WebString& message,
2463 const WebString& default_value,
2464 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412465 string16 result;
[email protected]e9ff79c2012-10-19 21:31:262466 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412467 message,
2468 default_value,
[email protected]b6cb3a842011-06-24 18:28:412469 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522470 &result);
2471 if (ok)
[email protected]4f5ce842011-05-27 19:34:412472 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522473 return ok;
2474}
2475
[email protected]310ebd6302011-10-10 19:06:282476bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522477 WebFrame* frame, const WebString& message) {
[email protected]ab533826b2013-05-10 23:54:562478 bool is_reload = false;
2479 WebDataSource* ds = frame->provisionalDataSource();
2480 if (ds)
2481 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
2482 return runModalBeforeUnloadDialog(frame, is_reload, message);
2483}
2484
2485bool RenderViewImpl::runModalBeforeUnloadDialog(
2486 WebFrame* frame, bool is_reload, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152487 // If we are swapping out, we have already run the beforeunload handler.
2488 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2489 // at all, to avoid running it twice.
2490 if (is_swapped_out_)
2491 return true;
2492
[email protected]48c9cf2d2009-09-16 16:47:522493 bool success = false;
2494 // This is an ignored return value, but is included so we can accept the same
2495 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412496 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212497 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322498 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412499 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522500 return success;
2501}
2502
[email protected]310ebd6302011-10-10 19:06:282503void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442504 WebFrame* frame, const WebContextMenuData& data) {
[email protected]3175fea2013-05-16 10:57:482505 ContextMenuParams params = ContextMenuParamsBuilder::Build(data);
[email protected]f56c7872013-06-18 12:31:572506 params.source_type = context_menu_source_type_;
[email protected]a14ddcd2013-06-21 22:53:032507 if (context_menu_source_type_ == ui::MENU_SOURCE_TOUCH_EDIT_MENU) {
[email protected]f56c7872013-06-18 12:31:572508 params.x = touch_editing_context_menu_location_.x();
2509 params.y = touch_editing_context_menu_location_.y();
2510 }
[email protected]7fcd9b72011-07-27 16:52:372511
[email protected]329266d2012-09-27 06:20:572512 // Plugins, e.g. PDF, don't currently update the render view when their
2513 // selected text changes, but the context menu params do contain the updated
2514 // selection. If that's the case, update the render view's state just prior
2515 // to showing the context menu.
2516 // TODO(asvitkine): http://crbug.com/152432
[email protected]432c9a72013-02-27 01:51:032517 if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_,
2518 selection_text_offset_,
2519 selection_range_,
2520 params)) {
[email protected]329266d2012-09-27 06:20:572521 selection_text_ = params.selection_text;
2522 // TODO(asvitkine): Text offset and range is not available in this case.
2523 selection_text_offset_ = 0;
2524 selection_range_ = ui::Range(0, selection_text_.length());
2525 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2526 selection_text_,
2527 selection_text_offset_,
2528 selection_range_));
2529 }
2530
[email protected]7fcd9b72011-07-27 16:52:372531 // frame is NULL if invoked by BlockedPlugin.
2532 if (frame)
2533 params.frame_id = frame->identifier();
2534
[email protected]e9ff79c2012-10-19 21:31:262535 // Serializing a GURL longer than kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272536 // it. We replace it with an empty GURL so the appropriate items are disabled
2537 // in the context menu.
2538 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2539 // data encoded images. We should have a way to save them.
[email protected]e9ff79c2012-10-19 21:31:262540 if (params.src_url.spec().size() > kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272541 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102542 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412543
2544#if defined(OS_ANDROID)
2545 gfx::Rect start_rect;
2546 gfx::Rect end_rect;
2547 GetSelectionBounds(&start_rect, &end_rect);
[email protected]326a2342013-02-15 15:47:512548 params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom());
2549 params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom());
[email protected]44daa3b2012-09-27 19:26:412550#endif
2551
[email protected]c27324b2009-11-19 22:44:292552 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]b2324b092012-11-01 10:34:112553
2554 FOR_EACH_OBSERVER(
2555 RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data));
[email protected]79e37442009-10-09 18:17:442556}
2557
[email protected]310ebd6302011-10-10 19:06:282558void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522559}
2560
[email protected]310ebd6302011-10-10 19:06:282561void RenderViewImpl::UpdateTargetURL(const GURL& url,
2562 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582563 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522564 if (latest_url == target_url_)
2565 return;
[email protected]163f8242009-10-30 20:19:552566
[email protected]48c9cf2d2009-09-16 16:47:522567 // Tell the browser to display a destination link.
2568 if (target_url_status_ == TARGET_INFLIGHT ||
2569 target_url_status_ == TARGET_PENDING) {
2570 // If we have a request in-flight, save the URL to be sent when we
2571 // receive an ACK to the in-flight request. We can happily overwrite
2572 // any existing pending sends.
2573 pending_target_url_ = latest_url;
2574 target_url_status_ = TARGET_PENDING;
2575 } else {
[email protected]e9ff79c2012-10-19 21:31:262576 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:412577 // see |ParamTraits<GURL>|.
[email protected]e9ff79c2012-10-19 21:31:262578 if (latest_url.possibly_invalid_spec().size() > kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:412579 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522580 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2581 target_url_ = latest_url;
2582 target_url_status_ = TARGET_INFLIGHT;
2583 }
2584}
2585
[email protected]70221f02013-01-31 22:17:072586gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
2587 const gfx::RectF& rect) const {
2588 gfx::RectF window_rect = rect;
2589 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
2590 return window_rect;
2591}
2592
[email protected]310ebd6302011-10-10 19:06:282593void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]a183fb82012-12-14 04:46:222594 // No need to update state if no page has committed yet.
2595 if (page_id_ == -1)
2596 return;
2597
[email protected]882daa92009-11-05 16:31:312598 int delay;
2599 if (send_content_state_immediately_)
2600 delay = 0;
2601 else if (is_hidden())
2602 delay = kDelaySecondsForContentStateSyncHidden;
2603 else
2604 delay = kDelaySecondsForContentStateSync;
2605
2606 if (nav_state_sync_timer_.IsRunning()) {
2607 // The timer is already running. If the delay of the timer maches the amount
2608 // we want to delay by, then return. Otherwise stop the timer so that it
2609 // gets started with the right delay.
2610 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2611 return;
2612 nav_state_sync_timer_.Stop();
2613 }
2614
[email protected]d323a172011-09-02 18:23:022615 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282616 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312617}
2618
[email protected]310ebd6302011-10-10 19:06:282619void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552620 mouse_over_url_ = GURL(url);
2621 UpdateTargetURL(mouse_over_url_, focus_url_);
2622}
2623
[email protected]310ebd6302011-10-10 19:06:282624void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552625 focus_url_ = GURL(url);
2626 UpdateTargetURL(focus_url_, mouse_over_url_);
2627}
2628
[email protected]0407e422012-05-18 19:51:252629void RenderViewImpl::startDragging(WebFrame* frame,
2630 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282631 WebDragOperationsMask mask,
2632 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:242633 const WebPoint& webImageOffset) {
[email protected]dc293a72013-07-01 11:11:222634 DropData drop_data(DropDataBuilder::Build(data));
[email protected]b67151d2012-05-25 23:23:242635 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:242636 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:552637 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242638 drop_data,
[email protected]c27ae592010-03-18 15:24:412639 mask,
[email protected]976127072012-05-10 20:08:112640 image.getSkBitmap(),
[email protected]41d86852012-11-07 12:23:242641 imageOffset,
2642 possible_drag_event_info_));
[email protected]48c9cf2d2009-09-16 16:47:522643}
2644
[email protected]310ebd6302011-10-10 19:06:282645bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452646 return renderer_preferences_.can_accept_load_drops;
2647}
2648
[email protected]310ebd6302011-10-10 19:06:282649void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522650 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2651}
2652
[email protected]310ebd6302011-10-10 19:06:282653void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522654 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2655}
2656
[email protected]310ebd6302011-10-10 19:06:282657void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512658 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072659
[email protected]38b592902011-04-16 02:08:422660 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492661}
2662
[email protected]572a6ca2012-10-11 19:38:012663void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2664 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2665}
2666
[email protected]169d4282011-11-30 19:33:592667void RenderViewImpl::didUpdateLayout() {
2668 // We don't always want to set up a timer, only if we've been put in that
2669 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2670 // message.
2671 if (!send_preferred_size_changes_ || !webview())
2672 return;
2673
2674 if (check_preferred_size_timer_.IsRunning())
2675 return;
2676 check_preferred_size_timer_.Start(FROM_HERE,
2677 TimeDelta::FromMilliseconds(0), this,
2678 &RenderViewImpl::CheckPreferredSize);
2679}
2680
[email protected]310ebd6302011-10-10 19:06:282681void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522682 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2683}
2684
[email protected]310ebd6302011-10-10 19:06:282685int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002686 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522687}
2688
[email protected]310ebd6302011-10-10 19:06:282689int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002690 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522691}
2692
[email protected]310ebd6302011-10-10 19:06:282693void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322694 const WebAccessibilityObject& obj,
2695 WebAccessibilityNotification notification) {
[email protected]2a84f9d2012-06-05 21:50:432696 if (renderer_accessibility_) {
2697 renderer_accessibility_->HandleWebAccessibilityNotification(
2698 obj, notification);
2699 }
[email protected]063afcb2011-09-29 07:54:322700}
2701
[email protected]310ebd6302011-10-10 19:06:282702void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142703 const WebString& value) {
2704 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2705 key.utf8(),
2706 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262707}
2708
[email protected]79dbc662009-09-04 05:42:512709// WebKit::WebWidgetClient ----------------------------------------------------
2710
[email protected]310ebd6302011-10-10 19:06:282711void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122712 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2713 // we won't have to test for user gesture anymore and we can
2714 // move that code back to render_widget.cc
[email protected]af15bf22013-03-08 01:18:172715 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302716 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442717 Send(new ViewHostMsg_Focus(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122718 }
2719}
2720
[email protected]310ebd6302011-10-10 19:06:282721void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122722 // TODO(jcivelli): see TODO above in didFocus().
[email protected]af15bf22013-03-08 01:18:172723 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302724 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442725 Send(new ViewHostMsg_Blur(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122726 }
2727}
2728
initial.commit09911bf2008-07-26 23:55:292729// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282730// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292731// point to dispatch the ShowView message.
2732//
2733// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282734// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292735//
[email protected]310ebd6302011-10-10 19:06:282736void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:252737 if (did_show_) {
[email protected]b2142e962012-10-30 13:59:252738 // When supports_multiple_windows is disabled, popups are reusing
2739 // the same view. In some scenarios, this makes WebKit to call show() twice.
[email protected]c9edabd2013-05-23 13:56:242740 if (webkit_preferences_.supports_multiple_windows)
2741 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:292742 return;
[email protected]b2142e962012-10-30 13:59:252743 }
initial.commit09911bf2008-07-26 23:55:292744 did_show_ = true;
2745
[email protected]b2142e962012-10-30 13:59:252746 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2747
[email protected]28295ec2009-10-16 05:34:332748 // Force new windows to a popup if they were not opened with a user gesture.
2749 if (!opened_by_user_gesture_) {
2750 // We exempt background tabs for compat with older versions of Chrome.
2751 // TODO(darin): This seems bogus. These should have a user gesture, so
2752 // we probably don't need this check.
2753 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2754 policy = WebKit::WebNavigationPolicyNewPopup;
2755 }
2756
initial.commit09911bf2008-07-26 23:55:292757 // NOTE: initial_pos_ may still have its default values at this point, but
2758 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2759 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282760 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2761 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292762 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242763 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292764}
2765
[email protected]310ebd6302011-10-10 19:06:282766void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292767 DCHECK(did_show_) << "should already have shown the view";
2768
[email protected]c1f50aa2010-02-18 03:46:572769 // We must keep WebKit's shared timer running in this case in order to allow
2770 // showModalDialog to function properly.
2771 //
2772 // TODO(darin): WebKit should really be smarter about suppressing events and
2773 // timers so that we do not need to manage the shared timer in such a heavy
2774 // handed manner.
2775 //
[email protected]f1a29a02011-10-06 23:08:442776 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2777 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572778
[email protected]08a1c8102012-05-11 23:14:262779 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2780 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292781}
2782
[email protected]2b624c562011-10-27 22:58:262783bool RenderViewImpl::enterFullScreen() {
2784 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2785 return true;
2786}
2787
2788void RenderViewImpl::exitFullScreen() {
2789 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2790}
2791
[email protected]217690d2012-01-27 07:33:112792bool RenderViewImpl::requestPointerLock() {
2793 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2794}
2795
2796void RenderViewImpl::requestPointerUnlock() {
2797 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2798}
2799
2800bool RenderViewImpl::isPointerLocked() {
2801 return mouse_lock_dispatcher_->IsMouseLockedTo(
2802 webwidget_mouse_lock_target_.get());
2803}
2804
[email protected]7a1ec28a2012-03-28 21:10:242805void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
[email protected]0cd50aa2013-02-12 22:28:012806#if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003
[email protected]ea5f70a2013-03-07 12:30:362807 InputHandlerManager* input_handler_manager =
2808 RenderThreadImpl::current()->input_handler_manager();
[email protected]200a9c062013-05-20 04:34:372809 if (input_handler_manager) {
2810 input_handler_manager->AddInputHandler(
2811 routing_id_,
2812 compositor_->GetInputHandler(),
2813 AsWeakPtr());
2814 }
[email protected]70cff27502013-01-17 09:16:492815#endif
[email protected]7a1ec28a2012-03-28 21:10:242816
2817 RenderWidget::didActivateCompositor(input_handler_identifier);
2818}
2819
[email protected]c68c3e4e2013-01-24 00:36:562820void RenderViewImpl::didHandleGestureEvent(
2821 const WebGestureEvent& event,
2822 bool event_cancelled) {
2823 RenderWidget::didHandleGestureEvent(event, event_cancelled);
2824 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2825 DidHandleGestureEvent(event));
2826}
2827
[email protected]6e89eb72013-07-23 13:28:222828void RenderViewImpl::initializeLayerTreeView() {
2829 RenderWidget::initializeLayerTreeView();
2830 RenderWidgetCompositor* rwc = compositor();
2831 if (!rwc || !webview() || !webview()->devToolsAgent())
2832 return;
2833 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
2834}
2835
[email protected]3d9689372009-09-10 04:29:172836// WebKit::WebFrameClient -----------------------------------------------------
2837
[email protected]29e2fb42013-07-19 01:13:472838WebKit::WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2839 const WebPluginParams& params) {
[email protected]e507045d2013-07-24 15:23:442840 NOTREACHED();
[email protected]ebd71962012-12-20 02:56:552841 return NULL;
[email protected]3d9689372009-09-10 04:29:172842}
2843
[email protected]310ebd6302011-10-10 19:06:282844WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422845 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372846 unsigned long long document_id) {
[email protected]e507045d2013-07-24 15:23:442847 NOTREACHED();
2848 return NULL;
[email protected]9c00f002009-11-05 22:37:422849}
2850
[email protected]97b150db2012-08-16 18:26:022851WebMediaPlayer* RenderViewImpl::createMediaPlayer(
2852 WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442853 FOR_EACH_OBSERVER(
2854 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172855
[email protected]780fc8242012-09-19 20:28:522856 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]75abf382013-07-09 08:14:192857#if defined(ENABLE_WEBRTC)
[email protected]c3bdce152013-07-10 04:56:342858 EnsureMediaStreamClient();
[email protected]75abf382013-07-09 08:14:192859#if !defined(GOOGLE_TV)
[email protected]c3bdce152013-07-10 04:56:342860 if (media_stream_client_->IsMediaStream(url)) {
[email protected]befe54782013-04-23 00:49:252861#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
2862 bool found_neon =
2863 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
2864 UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon);
2865#endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
[email protected]5e35a8d2013-07-10 19:37:212866 return new WebMediaPlayerMS(
[email protected]c3bdce152013-07-10 04:56:342867 frame, client, AsWeakPtr(), media_stream_client_, new RenderMediaLog());
[email protected]d05e2162012-11-16 22:21:462868 }
[email protected]75abf382013-07-09 08:14:192869#endif // !defined(GOOGLE_TV)
2870#endif // defined(ENABLE_WEBRTC)
[email protected]d05e2162012-11-16 22:21:462871
[email protected]25fb9b32012-04-27 03:21:552872#if defined(OS_ANDROID)
[email protected]855623ed2012-09-24 18:59:552873 GpuChannelHost* gpu_channel_host =
2874 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262875 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]855623ed2012-09-24 18:59:552876 if (!gpu_channel_host) {
2877 LOG(ERROR) << "Failed to establish GPU channel for media player";
2878 return NULL;
2879 }
2880
[email protected]a45c46e2013-03-07 01:04:462881 scoped_refptr<cc::ContextProvider> context_provider =
2882 RenderThreadImpl::current()->OffscreenContextProviderForMainThread();
[email protected]13914c92013-06-13 22:42:422883 if (!context_provider.get()) {
[email protected]a45c46e2013-03-07 01:04:462884 LOG(ERROR) << "Failed to get context3d for media player";
2885 return NULL;
2886 }
2887
[email protected]780fc8242012-09-19 20:28:522888 if (!media_player_proxy_) {
[email protected]be580992013-06-22 14:32:442889 media_player_proxy_ = new WebMediaPlayerProxyAndroid(
[email protected]780fc8242012-09-19 20:28:522890 this, media_player_manager_.get());
2891 }
[email protected]be580992013-06-22 14:32:442892 scoped_ptr<WebMediaPlayerAndroid> web_media_player_android(
2893 new WebMediaPlayerAndroid(
[email protected]e69bb062013-06-03 13:05:402894 frame,
2895 client,
[email protected]9aff54d2013-06-18 18:38:502896 AsWeakPtr(),
[email protected]e69bb062013-06-03 13:05:402897 media_player_manager_.get(),
2898 media_player_proxy_,
[email protected]be580992013-06-22 14:32:442899 new StreamTextureFactory(
[email protected]e69bb062013-06-03 13:05:402900 context_provider->Context3d(), gpu_channel_host, routing_id_),
2901 new RenderMediaLog()));
2902#if defined(ENABLE_WEBRTC) && defined(GOOGLE_TV)
[email protected]c3bdce152013-07-10 04:56:342903 if (media_stream_client_->IsMediaStream(url)) {
[email protected]e69bb062013-06-03 13:05:402904 RTCVideoDecoderFactoryTv* factory = RenderThreadImpl::current()
2905 ->GetMediaStreamDependencyFactory()->decoder_factory_tv();
[email protected]75abf382013-07-09 08:14:192906 // |media_stream_client| and |factory| outlives |web_media_player_android|.
[email protected]e69bb062013-06-03 13:05:402907 if (!factory->AcquireDemuxer() ||
2908 !web_media_player_android->InjectMediaStream(
[email protected]c3bdce152013-07-10 04:56:342909 media_stream_client_,
[email protected]e69bb062013-06-03 13:05:402910 factory,
2911 base::Bind(
2912 base::IgnoreResult(&RTCVideoDecoderFactoryTv::ReleaseDemuxer),
2913 base::Unretained(factory)))) {
2914 LOG(ERROR) << "Failed to inject media stream.";
2915 return NULL;
2916 }
2917 }
2918#endif // defined(ENABLE_WEBRTC) && defined(GOOGLE_TV)
2919 return web_media_player_android.release();
2920#endif // defined(OS_ANDROID)
[email protected]25fb9b32012-04-27 03:21:552921
[email protected]4a914882013-01-10 00:43:482922 scoped_refptr<media::AudioRendererSink> sink;
[email protected]3d9689372009-09-10 04:29:172923 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]17c4ce62f2013-05-03 19:54:022924 sink = RenderThreadImpl::current()->GetAudioRendererMixerManager()->
2925 CreateInput(routing_id_);
[email protected]fc72bb12013-06-02 21:13:462926 DVLOG(1) << "Using AudioRendererMixerManager-provided sink: " << sink.get();
[email protected]3d9689372009-09-10 04:29:172927 }
2928
[email protected]b9a407e2013-07-24 07:30:022929 scoped_refptr<media::GpuVideoDecoderFactories> gpu_factories =
[email protected]86e3a702013-07-24 12:22:532930 RenderThreadImpl::current()->GetGpuFactories(
2931 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy());
[email protected]e1d69d762011-12-13 05:12:182932
[email protected]5e35a8d2013-07-10 19:37:212933 WebMediaPlayerParams params(
[email protected]c1330c82013-06-06 02:23:252934 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(),
[email protected]d726eddc2013-07-02 22:25:552935 base::Bind(&ContentRendererClient::DeferMediaLoad,
2936 base::Unretained(GetContentClient()->renderer()),
2937 static_cast<RenderView*>(this)),
2938 sink,
2939 gpu_factories,
2940 new RenderMediaLog());
[email protected]5e35a8d2013-07-10 19:37:212941 return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params);
[email protected]3d9689372009-09-10 04:29:172942}
2943
[email protected]310ebd6302011-10-10 19:06:282944WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212945 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]e507045d2013-07-24 15:23:442946 NOTREACHED();
2947 return NULL;
[email protected]035545f2010-04-09 13:10:212948}
2949
[email protected]310ebd6302011-10-10 19:06:282950WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382951 return &cookie_jar_;
2952}
2953
[email protected]59167c22013-06-03 18:07:322954void RenderViewImpl::didAccessInitialDocument(WebFrame* frame) {
2955 // Notify the browser process that it is no longer safe to show the pending
2956 // URL of the main frame, since a URL spoof is now possible.
2957 if (!frame->parent() && page_id_ == -1)
2958 Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_));
2959}
2960
[email protected]0720b532012-08-28 19:23:372961void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) {
[email protected]e507045d2013-07-24 15:23:442962 NOTREACHED();
[email protected]0720b532012-08-28 19:23:372963}
2964
[email protected]7cc78902012-12-06 02:32:262965void RenderViewImpl::didDisownOpener(WebKit::WebFrame* frame) {
[email protected]29ece2e2013-04-03 04:53:522966 // We only need to notify the browser if the active, top-level frame clears
2967 // its opener. We can ignore cases where a swapped out frame clears its
2968 // opener after hearing about it from the browser, and the browser does not
2969 // (yet) care about subframe openers.
2970 if (is_swapped_out_ || frame->parent())
[email protected]7cc78902012-12-06 02:32:262971 return;
2972
2973 // Notify WebContents and all its swapped out RenderViews.
2974 Send(new ViewHostMsg_DidDisownOpener(routing_id_));
2975}
2976
[email protected]310ebd6302011-10-10 19:06:282977void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512978 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452979}
2980
[email protected]310ebd6302011-10-10 19:06:282981void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512982 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172983}
2984
[email protected]25bcc8f2013-01-09 02:49:252985void RenderViewImpl::didChangeName(WebFrame* frame,
2986 const WebString& name) {
[email protected]e507045d2013-07-24 15:23:442987 NOTREACHED();
[email protected]25bcc8f2013-01-09 02:49:252988}
2989
[email protected]310ebd6302011-10-10 19:06:282990void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172991 WebFrame* frame, const WebURLRequest& request,
2992 WebNavigationPolicy policy) {
[email protected]e507045d2013-07-24 15:23:442993 NOTREACHED();
[email protected]0622875ab2011-07-27 12:10:342994}
2995
[email protected]5e92282f2012-08-17 08:11:572996void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:252997 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:572998}
2999
[email protected]b2324b092012-11-01 10:34:113000void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
3001 const std::string& value) {
3002 EditCommands edit_commands;
3003 edit_commands.push_back(EditCommand(name, value));
3004 OnSetEditCommandsForNextKeyEvent(edit_commands);
3005}
3006
3007void RenderViewImpl::ClearEditCommands() {
3008 edit_commands_.clear();
3009}
3010
[email protected]e4495212012-12-06 03:09:123011SSLStatus RenderViewImpl::GetSSLStatusOfFrame(WebKit::WebFrame* frame) const {
[email protected]83c0abca2013-07-23 20:09:423012 std::string security_info;
3013 if (frame && frame->dataSource())
3014 security_info = frame->dataSource()->response().securityInfo();
3015
3016 SSLStatus ssl_status;
3017 DeserializeSecurityInfo(security_info,
3018 &ssl_status.cert_id,
3019 &ssl_status.cert_status,
3020 &ssl_status.security_bits,
3021 &ssl_status.connection_status);
3022 return ssl_status;
[email protected]e4495212012-12-06 03:09:123023}
3024
[email protected]310ebd6302011-10-10 19:06:283025void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:343026 WebFrame* frame, const WebURLRequest& request,
3027 WebNavigationPolicy policy,
3028 const WebString& suggested_name) {
[email protected]e507045d2013-07-24 15:23:443029 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173030}
3031
[email protected]310ebd6302011-10-10 19:06:283032WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]0d8f04b2013-04-29 20:05:313033 WebFrame* frame, WebDataSource::ExtraData* extraData,
3034 const WebURLRequest& request, WebNavigationType type,
3035 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]099df81cf2012-11-14 17:44:043036 if (request.url() != GURL(kSwappedOutURL) &&
3037 GetContentClient()->renderer()->HandleNavigation(frame, request, type,
3038 default_policy,
3039 is_redirect)) {
3040 return WebKit::WebNavigationPolicyIgnore;
3041 }
3042
[email protected]44e55b012013-07-23 14:21:563043 Referrer referrer(GetReferrerFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:333044
[email protected]992db4c2011-05-12 15:37:153045 if (is_swapped_out_) {
[email protected]e9ff79c2012-10-19 21:31:263046 if (request.url() != GURL(kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:333047 // Targeted links may try to navigate a swapped out frame. Allow the
3048 // browser process to navigate the tab instead. Note that it is also
3049 // possible for non-targeted navigations (from this view) to arrive
3050 // here just after we are swapped out. It's ok to send them to the
3051 // browser, as long as they're for the top level frame.
3052 // TODO(creis): Ensure this supports targeted form submissions when
3053 // fixing http://crbug.com/101395.
3054 if (frame->parent() == NULL) {
3055 OpenURL(frame, request.url(), referrer, default_policy);
3056 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3057 }
3058
3059 // We should otherwise ignore in-process iframe navigations, if they
3060 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:553061 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:333062 }
[email protected]73eb2602012-02-09 19:50:553063
[email protected]e9ff79c2012-10-19 21:31:263064 // Allow kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:153065 return default_policy;
3066 }
3067
[email protected]3d9689372009-09-10 04:29:173068 // Webkit is asking whether to navigate to a new URL.
3069 // This is fine normally, except if we're showing UI from one security
3070 // context and they're trying to navigate to a different context.
3071 const GURL& url = request.url();
3072
[email protected]d19ea342011-04-20 20:31:133073 // A content initiated navigation may have originated from a link-click,
3074 // script, drag-n-drop operation, etc.
[email protected]0d8f04b2013-04-29 20:05:313075 bool is_content_initiated = static_cast<DocumentState*>(extraData)->
[email protected]007733c2011-11-17 00:34:073076 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:133077
[email protected]a8c269a2011-10-25 20:17:223078 // Experimental:
[email protected]c6f2e672012-11-15 01:47:023079 // If --enable-strict-site-isolation or --site-per-process is enabled, send
3080 // all top-level navigations to the browser to let it swap processes when
3081 // crossing site boundaries. This is currently expected to break some script
3082 // calls and navigations, such as form submissions.
[email protected]a8c269a2011-10-25 20:17:223083 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]c6f2e672012-11-15 01:47:023084 bool force_swap_due_to_flag =
3085 command_line.HasSwitch(switches::kEnableStrictSiteIsolation) ||
3086 command_line.HasSwitch(switches::kSitePerProcess);
3087 if (force_swap_due_to_flag &&
[email protected]313b80bd2011-11-23 03:49:103088 !frame->parent() && (is_content_initiated || is_redirect)) {
3089 WebString origin_str = frame->document().securityOrigin().toString();
3090 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:093091 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:103092 // crbug.com/101395 is fixed.
[email protected]ed32c212013-05-14 20:49:293093 bool same_domain_or_host =
3094 net::registry_controlled_domains::SameDomainOrHost(
3095 frame_url,
3096 url,
3097 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
3098 if (!same_domain_or_host || frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:103099 OpenURL(frame, url, referrer, default_policy);
3100 return WebKit::WebNavigationPolicyIgnore;
3101 }
[email protected]a8c269a2011-10-25 20:17:223102 }
3103
[email protected]fd3238af2012-05-22 18:55:303104 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:083105 if (is_content_initiated) {
[email protected]140a5882013-07-23 19:30:333106 bool is_form_post = ((type == WebKit::WebNavigationTypeFormSubmitted) ||
3107 (type == WebKit::WebNavigationTypeFormResubmitted)) &&
3108 EqualsASCII(request.httpMethod(), "POST");
[email protected]fd3238af2012-05-22 18:55:303109 bool browser_handles_request =
3110 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]140a5882013-07-23 19:30:333111 IsNonLocalTopLevelNavigation(url, frame, type, is_form_post);
[email protected]fd3238af2012-05-22 18:55:303112 if (!browser_handles_request) {
3113 browser_handles_request =
3114 renderer_preferences_.browser_handles_all_top_level_requests &&
3115 IsTopLevelNavigation(frame);
3116 }
3117
3118 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:083119 // Reset these counters as the RenderView could be reused for the next
3120 // navigation.
3121 page_id_ = -1;
3122 last_page_id_sent_to_browser_ = -1;
3123 OpenURL(frame, url, referrer, default_policy);
3124 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3125 }
[email protected]3d9689372009-09-10 04:29:173126 }
3127
[email protected]dc67e1c32012-06-08 00:10:403128 // Use the frame's original request's URL rather than the document's URL for
3129 // subsequent checks. For a popup, the document's URL may become the opener
3130 // window's URL if the opener has called document.write().
3131 // See http://crbug.com/93517.
3132 GURL old_url(frame->dataSource()->request().url());
3133
[email protected]6101c342010-12-16 22:44:373134 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:553135 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:043136 // top-level navigations (not iframes). But we sometimes navigate to
3137 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:373138 //
[email protected]744c2a22012-03-15 18:42:043139 // Note: this is known to break POST submissions when crossing process
3140 // boundaries until http://crbug.com/101395 is fixed. This is better for
3141 // security than loading a WebUI, extension or app page in the wrong process.
3142 // POST requests don't work because this mechanism does not preserve form
3143 // POST data. We will need to send the request's httpBody data up to the
3144 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:573145 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
3146 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:223147 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:043148 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:373149 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:043150
[email protected]0a57375a2013-03-07 22:18:593151 // All navigations to or from WebUI URLs or within WebUI-enabled
3152 // RenderProcesses must be handled by the browser process so that the
3153 // correct bindings and data sources can be registered.
[email protected]744c2a22012-03-15 18:42:043154 // Similarly, navigations to view-source URLs or within ViewSource mode
[email protected]1c210f692012-11-06 22:31:473155 // must be handled by the browser process (except for reloads - those are
3156 // safe to leave within the renderer).
[email protected]dc67e1c32012-06-08 00:10:403157 // Lastly, access to file:// URLs from non-file:// URL pages must be
3158 // handled by the browser so that ordinary renderer processes don't get
3159 // blessed with file permissions.
3160 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
3161 bool is_initial_navigation = page_id_ == -1;
[email protected]0a57375a2013-03-07 22:18:593162 bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) ||
[email protected]e9ff79c2012-10-19 21:31:263163 (cumulative_bindings & BINDINGS_POLICY_WEB_UI) ||
[email protected]dbdda5402013-05-30 22:13:483164 url.SchemeIs(kViewSourceScheme) ||
[email protected]1c210f692012-11-06 22:31:473165 (frame->isViewSourceModeEnabled() &&
3166 type != WebKit::WebNavigationTypeReload);
[email protected]5351dbc2010-08-27 15:22:113167
[email protected]dc67e1c32012-06-08 00:10:403168 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
3169 // Fork non-file to file opens. Check the opener URL if this is the
3170 // initial navigation in a newly opened window.
3171 GURL source_url(old_url);
3172 if (is_initial_navigation && source_url.is_empty() && frame->opener())
3173 source_url = frame->opener()->top()->document().url();
3174 DCHECK(!source_url.is_empty());
3175 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
3176 }
3177
[email protected]e48869a2011-04-01 19:56:033178 if (!should_fork) {
3179 // Give the embedder a chance.
[email protected]c5dec6292013-01-25 04:54:523180 should_fork = GetContentClient()->renderer()->ShouldFork(
3181 frame, url, request.httpMethod().utf8(), is_initial_navigation,
[email protected]b0a29f22013-05-30 23:00:093182 is_redirect, &send_referrer);
[email protected]6101c342010-12-16 22:44:373183 }
3184
3185 if (should_fork) {
[email protected]445e1042011-12-03 21:03:153186 OpenURL(
3187 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:113188 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3189 }
[email protected]3d9689372009-09-10 04:29:173190 }
3191
3192 // Detect when a page is "forking" a new tab that can be safely rendered in
3193 // its own process. This is done by sites like Gmail that try to open links
3194 // in new windows without script connections back to the original page. We
3195 // treat such cases as browser navigations (in which we will create a new
3196 // renderer for a cross-site navigation), rather than WebKit navigations.
3197 //
3198 // We use the following heuristic to decide whether to fork a new page in its
3199 // own process:
3200 // The parent page must open a new tab to about:blank, set the new tab's
3201 // window.opener to null, and then redirect the tab to a cross-site URL using
3202 // JavaScript.
[email protected]007a848b2009-10-26 15:55:463203 //
3204 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
3205 // (see below).
[email protected]3d9689372009-09-10 04:29:173206 bool is_fork =
3207 // Must start from a tab showing about:blank, which is later redirected.
[email protected]081dc522013-05-15 04:59:203208 old_url == GURL(kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173209 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523210 historyBackListCount() < 1 &&
3211 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173212 // The parent page must have set the child's window.opener to null before
3213 // redirecting to the desired URL.
3214 frame->opener() == NULL &&
3215 // Must be a top-level frame.
3216 frame->parent() == NULL &&
3217 // Must not have issued the request from this page.
3218 is_content_initiated &&
3219 // Must be targeted at the current tab.
3220 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3221 // Must be a JavaScript navigation, which appears as "other".
3222 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463223
[email protected]f92ce2b2012-03-06 18:02:593224 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:173225 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:153226 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:173227 return WebKit::WebNavigationPolicyIgnore;
3228 }
3229
3230 return default_policy;
3231}
3232
[email protected]f4f40a052013-04-19 15:28:113233WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
3234 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]89bc54c62013-04-24 01:51:333235 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0d8f04b2013-04-29 20:05:313236 return decidePolicyForNavigation(frame,
3237 frame->provisionalDataSource()->extraData(),
[email protected]89bc54c62013-04-24 01:51:333238 request, type, default_policy, is_redirect);
[email protected]f4f40a052013-04-19 15:28:113239}
3240
[email protected]cd92296c2013-07-19 06:24:503241bool RenderViewImpl::canHandleRequest(
3242 WebFrame* frame, const WebURLRequest& request) {
3243 // We allow WebKit to think that everything can be handled even though
3244 // browser-side we limit what we load.
3245 return true;
3246}
3247
3248WebURLError RenderViewImpl::cannotHandleRequestError(
3249 WebFrame* frame, const WebURLRequest& request) {
3250 NOTREACHED(); // Since we said we can handle all requests.
3251 return WebURLError();
3252}
3253
3254WebURLError RenderViewImpl::cancelledError(
3255 WebFrame* frame, const WebURLRequest& request) {
[email protected]e507045d2013-07-24 15:23:443256 NOTREACHED();
3257 return WebURLError();
[email protected]cd92296c2013-07-19 06:24:503258}
3259
3260void RenderViewImpl::unableToImplementPolicyWithError(
3261 WebFrame*, const WebURLError&) {
3262 NOTREACHED(); // Since we said we can handle all requests.
3263}
3264
[email protected]310ebd6302011-10-10 19:06:283265void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:433266 const WebKit::WebFormElement& form) {
[email protected]e507045d2013-07-24 15:23:443267 NOTREACHED();
[email protected]90eeddb2010-05-06 21:06:433268}
3269
[email protected]310ebd6302011-10-10 19:06:283270void RenderViewImpl::willSubmitForm(WebFrame* frame,
3271 const WebFormElement& form) {
[email protected]2a5b1732011-04-01 23:55:553272 FOR_EACH_OBSERVER(
3273 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:173274}
3275
[email protected]310ebd6302011-10-10 19:06:283276void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:173277 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3278 double fire_time) {
[email protected]bf692cd2012-11-14 19:10:023279 // Replace any occurrences of swappedout:// with about:blank.
[email protected]081dc522013-05-15 04:59:203280 const WebURL& blank_url = GURL(kAboutBlankURL);
[email protected]e2caa032012-11-15 23:29:183281
[email protected]eb0bff942011-04-07 22:08:383282 FOR_EACH_OBSERVER(
3283 RenderViewObserver, observers_,
[email protected]bf692cd2012-11-14 19:10:023284 WillPerformClientRedirect(frame,
3285 from == GURL(kSwappedOutURL) ? blank_url : from,
3286 to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:173287}
3288
[email protected]310ebd6302011-10-10 19:06:283289void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:383290 FOR_EACH_OBSERVER(
3291 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:173292}
3293
[email protected]310ebd6302011-10-10 19:06:283294void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:173295 WebFrame* frame, const WebURL& from) {
[email protected]bf692cd2012-11-14 19:10:023296 // Replace any occurrences of swappedout:// with about:blank.
[email protected]081dc522013-05-15 04:59:203297 const WebURL& blank_url = GURL(kAboutBlankURL);
[email protected]445e1042011-12-03 21:03:153298 if (!frame->parent()) {
3299 WebDataSource* ds = frame->provisionalDataSource();
3300 // If there's no provisional data source, it's a reference fragment
3301 // navigation.
3302 completed_client_redirect_src_ = Referrer(
[email protected]bf692cd2012-11-14 19:10:023303 from == GURL(kSwappedOutURL) ? blank_url : from,
3304 ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:043305 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:153306 }
[email protected]eb0bff942011-04-07 22:08:383307 FOR_EACH_OBSERVER(
[email protected]bf692cd2012-11-14 19:10:023308 RenderViewObserver, observers_, DidCompleteClientRedirect(
3309 frame, from == GURL(kSwappedOutURL) ? blank_url : from));
[email protected]3d9689372009-09-10 04:29:173310}
3311
[email protected]310ebd6302011-10-10 19:06:283312void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:573313 bool content_initiated = !pending_navigation_params_.get();
3314
[email protected]007733c2011-11-17 00:34:073315 DocumentState* document_state = DocumentState::FromDataSource(ds);
3316 if (!document_state) {
3317 document_state = new DocumentState;
3318 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:573319 if (!content_initiated)
3320 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:073321 }
3322
[email protected]bf70edce2012-06-20 22:32:223323 // Carry over the user agent override flag, if it exists.
3324 if (content_initiated && webview() && webview()->mainFrame() &&
3325 webview()->mainFrame()->dataSource()) {
3326 DocumentState* old_document_state =
3327 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
3328 if (old_document_state) {
[email protected]e20b88d2013-04-09 15:28:373329 InternalDocumentStateData* internal_data =
3330 InternalDocumentStateData::FromDocumentState(document_state);
3331 InternalDocumentStateData* old_internal_data =
3332 InternalDocumentStateData::FromDocumentState(old_document_state);
3333 internal_data->set_is_overriding_user_agent(
3334 old_internal_data->is_overriding_user_agent());
[email protected]bf70edce2012-06-20 22:32:223335 }
3336 }
3337
[email protected]3d9689372009-09-10 04:29:173338 // The rest of RenderView assumes that a WebDataSource will always have a
3339 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:443340 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:073341 document_state->set_navigation_state(
3342 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:443343 } else {
[email protected]45d83a12012-04-06 22:57:573344 document_state->set_navigation_state(CreateNavigationStateFromPending());
3345 pending_navigation_params_.reset();
3346 }
[email protected]8a3125a712010-08-09 18:58:513347
[email protected]007733c2011-11-17 00:34:073348 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:513349 // navigating from a page that used prefetching using a link on that
3350 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:073351 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:513352 // this value appropriately.
3353 // TODO(gavinp): catch the important case of navigation in a new
3354 // renderer process.
3355 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303356 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523357 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513358 const GURL referrer(
3359 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3360 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:073361 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:513362 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413363 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513364 WebDataSource* old_frame_ds = old_frame->dataSource();
3365 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073366 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513367 break;
3368 }
3369 }
3370 }
3371 }
3372 }
3373
[email protected]4c1b6f0b2010-02-07 16:38:183374 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523375 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513376 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183377 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073378 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183379 break;
3380 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073381 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183382 break;
3383 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073384 document_state->set_load_type(
3385 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183386 break;
3387 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073388 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183389 break;
3390 }
3391 }
[email protected]fa7b6b542009-11-03 05:02:303392
[email protected]946a0032011-03-31 18:42:283393 FOR_EACH_OBSERVER(
3394 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173395}
3396
[email protected]45d83a12012-04-06 22:57:573397void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073398 DocumentState* document_state) {
3399 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573400 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073401
[email protected]e20b88d2013-04-09 15:28:373402 InternalDocumentStateData* internal_data =
3403 InternalDocumentStateData::FromDocumentState(document_state);
3404
[email protected]45d83a12012-04-06 22:57:573405 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
3406 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3407 // We're doing a load of a page that was restored from the last session. By
3408 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3409 // can result in stale data for pages that are set to expire. We explicitly
3410 // override that by setting the policy here so that as necessary we load
3411 // from the network.
[email protected]e20b88d2013-04-09 15:28:373412 internal_data->set_cache_policy_override(
[email protected]45d83a12012-04-06 22:57:573413 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073414 }
3415
3416 if (IsReload(params))
3417 document_state->set_load_type(DocumentState::RELOAD);
[email protected]691aa2f2013-05-28 22:52:043418 else if (params.page_state.IsValid())
[email protected]007733c2011-11-17 00:34:073419 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3420 else
3421 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593422
[email protected]e20b88d2013-04-09 15:28:373423 internal_data->set_referrer_policy(params.referrer.policy);
3424 internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent);
3425 internal_data->set_must_reset_scroll_and_scale_state(
[email protected]a3a5397d2012-09-12 06:50:343426 params.navigation_type ==
3427 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373428 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573429}
[email protected]007733c2011-11-17 00:34:073430
[email protected]45d83a12012-04-06 22:57:573431NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3432 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3433 NavigationState* navigation_state = NULL;
3434
3435 // A navigation resulting from loading a javascript URL should not be treated
3436 // as a browser initiated event. Instead, we want it to look as if the page
3437 // initiated any load resulting from JS execution.
3438 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
3439 navigation_state = NavigationState::CreateBrowserInitiated(
3440 params.page_id,
3441 params.pending_history_list_offset,
[email protected]60d6cca2013-04-30 08:47:133442 params.should_clear_history_list,
[email protected]45d83a12012-04-06 22:57:573443 params.transition);
3444 navigation_state->set_transferred_request_child_id(
3445 params.transferred_request_child_id);
3446 navigation_state->set_transferred_request_request_id(
3447 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003448 navigation_state->set_allow_download(params.allow_download);
[email protected]f050fde2013-03-21 00:40:453449 navigation_state->set_extra_headers(params.extra_headers);
[email protected]45d83a12012-04-06 22:57:573450 } else {
3451 navigation_state = NavigationState::CreateContentInitiated();
3452 }
3453 return navigation_state;
[email protected]007733c2011-11-17 00:34:073454}
3455
[email protected]5b52cd2f712012-03-28 02:12:483456void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3457 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103458 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483459 bool enable_fixed_layout =
3460 command_line.HasSwitch(switches::kEnableFixedLayout);
3461
3462 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
[email protected]5b52cd2f712012-03-28 02:12:483463
[email protected]47e932da2013-03-07 00:11:243464 // If viewport tag is enabled, then the WebKit side will take care
3465 // of setting the fixed layout size and page scale limits.
3466 if (enable_viewport)
3467 return;
3468
3469 if (enable_fixed_layout) {
[email protected]5b52cd2f712012-03-28 02:12:483470 std::string str =
3471 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
3472 std::vector<std::string> tokens;
3473 base::SplitString(str, ',', &tokens);
3474 if (tokens.size() == 2) {
3475 int width, height;
3476 if (base::StringToInt(tokens[0], &width) &&
3477 base::StringToInt(tokens[1], &height))
[email protected]e1ed5a12012-08-08 19:57:443478 webview()->setFixedLayoutSize(WebSize(width, height));
[email protected]5b52cd2f712012-03-28 02:12:483479 }
3480 }
[email protected]e4cd82e2013-04-10 15:20:383481 float maxPageScaleFactor =
3482 command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ;
3483 webview()->setPageScaleFactorLimits(1, maxPageScaleFactor);
[email protected]5b52cd2f712012-03-28 02:12:483484}
3485
[email protected]310ebd6302011-10-10 19:06:283486void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173487 WebDataSource* ds = frame->provisionalDataSource();
[email protected]09c48ef52013-01-09 12:25:073488
3489 // In fast/loader/stop-provisional-loads.html, we abort the load before this
3490 // callback is invoked.
3491 if (!ds)
3492 return;
3493
[email protected]007733c2011-11-17 00:34:073494 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:173495
[email protected]890b06ca2012-12-13 21:07:363496 // We should only navigate to swappedout:// when is_swapped_out_ is true.
3497 CHECK((ds->request().url() != GURL(kSwappedOutURL)) ||
3498 is_swapped_out_) << "Heard swappedout:// when not swapped out.";
3499
[email protected]3d9689372009-09-10 04:29:173500 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:073501 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:173502 double event_time = ds->triggeringEventTime();
3503 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:073504 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:173505 }
3506
[email protected]05c8e502010-08-15 15:13:523507 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:073508 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:523509
[email protected]3d9689372009-09-10 04:29:173510 bool is_top_most = !frame->parent();
3511 if (is_top_most) {
[email protected]af15bf22013-03-08 01:18:173512 navigation_gesture_ = WebUserGestureIndicator::isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133513 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173514
[email protected]d06bcac2013-03-27 21:17:573515 // If the navigation is not triggered by a user gesture, e.g. by some ajax
3516 // callback, then inherit the submitted password form from the previous
3517 // state. This fixes the no password save issue for ajax login, tracked in
3518 // [http://crbug/43219]. Note that there are still some sites that this
3519 // fails for because they use some element other than a submit button to
3520 // trigger submission.
3521 if (navigation_gesture_ == NavigationGestureAuto) {
3522 DocumentState* old_document_state = DocumentState::FromDataSource(
3523 frame->dataSource());
3524 const content::PasswordForm* old_password_form =
3525 old_document_state->password_form_data();
3526 if (old_password_form) {
3527 document_state->set_password_form_data(
3528 make_scoped_ptr(new content::PasswordForm(*old_password_form)));
3529 }
3530 }
3531
[email protected]3d9689372009-09-10 04:29:173532 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:153533 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173534 } else if (frame->parent()->isLoading()) {
3535 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003536 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:073537 document_state->navigation_state()->set_transition_type(
[email protected]e9ff79c2012-10-19 21:31:263538 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173539 }
3540
[email protected]28685da92011-02-07 21:49:173541 FOR_EACH_OBSERVER(
3542 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3543
[email protected]3d9689372009-09-10 04:29:173544 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]d37c33e2012-10-12 13:35:133545 routing_id_, frame->identifier(),
3546 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]434bc9b2012-11-27 21:22:143547 is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173548}
3549
[email protected]400992b2012-06-14 00:03:543550void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3551 WebFrame* frame) {
3552 if (frame->parent())
3553 return;
3554 // Received a redirect on the main frame.
3555 WebDataSource* data_source = frame->provisionalDataSource();
3556 if (!data_source) {
3557 // Should only be invoked when we have a data source.
3558 NOTREACHED();
3559 return;
3560 }
3561 std::vector<GURL> redirects;
3562 GetRedirectChain(data_source, &redirects);
3563 if (redirects.size() >= 2) {
3564 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]434bc9b2012-11-27 21:22:143565 redirects[redirects.size() - 2], redirects.back()));
[email protected]400992b2012-06-14 00:03:543566 }
3567}
3568
[email protected]310ebd6302011-10-10 19:06:283569void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3570 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173571 // Notify the browser that we failed a provisional load with an error.
3572 //
3573 // Note: It is important this notification occur before DidStopLoading so the
3574 // SSL manager can react to the provisional load failure before being
3575 // notified the load stopped.
3576 //
3577 WebDataSource* ds = frame->provisionalDataSource();
3578 DCHECK(ds);
3579
3580 const WebURLRequest& failed_request = ds->request();
3581
[email protected]28685da92011-02-07 21:49:173582 FOR_EACH_OBSERVER(
3583 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3584
[email protected]3d9689372009-09-10 04:29:173585 bool show_repost_interstitial =
3586 (error.reason == net::ERR_CACHE_MISS &&
3587 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583588
3589 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3590 params.frame_id = frame->identifier();
3591 params.is_main_frame = !frame->parent();
3592 params.error_code = error.reason;
[email protected]e9ff79c2012-10-19 21:31:263593 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533594 frame,
[email protected]d7b175e2011-10-11 15:31:583595 failed_request,
3596 error,
3597 NULL,
3598 &params.error_description);
3599 params.url = error.unreachableURL;
3600 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173601 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583602 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173603
3604 // Don't display an error page if this is simply a cancelled load. Aside
3605 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3606 if (error.reason == net::ERR_ABORTED)
3607 return;
3608
[email protected]70dee7e2013-05-29 18:28:303609 if (RenderThreadImpl::current()->layout_test_mode())
[email protected]ac7f5a02013-03-16 16:14:413610 return;
3611
[email protected]3d9689372009-09-10 04:29:173612 // Make sure we never show errors in view source mode.
3613 frame->enableViewSourceMode(false);
3614
[email protected]007733c2011-11-17 00:34:073615 DocumentState* document_state = DocumentState::FromDataSource(ds);
3616 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173617
3618 // If this is a failed back/forward/reload navigation, then we need to do a
3619 // 'replace' load. This is necessary to avoid messing up session history.
3620 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3621 // as session history is concerned.
3622 //
3623 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3624 // the page id.
3625 //
3626 bool replace =
3627 navigation_state->pending_page_id() != -1 ||
[email protected]026aac22013-07-10 02:09:113628 PageTransitionCoreTypeIs(navigation_state->transition_type(),
3629 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173630
3631 // If we failed on a browser initiated request, then make sure that our error
3632 // page load is regarded as the same browser initiated request.
3633 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073634 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3635 pending_navigation_params_->page_id =
3636 navigation_state->pending_page_id();
3637 pending_navigation_params_->pending_history_list_offset =
3638 navigation_state->pending_history_list_offset();
[email protected]60d6cca2013-04-30 08:47:133639 pending_navigation_params_->should_clear_history_list =
3640 navigation_state->history_list_was_cleared();
[email protected]007733c2011-11-17 00:34:073641 pending_navigation_params_->transition =
3642 navigation_state->transition_type();
3643 pending_navigation_params_->request_time =
3644 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173645 }
3646
3647 // Provide the user with a more helpful error page?
3648 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3649 return;
3650
3651 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083652 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173653}
3654
[email protected]310ebd6302011-10-10 19:06:283655void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3656 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073657 DocumentState* document_state =
3658 DocumentState::FromDataSource(frame->dataSource());
3659 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:373660 InternalDocumentStateData* internal_data =
3661 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]3d9689372009-09-10 04:29:173662
[email protected]007733c2011-11-17 00:34:073663 if (document_state->commit_load_time().is_null())
3664 document_state->set_commit_load_time(Time::Now());
3665
[email protected]e20b88d2013-04-09 15:28:373666 if (internal_data->must_reset_scroll_and_scale_state()) {
[email protected]06c7ba022012-12-17 19:24:123667 webview()->resetScrollAndScaleState();
[email protected]e20b88d2013-04-09 15:28:373668 internal_data->set_must_reset_scroll_and_scale_state(false);
[email protected]a3a5397d2012-09-12 06:50:343669 }
[email protected]4b9c9e292013-07-18 19:13:283670 internal_data->set_use_error_page(false);
[email protected]a3a5397d2012-09-12 06:50:343671
[email protected]3d9689372009-09-10 04:29:173672 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203673 // When we perform a new navigation, we need to update the last committed
3674 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173675 UpdateSessionHistory(frame);
3676
3677 // We bump our Page ID to correspond with the new session history entry.
3678 page_id_ = next_page_id_++;
3679
[email protected]e9ff79c2012-10-19 21:31:263680 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263681 // we don't want to forget the entry that was there, and since we will
[email protected]e9ff79c2012-10-19 21:31:263682 // never come back to kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313683 // UpdateSessionHistory and update page_id_ even in this case, so that
3684 // the current entry gets a state update and so that we don't send a
3685 // state update to the wrong entry when we swap back in.
[email protected]e9ff79c2012-10-19 21:31:263686 if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313687 // Advance our offset in session history, applying the length limit.
3688 // There is now no forward history.
3689 history_list_offset_++;
[email protected]e9ff79c2012-10-19 21:31:263690 if (history_list_offset_ >= kMaxSessionHistoryEntries)
3691 history_list_offset_ = kMaxSessionHistoryEntries - 1;
[email protected]69ddf852012-02-21 23:21:313692 history_list_length_ = history_list_offset_ + 1;
3693 history_page_ids_.resize(history_list_length_, -1);
3694 history_page_ids_[history_list_offset_] = page_id_;
3695 }
[email protected]3d9689372009-09-10 04:29:173696 } else {
3697 // Inspect the navigation_state on this frame to see if the navigation
3698 // corresponds to a session history navigation... Note: |frame| may or
3699 // may not be the toplevel frame, but for the case of capturing session
3700 // history, the first committed frame suffices. We keep track of whether
3701 // we've seen this commit before so that only capture session history once
3702 // per navigation.
3703 //
3704 // Note that we need to check if the page ID changed. In the case of a
3705 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3706 // previous URL and the current page ID, which would be wrong.
3707 if (navigation_state->pending_page_id() != -1 &&
3708 navigation_state->pending_page_id() != page_id_ &&
3709 !navigation_state->request_committed()) {
3710 // This is a successful session history navigation!
3711 UpdateSessionHistory(frame);
3712 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003713
3714 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033715
3716 // If the history list is valid, our list of page IDs should be correct.
3717 DCHECK(history_list_length_ <= 0 ||
3718 history_list_offset_ < 0 ||
3719 history_list_offset_ >= history_list_length_ ||
3720 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173721 }
3722 }
3723
[email protected]28685da92011-02-07 21:49:173724 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3725 DidCommitProvisionalLoad(frame, is_new_navigation));
3726
[email protected]3d9689372009-09-10 04:29:173727 // Remember that we've already processed this request, so we don't update
3728 // the session history again. We do this regardless of whether this is
3729 // a session history navigation, because if we attempted a session history
3730 // navigation without valid HistoryItem state, WebCore will think it is a
3731 // new navigation.
3732 navigation_state->set_request_committed(true);
3733
3734 UpdateURL(frame);
3735
3736 // If this committed load was initiated by a client redirect, we're
3737 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153738 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173739
3740 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273741 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063742
3743 if (!frame->parent()) { // Only for top frames.
3744 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3745 if (render_thread_impl) { // Can be NULL in tests.
3746 render_thread_impl->histogram_customizer()->
3747 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3748 g_view_map.Get().size());
3749 }
3750 }
[email protected]3d9689372009-09-10 04:29:173751}
3752
[email protected]310ebd6302011-10-10 19:06:283753void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103754 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3755 DidClearWindowObject(frame));
3756
[email protected]e9ff79c2012-10-19 21:31:263757 if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) {
[email protected]59383c782013-04-17 16:43:273758 if (!dom_automation_controller_)
[email protected]766a7082012-02-03 23:39:153759 dom_automation_controller_.reset(new DomAutomationController());
3760 dom_automation_controller_->set_message_sender(
[email protected]e9ff79c2012-10-19 21:31:263761 static_cast<RenderView*>(this));
[email protected]766a7082012-02-03 23:39:153762 dom_automation_controller_->set_routing_id(routing_id());
3763 dom_automation_controller_->BindToJavascript(frame,
3764 "domAutomationController");
3765 }
[email protected]27c521a2013-05-29 20:44:323766
3767 if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) {
3768 if (!stats_collection_controller_.get())
3769 stats_collection_controller_.reset(new StatsCollectionController());
3770 stats_collection_controller_->set_message_sender(
3771 static_cast<RenderView*>(this));
3772 stats_collection_controller_->BindToJavascript(frame,
3773 "statsCollectionController");
3774 }
[email protected]3d9689372009-09-10 04:29:173775}
3776
[email protected]310ebd6302011-10-10 19:06:283777void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:033778 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3779 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173780}
3781
[email protected]310ebd6302011-10-10 19:06:283782void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3783 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463784 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173785
3786 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273787 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173788}
3789
[email protected]41225fe2013-03-29 05:32:023790void RenderViewImpl::didChangeIcon(WebFrame* frame,
3791 WebIconURL::Type icon_type) {
3792 if (frame->parent())
3793 return;
3794
3795 if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
3796 return;
3797
3798 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
3799 std::vector<FaviconURL> urls;
3800 for (size_t i = 0; i < icon_urls.size(); i++) {
3801 urls.push_back(FaviconURL(icon_urls[i].iconURL(),
3802 ToFaviconType(icon_urls[i].iconType())));
3803 }
3804 SendUpdateFaviconURL(urls);
[email protected]5019ef12010-04-27 17:26:583805}
3806
[email protected]310ebd6302011-10-10 19:06:283807void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173808 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073809 DocumentState* document_state = DocumentState::FromDataSource(ds);
3810 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173811
[email protected]622474d2010-11-04 09:21:083812 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173813
[email protected]28685da92011-02-07 21:49:173814 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3815 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173816
3817 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273818 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173819}
3820
[email protected]310ebd6302011-10-10 19:06:283821void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083822 if (webview()->mainFrame() == frame) {
3823 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3824 page_id_));
3825 }
[email protected]3d9689372009-09-10 04:29:173826}
3827
[email protected]310ebd6302011-10-10 19:06:283828void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313829 WebDataSource* ds = frame->dataSource();
3830 DCHECK(ds);
3831
3832
[email protected]28685da92011-02-07 21:49:173833 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313834
3835 const WebURLRequest& failed_request = ds->request();
3836 string16 error_description;
[email protected]e9ff79c2012-10-19 21:31:263837 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533838 frame,
[email protected]1a55c5be2011-11-29 11:36:313839 failed_request,
3840 error,
3841 NULL,
3842 &error_description);
3843 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3844 frame->identifier(),
3845 failed_request.url(),
3846 !frame->parent(),
3847 error.reason,
3848 error_description));
[email protected]3d9689372009-09-10 04:29:173849}
3850
[email protected]310ebd6302011-10-10 19:06:283851void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173852 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073853 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]1ac2ff12013-07-16 20:53:533854 if (document_state->finish_load_time().is_null()) {
3855 if (!frame->parent()) {
3856 TRACE_EVENT_INSTANT0("WebCore", "LoadFinished",
3857 TRACE_EVENT_SCOPE_PROCESS);
3858 }
[email protected]007733c2011-11-17 00:34:073859 document_state->set_finish_load_time(Time::Now());
[email protected]1ac2ff12013-07-16 20:53:533860 }
[email protected]4d44a1c2010-04-28 19:20:413861
[email protected]676126f72011-01-15 00:03:513862 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173863
[email protected]1a55c5be2011-11-29 11:36:313864 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3865 frame->identifier(),
3866 ds->request().url(),
3867 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173868}
3869
[email protected]310ebd6302011-10-10 19:06:283870void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173871 WebFrame* frame, bool is_new_navigation) {
3872 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073873 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173874 // update the ExtraData on the datasource so that others who read the
3875 // ExtraData will get the new NavigationState. Similarly, if we did not
3876 // initiate this navigation, then we need to take care to reset any pre-
3877 // existing navigation state to a content-initiated navigation state.
3878 // DidCreateDataSource conveniently takes care of this for us.
3879 didCreateDataSource(frame, frame->dataSource());
3880
[email protected]007733c2011-11-17 00:34:073881 DocumentState* document_state =
3882 DocumentState::FromDataSource(frame->dataSource());
3883 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093884 new_state->set_was_within_same_page(true);
3885
[email protected]3d9689372009-09-10 04:29:173886 didCommitProvisionalLoad(frame, is_new_navigation);
3887
[email protected]750fcf872011-08-03 23:10:473888 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3889 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173890}
3891
[email protected]310ebd6302011-10-10 19:06:283892void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313893 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593894}
3895
[email protected]cd92296c2013-07-19 06:24:503896void RenderViewImpl::assignIdentifierToRequest(
3897 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3898 // Ignore
3899}
3900
[email protected]310ebd6302011-10-10 19:06:283901void RenderViewImpl::willSendRequest(WebFrame* frame,
3902 unsigned identifier,
3903 WebURLRequest& request,
3904 const WebURLResponse& redirect_response) {
[email protected]e507045d2013-07-24 15:23:443905 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173906}
3907
[email protected]310ebd6302011-10-10 19:06:283908void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173909 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]e507045d2013-07-24 15:23:443910 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173911}
3912
[email protected]310ebd6302011-10-10 19:06:283913void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173914 WebFrame* frame, unsigned identifier) {
[email protected]e20b88d2013-04-09 15:28:373915 InternalDocumentStateData* internal_data =
3916 InternalDocumentStateData::FromDataSource(frame->dataSource());
3917 if (!internal_data->use_error_page())
[email protected]3d9689372009-09-10 04:29:173918 return;
3919
[email protected]7bfc153f2011-09-23 22:00:203920 // Do not show error page when DevTools is attached.
3921 if (devtools_agent_->IsAttached())
3922 return;
3923
[email protected]06333afe2011-02-24 14:55:093924 // Display error page, if appropriate.
[email protected]e20b88d2013-04-09 15:28:373925 int http_status_code = internal_data->http_status_code();
[email protected]3f853a52010-09-13 19:15:083926 if (http_status_code == 404) {
3927 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413928 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173929
[email protected]b6cb3a842011-06-24 18:28:413930 const GURL& error_page_url =
3931 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093932 if (error_page_url.is_valid()) {
3933 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473934 original_error.domain = "http";
3935 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413936 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173937
[email protected]e20b88d2013-04-09 15:28:373938 internal_data->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093939 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:423940 error_page_url, frame, frame->dataSource()->request(),
3941 original_error,
[email protected]6e806822011-11-19 01:51:083942 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3943 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093944 return;
3945 }
3946 }
[email protected]3d9689372009-09-10 04:29:173947
[email protected]e6a2ce52011-10-08 01:40:133948 std::string error_domain;
[email protected]e9ff79c2012-10-19 21:31:263949 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:133950 http_status_code, &error_domain)) {
3951 WebURLError error;
3952 error.unreachableURL = frame->document().url();
3953 error.domain = WebString::fromUTF8(error_domain);
3954 error.reason = http_status_code;
3955
3956 LoadNavigationErrorPage(
3957 frame, frame->dataSource()->request(), error, std::string(), true);
3958 }
[email protected]3d9689372009-09-10 04:29:173959}
3960
[email protected]cd92296c2013-07-19 06:24:503961void RenderViewImpl::didFailResourceLoad(
3962 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3963 // Ignore
3964}
3965
[email protected]310ebd6302011-10-10 19:06:283966void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173967 WebFrame* frame, const WebURLRequest& request,
3968 const WebURLResponse& response) {
[email protected]e507045d2013-07-24 15:23:443969 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173970}
3971
[email protected]310ebd6302011-10-10 19:06:283972void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:443973 NOTREACHED();
[email protected]e3d60e5d2009-09-25 21:08:293974}
3975
[email protected]310ebd6302011-10-10 19:06:283976void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023977 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e507045d2013-07-24 15:23:443978 NOTREACHED();
[email protected]e3d60e5d2009-09-25 21:08:293979}
3980
[email protected]310ebd6302011-10-10 19:06:283981void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:443982 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173983}
3984
[email protected]310ebd6302011-10-10 19:06:283985void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3986 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583987 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283988 int world_id) {
[email protected]e507045d2013-07-24 15:23:443989 NOTREACHED();
[email protected]a00fe692012-02-27 05:52:583990}
3991
[email protected]310ebd6302011-10-10 19:06:283992void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3993 v8::Handle<v8::Context> context,
3994 int world_id) {
[email protected]e507045d2013-07-24 15:23:443995 NOTREACHED();
[email protected]0c882b282009-10-07 17:01:283996}
3997
[email protected]310ebd6302011-10-10 19:06:283998void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073999 // We don't always want to send the change messages over IPC, only if we've
4000 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
4001 // message.
4002 if (!send_preferred_size_changes_ || !webview())
4003 return;
4004
[email protected]e76b7972013-06-06 02:58:484005 gfx::Size size = webview()->contentsPreferredMinimumSize();
[email protected]8205d742010-10-22 23:51:534006
[email protected]705243f2010-05-05 19:58:074007 if (size == preferred_size_)
4008 return;
[email protected]c27324b2009-11-19 22:44:294009
[email protected]705243f2010-05-05 19:58:074010 preferred_size_ = size;
4011 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
4012 preferred_size_));
[email protected]3d9689372009-09-10 04:29:174013}
4014
[email protected]caaf2482013-05-01 20:33:324015BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
[email protected]fc72bb12013-06-02 21:13:464016 if (!browser_plugin_manager_.get())
[email protected]fb325d122012-11-20 23:58:054017 browser_plugin_manager_ = BrowserPluginManager::Create(this);
[email protected]fc72bb12013-06-02 21:13:464018 return browser_plugin_manager_.get();
[email protected]fb325d122012-11-20 23:58:054019}
4020
[email protected]c3bdce152013-07-10 04:56:344021void RenderViewImpl::EnsureMediaStreamClient() {
[email protected]7082fb942012-05-16 23:44:594022 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:404023 return;
4024
[email protected]d9da9582013-01-31 04:59:054025#if defined(OS_ANDROID)
[email protected]ce585bf2013-03-14 16:25:164026 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC))
[email protected]d9da9582013-01-31 04:59:054027 return;
4028#endif
4029
[email protected]4fb0f202012-05-30 22:44:534030#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:514031 if (!media_stream_dispatcher_)
4032 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
4033
[email protected]c3bdce152013-07-10 04:56:344034 if (!media_stream_client_) {
4035 MediaStreamImpl* media_stream_impl = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:254036 this,
[email protected]273558fb2012-01-12 15:03:514037 media_stream_dispatcher_,
[email protected]6ee10bd2012-09-13 09:01:534038 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
[email protected]c3bdce152013-07-10 04:56:344039 media_stream_client_ = media_stream_impl;
4040 web_user_media_client_ = media_stream_impl;
[email protected]273558fb2012-01-12 15:03:514041 }
[email protected]5b87e782012-02-09 18:19:324042#endif
[email protected]273558fb2012-01-12 15:03:514043}
4044
[email protected]310ebd6302011-10-10 19:06:284045void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
4046 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:314047 if (webview()->mainFrame() != frame)
4048 return;
4049 WebView* frameView = frame->view();
4050 if (!frameView)
4051 return;
4052
4053 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
4054 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
4055
4056 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
4057 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
4058 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
4059 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
4060
4061 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
4062 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
4063 }
4064}
4065
[email protected]310ebd6302011-10-10 19:06:284066void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:314067 WebSize offset = frame->scrollOffset();
4068 WebSize minimum_offset = frame->minimumScrollOffset();
4069 WebSize maximum_offset = frame->maximumScrollOffset();
4070
4071 bool is_pinned_to_left = offset.width <= minimum_offset.width;
4072 bool is_pinned_to_right = offset.width >= maximum_offset.width;
4073
4074 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
4075 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
4076 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
4077 routing_id_, is_pinned_to_left, is_pinned_to_right));
4078
4079 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
4080 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
4081 }
[email protected]4e721742013-02-04 21:39:304082
4083 Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_));
[email protected]dd6afca2011-08-13 03:44:314084}
4085
[email protected]310ebd6302011-10-10 19:06:284086void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:494087 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:314088
4089 if (webview()->mainFrame() == frame)
4090 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:264091
4092 FOR_EACH_OBSERVER(
4093 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:314094}
4095
[email protected]a9344092d2013-02-27 00:56:454096void RenderViewImpl::willInsertBody(WebKit::WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444097 NOTREACHED();
[email protected]a9344092d2013-02-27 00:56:454098}
4099
[email protected]4d0f8182012-10-19 23:14:474100void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) {
4101 if (frame != webview()->mainFrame())
4102 return;
4103
[email protected]92d457802013-04-01 19:18:494104 InternalDocumentStateData* data =
4105 InternalDocumentStateData::FromDataSource(frame->dataSource());
4106 data->set_did_first_visually_non_empty_layout(true);
4107
4108#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:474109 // Update body background color if necessary.
4110 SkColor bg_color = webwidget_->backgroundColor();
4111
4112 // If not initialized, default to white. Note that 0 is different from black
4113 // as black still has alpha 0xFF.
4114 if (!bg_color)
4115 bg_color = SK_ColorWHITE;
4116
4117 if (bg_color != body_background_color_) {
4118 body_background_color_ = bg_color;
[email protected]e507045d2013-07-24 15:23:444119 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(
4120 GetRoutingID(), bg_color));
[email protected]4d0f8182012-10-19 23:14:474121 }
[email protected]4d0f8182012-10-19 23:14:474122#endif
[email protected]92d457802013-04-01 19:18:494123}
[email protected]4d0f8182012-10-19 23:14:474124
[email protected]55750b32012-09-21 14:05:034125void RenderViewImpl::SendFindReply(int request_id,
4126 int match_count,
4127 int ordinal,
4128 const WebRect& selection_rect,
4129 bool final_status_update) {
[email protected]55750b32012-09-21 14:05:034130 Send(new ViewHostMsg_Find_Reply(routing_id_,
4131 request_id,
4132 match_count,
4133 selection_rect,
4134 ordinal,
4135 final_status_update));
4136}
4137
[email protected]432c9a72013-02-27 01:51:034138// static
4139bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams(
4140 const string16& selection_text,
4141 size_t selection_text_offset,
4142 const ui::Range& selection_range,
4143 const ContextMenuParams& params) {
4144 string16 trimmed_selection_text;
4145 if (!selection_text.empty() && !selection_range.is_empty()) {
4146 const int start = selection_range.GetMin() - selection_text_offset;
4147 const size_t length = selection_range.length();
4148 if (start >= 0 && start + length <= selection_text.length()) {
4149 TrimWhitespace(selection_text.substr(start, length), TRIM_ALL,
4150 &trimmed_selection_text);
4151 }
4152 }
4153 string16 trimmed_params_text;
4154 TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text);
4155 return trimmed_params_text != trimmed_selection_text;
4156}
4157
[email protected]55750b32012-09-21 14:05:034158void RenderViewImpl::reportFindInPageMatchCount(int request_id,
4159 int count,
[email protected]310ebd6302011-10-10 19:06:284160 bool final_update) {
[email protected]e507045d2013-07-24 15:23:444161 NOTREACHED();
[email protected]8922e1f2009-10-03 05:01:264162}
4163
[email protected]310ebd6302011-10-10 19:06:284164void RenderViewImpl::reportFindInPageSelection(int request_id,
4165 int active_match_ordinal,
4166 const WebRect& selection_rect) {
[email protected]e507045d2013-07-24 15:23:444167 NOTREACHED();
[email protected]8922e1f2009-10-03 05:01:264168}
4169
[email protected]310ebd6302011-10-10 19:06:284170void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:224171 WebFrame* frame,
[email protected]18cdb0e2013-03-19 16:37:534172 WebKit::WebFileSystemType type,
[email protected]2b06a992010-08-21 05:48:224173 long long size,
[email protected]d275d7a2010-11-03 01:34:494174 bool create,
[email protected]2b06a992010-08-21 05:48:224175 WebFileSystemCallbacks* callbacks) {
[email protected]e507045d2013-07-24 15:23:444176 NOTREACHED();
[email protected]2b06a992010-08-21 05:48:224177}
4178
[email protected]d5e08552012-08-02 21:43:404179void RenderViewImpl::deleteFileSystem(
4180 WebFrame* frame,
[email protected]18cdb0e2013-03-19 16:37:534181 WebKit::WebFileSystemType type ,
[email protected]d5e08552012-08-02 21:43:404182 WebFileSystemCallbacks* callbacks) {
[email protected]e507045d2013-07-24 15:23:444183 NOTREACHED();
[email protected]d5e08552012-08-02 21:43:404184}
4185
[email protected]310ebd6302011-10-10 19:06:284186void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:404187 WebFrame* frame,
4188 WebStorageQuotaType type,
4189 WebStorageQuotaCallbacks* callbacks) {
[email protected]e507045d2013-07-24 15:23:444190 NOTREACHED();
[email protected]10e5cf12011-04-13 04:10:404191}
4192
[email protected]310ebd6302011-10-10 19:06:284193void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404194 WebFrame* frame,
4195 WebStorageQuotaType type,
4196 unsigned long long requested_size,
4197 WebStorageQuotaCallbacks* callbacks) {
[email protected]e507045d2013-07-24 15:23:444198 NOTREACHED();
[email protected]10e5cf12011-04-13 04:10:404199}
4200
[email protected]f546640b2012-05-15 00:03:494201bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]0720b532012-08-28 19:23:374202 WebKit::WebFrame* sourceFrame,
4203 WebKit::WebFrame* targetFrame,
[email protected]f546640b2012-05-15 00:03:494204 WebKit::WebSecurityOrigin target_origin,
4205 WebKit::WebDOMMessageEvent event) {
4206 if (!is_swapped_out_)
4207 return false;
4208
4209 ViewMsg_PostMessage_Params params;
4210 params.data = event.data().toString();
4211 params.source_origin = event.origin();
4212 if (!target_origin.isNull())
4213 params.target_origin = target_origin.toString();
4214
4215 // Include the routing ID for the source frame, which the browser process
4216 // will translate into the routing ID for the equivalent frame in the target
4217 // process.
[email protected]f546640b2012-05-15 00:03:494218 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]0720b532012-08-28 19:23:374219 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
[email protected]f546640b2012-05-15 00:03:494220 if (source_view)
4221 params.source_routing_id = source_view->routing_id();
4222
4223 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4224 return true;
4225}
4226
[email protected]5fa3a062012-03-21 15:39:344227void RenderViewImpl::willOpenSocketStream(
4228 WebSocketStreamHandle* handle) {
[email protected]e507045d2013-07-24 15:23:444229 NOTREACHED();
[email protected]5fa3a062012-03-21 15:39:344230}
4231
[email protected]ccee4862012-10-03 18:34:264232void RenderViewImpl::willStartUsingPeerConnectionHandler(
4233 WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) {
[email protected]e507045d2013-07-24 15:23:444234 NOTREACHED();
[email protected]ccee4862012-10-03 18:34:264235}
4236
[email protected]9982c802013-06-12 15:22:064237WebKit::WebString RenderViewImpl::acceptLanguages() {
4238 return WebString::fromUTF8(renderer_preferences_.accept_languages);
4239}
4240
[email protected]bf70edce2012-06-20 22:32:224241WebKit::WebString RenderViewImpl::userAgentOverride(
4242 WebKit::WebFrame* frame,
4243 const WebKit::WebURL& url) {
[email protected]e507045d2013-07-24 15:23:444244 NOTREACHED();
[email protected]e20b88d2013-04-09 15:28:374245 return WebKit::WebString();
[email protected]bf70edce2012-06-20 22:32:224246}
4247
[email protected]a3e217f2013-04-12 22:38:344248WebString RenderViewImpl::doNotTrackValue(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444249 NOTREACHED();
4250 return WebKit::WebString();
[email protected]a3e217f2013-04-12 22:38:344251}
4252
[email protected]818915cd2012-11-20 13:14:114253bool RenderViewImpl::allowWebGL(WebFrame* frame, bool default_value) {
[email protected]e507045d2013-07-24 15:23:444254 NOTREACHED();
4255 return false;
[email protected]818915cd2012-11-20 13:14:114256}
4257
4258void RenderViewImpl::didLoseWebGLContext(
4259 WebKit::WebFrame* frame,
4260 int arb_robustness_status_code) {
[email protected]e507045d2013-07-24 15:23:444261 NOTREACHED();
[email protected]818915cd2012-11-20 13:14:114262}
4263
[email protected]18d5be92011-07-25 18:00:194264// WebKit::WebPageSerializerClient implementation ------------------------------
4265
[email protected]310ebd6302011-10-10 19:06:284266void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194267 const WebURL& frame_url,
4268 const WebCString& data,
4269 WebPageSerializerClient::PageSerializationStatus status) {
4270 Send(new ViewHostMsg_SendSerializedHtmlData(
4271 routing_id(),
4272 frame_url,
4273 data.data(),
4274 static_cast<int32>(status)));
4275}
4276
[email protected]e9ff79c2012-10-19 21:31:264277// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:314278
[email protected]310ebd6302011-10-10 19:06:284279bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314280 return RenderWidget::Send(message);
4281}
4282
[email protected]82114f52012-03-20 22:53:414283int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314284 return routing_id_;
4285}
4286
[email protected]82114f52012-03-20 22:53:414287int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314288 return page_id_;
4289}
4290
[email protected]82114f52012-03-20 22:53:414291gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314292 return size();
4293}
4294
[email protected]82114f52012-03-20 22:53:414295WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314296 return webkit_preferences_;
4297}
4298
[email protected]324825d2012-11-30 12:37:154299void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
4300 OnUpdateWebPreferences(preferences);
4301}
4302
[email protected]82114f52012-03-20 22:53:414303WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314304 return webview();
4305}
4306
[email protected]82114f52012-03-20 22:53:414307WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314308 if (!webview())
4309 return WebNode();
4310 WebFrame* focused_frame = webview()->focusedFrame();
4311 if (focused_frame) {
4312 WebDocument doc = focused_frame->document();
4313 if (!doc.isNull())
4314 return doc.focusedNode();
4315 }
4316
4317 return WebNode();
4318}
4319
[email protected]82114f52012-03-20 22:53:414320WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314321 return context_menu_node_;
4322}
4323
[email protected]2a84f9d2012-06-05 21:50:434324bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4325 if (node.isNull())
4326 return false;
4327
4328 if (node.isContentEditable())
4329 return true;
4330
4331 if (node.isElementNode()) {
4332 const WebElement& element = node.toConst<WebElement>();
4333 if (element.isTextFormControlElement())
4334 return true;
4335
4336 // Also return true if it has an ARIA role of 'textbox'.
4337 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4338 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4339 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4340 return true;
4341 break;
4342 }
[email protected]a2ef54c2011-10-10 16:20:314343 }
4344 }
[email protected]2a84f9d2012-06-05 21:50:434345
4346 return false;
[email protected]a2ef54c2011-10-10 16:20:314347}
4348
[email protected]310ebd6302011-10-10 19:06:284349WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:314350 WebKit::WebFrame* frame,
[email protected]d7bd3e52013-07-21 04:29:204351 const WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:414352 const WebKit::WebPluginParams& params) {
[email protected]6d17f6392012-12-05 05:24:544353 WebKit::WebPlugin* pepper_webplugin =
4354 pepper_helper_->CreatePepperWebPlugin(info, params);
4355
4356 if (pepper_webplugin)
4357 return pepper_webplugin;
[email protected]a2ef54c2011-10-10 16:20:314358
[email protected]29e2fb42013-07-19 01:13:474359 return new WebPluginImpl(frame, params, info.path, AsWeakPtr());
[email protected]a2ef54c2011-10-10 16:20:314360}
4361
[email protected]310ebd6302011-10-10 19:06:284362void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4363 const string16& jscript,
4364 int id,
4365 bool notify_result) {
[email protected]3b2a3a82013-02-20 15:29:314366 v8::HandleScope handle_scope;
[email protected]a2ef54c2011-10-10 16:20:314367 v8::Handle<v8::Value> result;
4368 WebFrame* web_frame = GetChildFrame(frame_xpath);
4369 if (web_frame)
4370 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4371 if (notify_result) {
[email protected]0cd50aa2013-02-12 22:28:014372 base::ListValue list;
[email protected]a2ef54c2011-10-10 16:20:314373 if (!result.IsEmpty() && web_frame) {
[email protected]a2ef54c2011-10-10 16:20:314374 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4375 v8::Context::Scope context_scope(context);
4376 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514377 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244378 converter.SetRegExpAllowed(true);
4379 base::Value* result_value = converter.FromV8Value(result, context);
[email protected]0cd50aa2013-02-12 22:28:014380 list.Set(0, result_value ? result_value : base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314381 } else {
[email protected]0cd50aa2013-02-12 22:28:014382 list.Set(0, base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314383 }
4384 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4385 }
4386}
4387
[email protected]310ebd6302011-10-10 19:06:284388bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314389 return (!send_preferred_size_changes_ ||
4390 (disable_scrollbars_size_limit_.width() <= width ||
4391 disable_scrollbars_size_limit_.height() <= height));
4392}
4393
[email protected]82114f52012-03-20 22:53:414394int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314395 return enabled_bindings_;
4396}
4397
[email protected]82114f52012-03-20 22:53:414398bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314399 return send_content_state_immediately_;
4400}
4401
[email protected]82114f52012-03-20 22:53:414402float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314403 return filtered_time_per_frame();
4404}
4405
[email protected]e9ff79c2012-10-19 21:31:264406int RenderViewImpl::ShowContextMenu(ContextMenuClient* client,
4407 const ContextMenuParams& params) {
[email protected]860ee642012-10-13 03:46:254408 DCHECK(client); // A null client means "internal" when we issue callbacks.
[email protected]e9ff79c2012-10-19 21:31:264409 ContextMenuParams our_params(params);
[email protected]860ee642012-10-13 03:46:254410 our_params.custom_context.request_id = pending_context_menus_.Add(client);
4411 Send(new ViewHostMsg_ContextMenu(routing_id_, our_params));
4412 return our_params.custom_context.request_id;
[email protected]a2ef54c2011-10-10 16:20:314413}
4414
[email protected]e0fd0eb2012-10-17 21:11:464415void RenderViewImpl::CancelContextMenu(int request_id) {
4416 DCHECK(pending_context_menus_.Lookup(request_id));
4417 pending_context_menus_.Remove(request_id);
4418}
4419
[email protected]82114f52012-03-20 22:53:414420WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314421 return visibilityState();
4422}
4423
[email protected]310ebd6302011-10-10 19:06:284424void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
4425 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314426 return runModalAlertDialog(frame, message);
4427}
4428
[email protected]310ebd6302011-10-10 19:06:284429void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:314430 WebKit::WebFrame* frame,
4431 const WebKit::WebURLRequest& request,
4432 WebKit::WebNavigationPolicy policy) {
[email protected]e507045d2013-07-24 15:23:444433 main_render_frame_->loadURLExternally(frame, request, policy);
[email protected]a2ef54c2011-10-10 16:20:314434}
4435
[email protected]3c71576ce2013-07-23 02:00:014436void RenderViewImpl::DidStartLoading() {
4437 didStartLoading();
4438}
4439
4440void RenderViewImpl::DidStopLoading() {
4441 didStopLoading();
4442}
4443
[email protected]5d65fe92012-06-02 00:48:554444void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074445 Send(new ViewHostMsg_MediaNotification(routing_id_,
4446 reinterpret_cast<int64>(player),
4447 player->hasVideo(),
4448 player->hasAudio(),
4449 true));
4450}
4451
[email protected]5d65fe92012-06-02 00:48:554452void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074453 Send(new ViewHostMsg_MediaNotification(routing_id_,
4454 reinterpret_cast<int64>(player),
4455 player->hasVideo(),
4456 player->hasAudio(),
4457 false));
4458}
4459
[email protected]5d65fe92012-06-02 00:48:554460void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074461 DidPause(player);
4462}
4463
[email protected]310ebd6302011-10-10 19:06:284464void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294465 if (!webview())
4466 return;
4467
[email protected]26aa0482009-09-30 16:55:274468 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054469 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294470}
4471
[email protected]310ebd6302011-10-10 19:06:284472void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364473 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004474 if (!frame)
4475 return;
[email protected]b781ff282011-08-20 06:19:364476
[email protected]e99ef6f2011-10-16 01:13:004477 string16 text;
4478 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:524479 ui::Range range;
[email protected]6d17f6392012-12-05 05:24:544480 if (pepper_helper_->IsPluginFocused()) {
4481 pepper_helper_->GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414482 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524483 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:004484 } else {
[email protected]3c8c74c2012-03-15 07:34:524485 size_t location, length;
4486 if (!webview()->caretOrSelectionRange(&location, &length))
4487 return;
4488
4489 range = ui::Range(location, location + length);
4490
[email protected]61232142013-06-20 16:43:324491 if (webview()->textInputInfo().type != WebKit::WebTextInputTypeNone) {
[email protected]3c8c74c2012-03-15 07:34:524492 // If current focused element is editable, we will send 100 more chars
4493 // before and after selection. It is for input method surrounding text
4494 // feature.
4495 if (location > kExtraCharsBeforeAndAfterSelection)
4496 offset = location - kExtraCharsBeforeAndAfterSelection;
4497 else
4498 offset = 0;
4499 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4500 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4501 if (!webrange.isNull())
4502 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4503 } else {
4504 offset = location;
4505 text = frame->selectionAsText();
4506 // http://crbug.com/101435
4507 // In some case, frame->selectionAsText() returned text's length is not
4508 // equal to the length returned from webview()->caretOrSelectionRange().
4509 // So we have to set the range according to text.length().
4510 range.set_end(range.start() + text.length());
4511 }
[email protected]b781ff282011-08-20 06:19:364512 }
4513
[email protected]b781ff282011-08-20 06:19:364514 // Sometimes we get repeated didChangeSelection calls from webkit when
4515 // the selection hasn't actually changed. We don't want to report these
4516 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004517 if (selection_text_offset_ != offset ||
4518 selection_range_ != range ||
4519 selection_text_ != text) {
4520 selection_text_ = text;
4521 selection_text_offset_ = offset;
4522 selection_range_ = range;
4523 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4524 }
[email protected]47822262013-04-23 17:22:364525 UpdateSelectionBounds();
[email protected]b781ff282011-08-20 06:19:364526}
4527
[email protected]310ebd6302011-10-10 19:06:284528GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4529 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554530 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294531 // If the URL that failed was secure, then the embedding web page was not
4532 // expecting a network attacker to be able to manipulate its contents. As
4533 // we fetch alternate error pages over HTTP, we would be allowing a network
4534 // attacker to manipulate the contents of the response if we tried to use
4535 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154536 return GURL();
initial.commit09911bf2008-07-26 23:55:294537 }
4538
4539 // Grab the base URL from the browser process.
4540 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154541 return GURL();
initial.commit09911bf2008-07-26 23:55:294542
4543 // Strip query params from the failed URL.
4544 GURL::Replacements remove_params;
4545 remove_params.ClearUsername();
4546 remove_params.ClearPassword();
4547 remove_params.ClearQuery();
4548 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554549 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504550 std::string spec_to_send = url_to_send.spec();
4551 // Notify link doctor of the url truncation by sending of "?" at the end.
4552 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414553 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294554
4555 // Construct the query params to send to link doctor.
4556 std::string params(alternate_error_page_url_.query());
4557 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024558 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294559 params.append("&sourceid=chrome");
4560 params.append("&error=");
4561 switch (error_type) {
4562 case DNS_ERROR:
4563 params.append("dnserror");
4564 break;
4565
4566 case HTTP_404:
4567 params.append("http404");
4568 break;
4569
[email protected]5df266ac2008-10-15 19:50:134570 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334571 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134572 break;
4573
initial.commit09911bf2008-07-26 23:55:294574 default:
4575 NOTREACHED() << "unknown ErrorPageType";
4576 }
4577
4578 // OK, build the final url to return.
4579 GURL::Replacements link_doctor_params;
4580 link_doctor_params.SetQueryStr(params);
4581 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4582 return url;
4583}
4584
[email protected]69ddf852012-02-21 23:21:314585GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4586 WebDataSource* ds = frame->dataSource();
4587 if (ds->hasUnreachableURL())
4588 return ds->unreachableURL();
4589
4590 const WebURLRequest& request = ds->request();
4591 return request.url();
4592}
4593
[email protected]310ebd6302011-10-10 19:06:284594WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014595 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494596}
4597
[email protected]55750b32012-09-21 14:05:034598void RenderViewImpl::OnFind(int request_id,
4599 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284600 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274601 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494602
[email protected]872542532011-06-23 00:43:164603 // Check if the plugin still exists in the document.
4604 if (main_frame->document().isPluginDocument() &&
4605 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494606 if (options.findNext) {
4607 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014608 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494609 } else {
[email protected]55750b32012-09-21 14:05:034610 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234611 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114612 // Send "no results".
[email protected]55750b32012-09-21 14:05:034613 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494614 }
4615 }
4616 return;
4617 }
4618
[email protected]b4bb2502009-10-01 22:35:274619 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274620 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294621 WebFrame* search_frame = focused_frame; // start searching focused frame.
4622
4623 bool multi_frame = (frame_after_main != main_frame);
4624
4625 // If we have multiple frames, we don't want to wrap the search within the
4626 // frame, so we check here if we only have main_frame in the chain.
4627 bool wrap_within_frame = !multi_frame;
4628
[email protected]b3f2b912009-04-09 16:18:524629 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294630 bool result = false;
4631
[email protected]7830da3e2009-11-06 16:27:264632 // If something is selected when we start searching it means we cannot just
4633 // increment the current match ordinal; we need to re-generate it.
4634 WebRange current_selection = focused_frame->selectionRange();
4635
initial.commit09911bf2008-07-26 23:55:294636 do {
[email protected]dd7daa82009-08-10 05:46:454637 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594638 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294639
4640 if (!result) {
4641 // don't leave text selected as you move to the next frame.
[email protected]6dd17a8a2013-05-01 05:50:104642 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
4643 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:294644
4645 // Find the next frame, but skip the invisible ones.
4646 do {
4647 // What is the next frame to search? (we might be going backwards). Note
4648 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594649 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274650 search_frame->traverseNext(true) :
4651 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454652 } while (!search_frame->hasVisibleContent() &&
4653 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294654
[email protected]884db412008-11-24 23:46:504655 // Make sure selection doesn't affect the search operation in new frame.
[email protected]6dd17a8a2013-05-01 05:50:104656 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
4657 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:294658
4659 // If we have multiple frames and we have wrapped back around to the
4660 // focused frame, we need to search it once more allowing wrap within
4661 // the frame, otherwise it will report 'no match' if the focused frame has
4662 // reported matches, but no frames after the focused_frame contain a
4663 // match for the search word(s).
4664 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454665 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594666 request_id, search_text, options, true, // Force wrapping.
4667 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294668 }
4669 }
4670
[email protected]26aa0482009-09-30 16:55:274671 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294672 } while (!result && search_frame != focused_frame);
4673
[email protected]7830da3e2009-11-06 16:27:264674 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294675 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454676 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294677 } else {
4678 // If nothing is found, set result to "0 of 0", otherwise, set it to
4679 // "-1 of 1" to indicate that we found at least one item, but we don't know
4680 // yet what is active.
4681 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4682 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294683
[email protected]4f3dc372009-02-24 00:10:294684 // If we find no matches then this will be our last status update.
4685 // Otherwise the scoping effort will send more results.
4686 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294687
[email protected]55750b32012-09-21 14:05:034688 SendFindReply(request_id, match_count, ordinal, selection_rect,
4689 final_status_update);
initial.commit09911bf2008-07-26 23:55:294690
initial.commit09911bf2008-07-26 23:55:294691 // Scoping effort begins, starting with the mainframe.
4692 search_frame = main_frame;
4693
[email protected]dd7daa82009-08-10 05:46:454694 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294695
4696 do {
4697 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454698 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294699
4700 // We don't start another scoping effort unless at least one match has
4701 // been found.
4702 if (result) {
4703 // Start new scoping request. If the scoping function determines that it
4704 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454705 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594706 search_text,
4707 options,
initial.commit09911bf2008-07-26 23:55:294708 true); // reset the tickmarks
4709 }
4710
4711 // Iterate to the next frame. The frame will not necessarily scope, for
4712 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274713 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294714 } while (search_frame != main_frame);
4715 }
4716}
4717
[email protected]e9ff79c2012-10-19 21:31:264718void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494719 WebView* view = webview();
4720 if (!view)
4721 return;
4722
4723 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164724 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014725 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494726 return;
4727 }
4728
[email protected]e9ff79c2012-10-19 21:31:264729 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]6dd17a8a2013-05-01 05:50:104730 if (clear_selection) {
4731 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
4732 GetFocusedNode());
4733 }
[email protected]24a7f3c2010-03-25 08:26:494734
4735 WebFrame* frame = view->mainFrame();
4736 while (frame) {
4737 frame->stopFinding(clear_selection);
4738 frame = frame->traverseNext(false);
4739 }
4740
[email protected]e9ff79c2012-10-19 21:31:264741 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494742 WebFrame* focused_frame = view->focusedFrame();
4743 if (focused_frame) {
4744 WebDocument doc = focused_frame->document();
4745 if (!doc.isNull()) {
4746 WebNode node = doc.focusedNode();
4747 if (!node.isNull())
4748 node.simulateClick();
4749 }
4750 }
4751 }
4752}
4753
[email protected]59363fc92012-09-05 03:46:314754#if defined(OS_ANDROID)
4755void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4756 float x, float y) {
4757 if (!webview())
4758 return;
4759
4760 WebFrame* main_frame = webview()->mainFrame();
4761 WebRect selection_rect;
4762 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4763 &selection_rect);
4764 if (ordinal == -1) {
4765 // Something went wrong, so send a no-op reply (force the main_frame to
4766 // report the current match count) in case the host is waiting for a
4767 // response due to rate-limiting).
4768 main_frame->increaseMatchCount(0, request_id);
4769 return;
4770 }
4771
[email protected]55750b32012-09-21 14:05:034772 SendFindReply(request_id,
4773 -1 /* number_of_matches */,
4774 ordinal,
4775 selection_rect,
4776 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:314777}
4778
4779void RenderViewImpl::OnFindMatchRects(int current_version) {
4780 if (!webview())
4781 return;
4782
4783 WebFrame* main_frame = webview()->mainFrame();
4784 std::vector<gfx::RectF> match_rects;
4785
4786 int rects_version = main_frame->findMatchMarkersVersion();
4787 if (current_version != rects_version) {
4788 WebVector<WebFloatRect> web_match_rects;
4789 main_frame->findMatchRects(web_match_rects);
4790 match_rects.reserve(web_match_rects.size());
4791 for (size_t i = 0; i < web_match_rects.size(); ++i)
4792 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4793 }
4794
4795 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4796 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4797 rects_version,
4798 match_rects,
4799 active_rect));
4800}
4801#endif
4802
[email protected]e9ff79c2012-10-19 21:31:264803void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514804 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4805 return;
4806
[email protected]258d31122010-05-09 10:59:414807 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104808
[email protected]b75b8292010-10-01 07:28:254809 double old_zoom_level = webview()->zoomLevel();
4810 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:264811 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254812 zoom_level = 0;
4813 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4814 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484815 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254816 } else {
4817 // Either the user hit the zoom factor limit and thus the zoom level is now
4818 // not a whole number, or a plugin changed it to a custom value. We want
4819 // to go to the next whole number so that the user can always get back to
4820 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484821 if ((old_zoom_level > 1 && zoom > 0) ||
4822 (old_zoom_level < 1 && zoom < 0)) {
4823 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254824 } else {
4825 // We're going towards 100%, so first go to the next whole number.
4826 zoom_level = static_cast<int>(old_zoom_level);
4827 }
4828 }
[email protected]b75b8292010-10-01 07:28:254829 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414830 zoomLevelChanged();
4831}
4832
[email protected]e9ff79c2012-10-19 21:31:264833void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x,
4834 int zoom_center_y) {
[email protected]47578fa02011-11-02 19:34:414835 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4836 kScalingIncrementForGesture);
4837}
4838
[email protected]e9ff79c2012-10-19 21:31:264839void RenderViewImpl::ZoomFactorHelper(PageZoom zoom,
[email protected]47578fa02011-11-02 19:34:414840 int zoom_center_x,
4841 int zoom_center_y,
4842 float scaling_increment) {
4843 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4844 return;
4845
[email protected]c514d6372011-08-16 22:54:444846 double old_page_scale_factor = webview()->pageScaleFactor();
4847 double page_scale_factor;
[email protected]e9ff79c2012-10-19 21:31:264848 if (zoom == PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444849 page_scale_factor = 1.0;
4850 } else {
4851 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414852 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444853 }
[email protected]47578fa02011-11-02 19:34:414854 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094855 webview()->setPageScaleFactor(page_scale_factor,
4856 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414857 }
[email protected]40bd6582009-12-04 23:49:514858}
4859
[email protected]310ebd6302011-10-10 19:06:284860void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174861 webview()->hidePopups();
4862 webview()->setZoomLevel(false, zoom_level);
4863 zoomLevelChanged();
4864}
4865
[email protected]310ebd6302011-10-10 19:06:284866void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4867 double zoom_level) {
[email protected]cbe55d22013-02-14 17:04:334868#if !defined(OS_ANDROID)
4869 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
4870 // for legacy WebView text scaling emulation. Thus, the code that resets
4871 // the zoom level from this map will be effectively resetting text zoom level.
[email protected]9d797f32010-04-23 07:17:544872 host_zoom_levels_[url] = zoom_level;
[email protected]cbe55d22013-02-14 17:04:334873#endif
initial.commit09911bf2008-07-26 23:55:294874}
4875
[email protected]310ebd6302011-10-10 19:06:284876void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274877 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294878}
4879
[email protected]310ebd6302011-10-10 19:06:284880void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274881 WebString no_encoding;
4882 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184883}
4884
[email protected]310ebd6302011-10-10 19:06:284885WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454886 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274887 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454888
4889 // xpath string can represent a frame deep down the tree (across multiple
4890 // frame DOMs).
4891 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4892 // should break into 2 xpaths
4893 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414894 std::vector<string16> xpaths;
4895 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454896
[email protected]26aa0482009-09-30 16:55:274897 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414898 for (std::vector<string16>::const_iterator i = xpaths.begin();
4899 frame && i != xpaths.end(); ++i) {
4900 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294901 }
4902
[email protected]dd7daa82009-08-10 05:46:454903 return frame;
initial.commit09911bf2008-07-26 23:55:294904}
4905
[email protected]310ebd6302011-10-10 19:06:284906void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4907 const string16& jscript,
4908 int id,
4909 bool notify_result) {
[email protected]c76faea2013-03-26 07:42:424910 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest",
4911 TRACE_EVENT_SCOPE_THREAD);
[email protected]882b7b22010-10-05 03:34:534912 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294913}
4914
[email protected]f546640b2012-05-15 00:03:494915void RenderViewImpl::OnPostMessageEvent(
4916 const ViewMsg_PostMessage_Params& params) {
[email protected]bf4a2312013-04-23 00:32:114917 // TODO(nasko): Support sending to subframes.
[email protected]e12dbe6f2012-10-04 22:11:194918 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:494919
4920 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:494921 WebFrame* source_frame = NULL;
4922 if (params.source_routing_id != MSG_ROUTING_NONE) {
4923 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
4924 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:194925 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:494926 }
4927
4928 // Create an event with the message. The final parameter to initMessageEvent
4929 // is the last event ID, which is not used with postMessage.
4930 WebDOMEvent event = frame->document().createEvent("MessageEvent");
4931 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
4932 msg_event.initMessageEvent("message",
4933 // |canBubble| and |cancellable| are always false
4934 false, false,
4935 WebSerializedScriptValue::fromString(params.data),
4936 params.source_origin, source_frame, "");
4937
4938 // We must pass in the target_origin to do the security check on this side,
4939 // since it may have changed since the original postMessage call was made.
4940 WebSecurityOrigin target_origin;
4941 if (!params.target_origin.empty()) {
4942 target_origin =
4943 WebSecurityOrigin::createFromString(WebString(params.target_origin));
4944 }
4945 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
4946}
4947
[email protected]310ebd6302011-10-10 19:06:284948void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4949 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414950 WebFrame* frame = GetChildFrame(frame_xpath);
4951 if (!frame)
[email protected]216813952011-05-19 22:21:264952 return;
[email protected]ae461542009-06-19 19:03:414953
[email protected]01cf589c2011-07-28 18:04:034954 frame->document().insertUserStyleSheet(
4955 WebString::fromUTF8(css),
4956 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484957}
4958
[email protected]310ebd6302011-10-10 19:06:284959void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]940ed1d2012-11-27 21:03:214960 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
4961 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
[email protected]dcc72db2013-01-02 00:44:184962 RenderThread::Get()->RegisterExtension(WebUIExtension::Get());
[email protected]940ed1d2012-11-27 21:03:214963 new WebUIExtensionData(this);
4964 }
4965
[email protected]81e63782009-02-27 19:35:094966 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:044967
4968 // Keep track of the total bindings accumulated in this process.
4969 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:294970}
4971
[email protected]dc293a72013-07-01 11:11:224972void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data,
[email protected]310ebd6302011-10-10 19:06:284973 const gfx::Point& client_point,
4974 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:424975 WebDragOperationsMask ops,
4976 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:554977 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]dc293a72013-07-01 11:11:224978 DropDataToWebDragData(drop_data),
[email protected]59f4f2fa2011-03-23 01:00:554979 client_point,
4980 screen_point,
[email protected]1f2230b2012-05-17 23:43:424981 ops,
4982 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:554983
4984 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4985}
4986
[email protected]310ebd6302011-10-10 19:06:284987void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4988 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:424989 WebDragOperationsMask ops,
4990 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:554991 WebDragOperation operation = webview()->dragTargetDragOver(
4992 client_point,
4993 screen_point,
[email protected]1f2230b2012-05-17 23:43:424994 ops,
4995 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:554996
4997 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4998}
4999
[email protected]310ebd6302011-10-10 19:06:285000void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555001 webview()->dragTargetDragLeave();
5002}
5003
[email protected]310ebd6302011-10-10 19:06:285004void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425005 const gfx::Point& screen_point,
5006 int key_modifiers) {
5007 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575008
5009 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555010}
5011
[email protected]310ebd6302011-10-10 19:06:285012void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5013 const gfx::Point& screen_point,
5014 bool ended,
5015 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035016 if (ended) {
[email protected]26aa0482009-09-30 16:55:275017 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205018 } else {
5019 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035020 }
initial.commit09911bf2008-07-26 23:55:295021}
5022
[email protected]310ebd6302011-10-10 19:06:285023void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275024 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295025}
5026
[email protected]310ebd6302011-10-10 19:06:285027void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595028 webkit_preferences_ = prefs;
[email protected]3184f90b2013-05-01 18:17:535029 webkit_glue::ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:295030}
5031
[email protected]38761452012-10-18 16:31:595032void RenderViewImpl::OnUpdateTimezone() {
5033 if (webview())
5034 NotifyTimezoneChange(webview()->mainFrame());
5035}
5036
[email protected]310ebd6302011-10-10 19:06:285037void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295038 alternate_error_page_url_ = url;
5039}
5040
[email protected]310ebd6302011-10-10 19:06:285041void RenderViewImpl::OnCustomContextMenuAction(
[email protected]e9ff79c2012-10-19 21:31:265042 const CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085043 unsigned action) {
[email protected]860ee642012-10-13 03:46:255044 if (custom_context.request_id) {
5045 // External context menu request, look in our map.
[email protected]e9ff79c2012-10-19 21:31:265046 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:255047 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:465048 if (client)
5049 client->OnMenuAction(custom_context.request_id, action);
[email protected]860ee642012-10-13 03:46:255050 } else {
5051 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:085052 webview()->performCustomContextMenuAction(action);
[email protected]860ee642012-10-13 03:46:255053 }
[email protected]a0c7153e2009-12-09 14:36:335054}
5055
[email protected]310ebd6302011-10-10 19:06:285056void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515057 int id,
[email protected]c42de732013-02-16 06:26:315058 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:515059 if (!enumeration_completions_[id])
5060 return;
5061
5062 WebVector<WebString> ws_file_names(paths.size());
5063 for (size_t i = 0; i < paths.size(); ++i)
[email protected]728c2ee2013-06-25 04:01:075064 ws_file_names[i] = paths[i].AsUTF16Unsafe();
[email protected]600ea402011-04-12 00:01:515065
5066 enumeration_completions_[id]->didChooseFile(ws_file_names);
5067 enumeration_completions_.erase(id);
5068}
5069
[email protected]fb11b6a42012-03-14 07:25:125070void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395071 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365072 // This could happen if we navigated to a different page before the user
5073 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475074 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365075 return;
5076
[email protected]b5188522012-03-15 00:18:045077 // Convert Chrome's SelectedFileInfo list to WebKit's.
5078 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5079 files.size());
5080 for (size_t i = 0; i < files.size(); ++i) {
5081 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]728c2ee2013-06-25 04:01:075082 selected_file.path = files[i].local_path.AsUTF16Unsafe();
5083 selected_file.displayName =
5084 base::FilePath(files[i].display_name).AsUTF16Unsafe();
[email protected]b5188522012-03-15 00:18:045085 selected_files[i] = selected_file;
5086 }
[email protected]a1128322009-10-06 18:38:465087
[email protected]cdaf8d02010-03-30 19:52:475088 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045089 file_chooser_completions_.front()->completion->didChooseFile(
5090 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475091 file_chooser_completions_.pop_front();
5092
5093 // If there are more pending file chooser requests, schedule one now.
5094 if (!file_chooser_completions_.empty()) {
5095 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5096 file_chooser_completions_.front()->params));
5097 }
initial.commit09911bf2008-07-26 23:55:295098}
5099
[email protected]244ac1892011-12-02 17:04:475100void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5101 const gfx::Size& max_size) {
5102 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5103 if (!webview())
5104 return;
[email protected]97e1bf72013-03-06 14:06:055105 auto_resize_mode_ = true;
[email protected]61e2b3cc2012-03-02 16:13:345106 webview()->enableAutoResizeMode(min_size, max_size);
5107}
5108
5109void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5110 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5111 if (!webview())
5112 return;
[email protected]97e1bf72013-03-06 14:06:055113 auto_resize_mode_ = false;
[email protected]61e2b3cc2012-03-02 16:13:345114 webview()->disableAutoResizeMode();
5115
[email protected]eac2b362013-05-22 07:01:455116 if (!new_size.IsEmpty()) {
5117 Resize(new_size,
5118 physical_backing_size_,
5119 overdraw_bottom_height_,
5120 resizer_rect_,
5121 is_fullscreen_,
5122 NO_RESIZE_ACK);
5123 }
[email protected]244ac1892011-12-02 17:04:475124}
5125
[email protected]2bf834f2011-11-17 20:02:215126void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245127 if (send_preferred_size_changes_)
5128 return;
[email protected]9fb325e2010-05-06 18:23:245129 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395130
[email protected]d812fd12011-05-27 23:05:075131 // Start off with an initial preferred size notification (in case
5132 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595133 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085134}
5135
[email protected]310ebd6302011-10-10 19:06:285136void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105137 const gfx::Size& disable_scrollbar_size_limit) {
5138 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5139}
5140
[email protected]310ebd6302011-10-10 19:06:285141void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:265142 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505143 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515144 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375145 UpdateFontRenderingFromRendererPrefs();
[email protected]38a85712013-01-02 22:45:025146
5147#if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015148 if (renderer_prefs.use_custom_colors) {
5149 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
5150 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
5151 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:025152#if defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015153 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]93623c5d2009-12-10 21:40:325154 renderer_prefs.thumb_inactive_color,
5155 renderer_prefs.thumb_active_color,
5156 renderer_prefs.track_color);
[email protected]38a85712013-01-02 22:45:025157#endif // defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015158
5159 if (webview()) {
5160#if defined(TOOLKIT_GTK)
5161 webview()->setScrollbarColors(
5162 renderer_prefs.thumb_inactive_color,
5163 renderer_prefs.thumb_active_color,
5164 renderer_prefs.track_color);
5165#endif // defined(TOOLKIT_GTK)
5166 webview()->setSelectionColors(
5167 renderer_prefs.active_selection_bg_color,
5168 renderer_prefs.active_selection_fg_color,
5169 renderer_prefs.inactive_selection_bg_color,
5170 renderer_prefs.inactive_selection_fg_color);
5171 webview()->themeChanged();
5172 }
[email protected]644d77e2010-01-27 01:03:105173 }
[email protected]38a85712013-01-02 22:45:025174#endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]d299d972012-03-23 02:26:555175
[email protected]107c0532013-02-06 02:34:095176 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
5177 RenderThreadImpl::current()->SetFlingCurveParameters(
5178 renderer_prefs.touchpad_fling_profile,
5179 renderer_prefs.touchscreen_fling_profile);
5180
[email protected]d051d9a2011-12-10 02:02:505181 // If the zoom level for this page matches the old zoom default, and this
5182 // is not a plugin, update the zoom level to match the new default.
5183 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]cbe55d22013-02-14 17:04:335184 !ZoomValuesEqual(old_zoom_level,
5185 renderer_preferences_.default_zoom_level) &&
[email protected]e9ff79c2012-10-19 21:31:265186 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]d051d9a2011-12-10 02:02:505187 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
5188 zoomLevelChanged();
5189 }
[email protected]80d96fa2009-06-10 22:34:515190}
5191
[email protected]310ebd6302011-10-10 19:06:285192void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5193 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285194 if (webview())
5195 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565196}
5197
[email protected]77829642012-05-15 14:47:175198void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
5199 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5200}
5201
[email protected]81375e872012-01-11 21:40:365202void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5203 const WebPluginAction& action) {
5204 if (webview())
5205 webview()->performPluginAction(action, location);
5206}
5207
[email protected]310ebd6302011-10-10 19:06:285208void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195209 const GURL& page_url) {
5210 // Prepare list to storage all savable resource links.
5211 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465212 std::vector<GURL> referrer_urls_list;
5213 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195214 std::vector<GURL> frames_list;
[email protected]12a936d2013-05-15 04:55:495215 SavableResourcesResult result(&resources_list,
5216 &referrer_urls_list,
5217 &referrer_policies_list,
5218 &frames_list);
[email protected]18d5be92011-07-25 18:00:195219
[email protected]e9ff79c2012-10-19 21:31:265220 // webkit/ doesn't know about Referrer.
[email protected]12a936d2013-05-15 04:55:495221 if (!GetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195222 webview(),
5223 page_url,
5224 &result,
[email protected]e9ff79c2012-10-19 21:31:265225 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195226 // If something is wrong when collecting all savable resource links,
5227 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465228 referrer_urls_list.clear();
5229 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195230 resources_list.clear();
5231 frames_list.clear();
5232 }
5233
[email protected]e9ff79c2012-10-19 21:31:265234 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:465235 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5236 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5237 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:265238 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:465239 }
5240
[email protected]18d5be92011-07-25 18:00:195241 // Send result of all savable resource links to embedder.
5242 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5243 resources_list,
5244 referrers_list,
5245 frames_list));
5246}
5247
[email protected]310ebd6302011-10-10 19:06:285248void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195249 const std::vector<GURL>& links,
[email protected]c42de732013-02-16 06:26:315250 const std::vector<base::FilePath>& local_paths,
5251 const base::FilePath& local_directory_name) {
[email protected]18d5be92011-07-25 18:00:195252
5253 // Convert std::vector of GURLs to WebVector<WebURL>
5254 WebVector<WebURL> weburl_links(links);
5255
[email protected]728c2ee2013-06-25 04:01:075256 // Convert std::vector of base::FilePath to WebVector<WebString>
[email protected]18d5be92011-07-25 18:00:195257 WebVector<WebString> webstring_paths(local_paths.size());
5258 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]728c2ee2013-06-25 04:01:075259 webstring_paths[i] = local_paths[i].AsUTF16Unsafe();
[email protected]18d5be92011-07-25 18:00:195260
5261 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5262 webstring_paths,
[email protected]728c2ee2013-06-25 04:01:075263 local_directory_name.AsUTF16Unsafe());
[email protected]18d5be92011-07-25 18:00:195264}
5265
[email protected]310ebd6302011-10-10 19:06:285266void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125267 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275268 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125269 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5270 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5271 before_unload_start_time,
5272 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295273}
5274
[email protected]e1986832013-06-14 07:27:285275void RenderViewImpl::OnSwapOut() {
[email protected]73eb2602012-02-09 19:50:555276 // Only run unload if we're not swapped out yet, but send the ack either way.
5277 if (!is_swapped_out_) {
5278 // Swap this RenderView out so the tab can navigate to a page rendered by a
5279 // different process. This involves running the unload handler and clearing
5280 // the page. Once WasSwappedOut is called, we also allow this process to
5281 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155282
[email protected]73eb2602012-02-09 19:50:555283 // Send an UpdateState message before we get swapped out.
5284 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155285
[email protected]73eb2602012-02-09 19:50:555286 // Synchronously run the unload handler before sending the ACK.
5287 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155288
[email protected]73eb2602012-02-09 19:50:555289 // Swap out and stop sending any IPC messages that are not ACKs.
5290 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155291
[email protected]6169a5772013-05-29 17:41:145292 // Now that we're swapped out and filtering IPC messages, stop loading to
5293 // ensure that no other in-progress navigation continues. We do this here
5294 // to avoid sending a DidStopLoading message to the browser process.
5295 OnStop();
5296
[email protected]285f4bb82012-04-17 15:57:285297 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555298 // run a second time, thanks to a check in FrameLoader::stopLoading.
5299 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285300 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375301 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285302
5303 // Let WebKit know that this view is hidden so it can drop resources and
5304 // stop compositing.
5305 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555306 }
[email protected]992db4c2011-05-12 15:37:155307
[email protected]e1986832013-06-14 07:27:285308 Send(new ViewHostMsg_SwapOut_ACK(routing_id_));
[email protected]992db4c2011-05-12 15:37:155309}
5310
[email protected]0720b532012-08-28 19:23:375311void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445312 // We use loadRequest instead of loadHTMLString because the former commits
5313 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:265314 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:445315 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]890b06ca2012-12-13 21:07:365316 CHECK(is_swapped_out_);
[email protected]e9ff79c2012-10-19 21:31:265317 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:445318 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375319 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445320}
5321
[email protected]310ebd6302011-10-10 19:06:285322void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375323 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295324 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5325 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5326 // in the onunload handler from appearing. For now, we're bypassing that and
5327 // calling the FrameLoader's CloseURL method directly. This should be
5328 // revisited to avoid having two ways to close a page. Having a single way
5329 // to close that can run onunload is also useful for fixing
5330 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275331 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295332
[email protected]992db4c2011-05-12 15:37:155333 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295334}
5335
[email protected]310ebd6302011-10-10 19:06:285336void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025337#if defined(USE_AURA)
5338 // Aura doesn't care if we switch themes.
5339#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525340 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465341 if (webview())
5342 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575343#else // defined(OS_WIN)
5344 // TODO(port): we don't support theming on non-Windows platforms yet
5345 NOTIMPLEMENTED();
5346#endif
initial.commit09911bf2008-07-26 23:55:295347}
5348
[email protected]310ebd6302011-10-10 19:06:285349void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:085350 if (decrement_shared_popup_at_destruction_)
5351 shared_popup_counter_->data--;
5352 shared_popup_counter_ = new SharedRenderViewCounter(0);
5353 decrement_shared_popup_at_destruction_ = false;
5354}
5355
[email protected]310ebd6302011-10-10 19:06:285356bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5357 const WebURLError& error,
5358 bool replace) {
[email protected]15d79e12009-08-02 19:23:455359 // We only show alternate error pages in the main frame. They are
5360 // intended to assist the user when navigating, so there is not much
5361 // value in showing them for failed subframes. Ideally, we would be
5362 // able to use the TYPED transition type for this, but that flag is
5363 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455364 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455365 return false;
5366
5367 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375368 // connection failure.
[email protected]15d79e12009-08-02 19:23:455369 int ec = error.reason;
5370 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5371 ec != net::ERR_CONNECTION_FAILED &&
5372 ec != net::ERR_CONNECTION_REFUSED &&
5373 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415374 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455375 return false;
[email protected]82114f52012-03-20 22:53:415376 }
[email protected]15d79e12009-08-02 19:23:455377
5378 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555379 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455380 if (!error_page_url.is_valid())
5381 return false;
5382
[email protected]11a65772013-04-27 00:36:425383 WebDataSource* ds = frame->provisionalDataSource();
5384 const WebURLRequest& failed_request = ds->request();
5385
[email protected]15d79e12009-08-02 19:23:455386 // Load an empty page first so there is an immediate response to the error,
5387 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455388 frame->loadHTMLString(std::string(),
[email protected]e9ff79c2012-10-19 21:31:265389 GURL(kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455390 error.unreachableURL,
5391 replace);
5392
5393 // Now, create a fetcher for the error page and associate it with the data
5394 // source we just created via the LoadHTMLString call. That way if another
5395 // navigation occurs, the fetcher will get destroyed.
[email protected]e20b88d2013-04-09 15:28:375396 InternalDocumentStateData* internal_data =
5397 InternalDocumentStateData::FromDataSource(frame->provisionalDataSource());
5398 internal_data->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455399 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:425400 error_page_url, frame, failed_request, error,
[email protected]6e806822011-11-19 01:51:085401 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5402 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455403 return true;
5404}
5405
[email protected]310ebd6302011-10-10 19:06:285406void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
[email protected]11a65772013-04-27 00:36:425407 const WebURLRequest& original_request,
[email protected]310ebd6302011-10-10 19:06:285408 const WebURLError& original_error,
5409 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455410 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095411 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555412 // will simply display a default error page.
[email protected]11a65772013-04-27 00:36:425413 LoadNavigationErrorPage(frame, original_request, original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455414}
5415
[email protected]310ebd6302011-10-10 19:06:285416void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005417 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475418 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005419}
5420
[email protected]0fdd5012013-05-29 08:05:565421void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]cda45c02010-02-25 19:28:105422 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475423 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105424 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205425 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]0fdd5012013-05-29 08:05:565426 ShouldDisplayScrollbars(params.new_size.width(),
5427 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:105428 }
[email protected]dd6afca2011-08-13 03:44:315429 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105430 }
5431
[email protected]0fdd5012013-05-29 08:05:565432 RenderWidget::OnResize(params);
[email protected]30f75e62009-02-25 22:01:005433}
[email protected]0aa477bd2009-03-23 22:21:435434
[email protected]29ed96a2012-02-04 18:12:165435void RenderViewImpl::WillInitiatePaint() {
5436 // Notify the pepper plugins that we're about to paint.
[email protected]6d17f6392012-12-05 05:24:545437 pepper_helper_->ViewWillInitiatePaint();
[email protected]29ed96a2012-02-04 18:12:165438}
5439
[email protected]310ebd6302011-10-10 19:06:285440void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:165441 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]6d17f6392012-12-05 05:24:545442 pepper_helper_->ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:285443}
5444
[email protected]310ebd6302011-10-10 19:06:285445void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:285446 // Notify any pepper plugins that we painted. This will call into the plugin,
5447 // and we it may ask to close itself as a result. This will, in turn, modify
5448 // our set, possibly invalidating the iterator. So we iterate on a copy that
5449 // won't change out from under us.
[email protected]6d17f6392012-12-05 05:24:545450 pepper_helper_->ViewFlushedPaint();
[email protected]53900d52010-06-16 04:25:015451
[email protected]5b1dec8c2012-02-07 04:35:385452 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5453 // See crbug.com/112921.
5454 if (!webview())
5455 return;
5456
[email protected]00c39612010-03-06 02:53:285457 WebFrame* main_frame = webview()->mainFrame();
5458
5459 // If we have a provisional frame we are between the start and commit stages
5460 // of loading and we don't want to save stats.
5461 if (!main_frame->provisionalDataSource()) {
5462 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075463 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]92d457802013-04-01 19:18:495464 InternalDocumentStateData* data =
[email protected]e20b88d2013-04-09 15:28:375465 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]92d457802013-04-01 19:18:495466 if (data->did_first_visually_non_empty_layout() &&
5467 !data->did_first_visually_non_empty_paint()) {
5468 data->set_did_first_visually_non_empty_paint(true);
5469 Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_,
5470 page_id_));
5471 }
5472
[email protected]05c8e502010-08-15 15:13:525473 // TODO(jar): The following code should all be inside a method, probably in
5474 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285475 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075476 if (document_state->first_paint_time().is_null()) {
5477 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285478 }
[email protected]007733c2011-11-17 00:34:075479 if (document_state->first_paint_after_load_time().is_null() &&
5480 !document_state->finish_load_time().is_null()) {
5481 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285482 }
5483 }
5484}
5485
[email protected]310ebd6302011-10-10 19:06:285486webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155487 const gfx::Rect& paint_bounds,
5488 TransportDIB** dib,
5489 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:205490 gfx::Rect* clip,
5491 float* scale_factor) {
[email protected]6d17f6392012-12-05 05:24:545492 return pepper_helper_->GetBitmapForOptimizedPluginPaint(
[email protected]0f3a2d12012-09-01 03:37:205493 paint_bounds, dib, location, clip, scale_factor);
[email protected]ca4847f2010-09-24 05:39:155494}
5495
[email protected]ceb36f7d2012-10-31 18:33:245496gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075497 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:245498 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525499}
5500
[email protected]310ebd6302011-10-10 19:06:285501void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165502 if (webview())
[email protected]26aa0482009-09-30 16:55:275503 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165504}
5505
[email protected]310ebd6302011-10-10 19:06:285506void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145507 if (webview())
[email protected]b4bb2502009-10-01 22:35:275508 webview()->setIsTransparent(!background.empty());
[email protected]ba91a792013-02-06 09:48:285509 if (compositor_)
5510 compositor_->setHasTransparentBackground(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145511
5512 SetBackground(background);
5513}
5514
[email protected]2a84f9d2012-06-05 21:50:435515void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5516 if (accessibility_mode_ == new_mode)
5517 return;
5518 accessibility_mode_ = new_mode;
5519 if (renderer_accessibility_) {
5520 delete renderer_accessibility_;
5521 renderer_accessibility_ = NULL;
5522 }
5523 if (accessibility_mode_ == AccessibilityModeComplete)
5524 renderer_accessibility_ = new RendererAccessibilityComplete(this);
[email protected]8d3dfee62013-06-19 05:50:335525#if !defined(OS_ANDROID)
[email protected]2a84f9d2012-06-05 21:50:435526 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5527 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
[email protected]8d3dfee62013-06-19 05:50:335528#endif
[email protected]2a84f9d2012-06-05 21:50:435529}
5530
[email protected]310ebd6302011-10-10 19:06:285531void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345532 if (webview())
[email protected]b4bb2502009-10-01 22:35:275533 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265534
5535#if defined(OS_MACOSX)
5536 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5537 for (plugin_it = plugin_delegates_.begin();
5538 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5539 (*plugin_it)->SetWindowFocus(active);
5540 }
5541#endif
[email protected]8c66c5a2009-07-22 17:26:345542}
5543
[email protected]6ce7abc52010-02-02 18:40:145544#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285545void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:145546 // Inform plugins that their container has changed visibility.
5547 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5548 for (plugin_it = plugin_delegates_.begin();
5549 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5550 (*plugin_it)->SetContainerVisibility(visible);
5551 }
5552}
[email protected]1e6e3c992010-02-08 15:52:135553
[email protected]310ebd6302011-10-10 19:06:285554void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5555 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135556 // Inform plugins that their window's frame has changed.
5557 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5558 for (plugin_it = plugin_delegates_.begin();
5559 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5560 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5561 }
5562}
[email protected]935d63d2010-10-15 23:31:555563
[email protected]310ebd6302011-10-10 19:06:285564void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5565 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135566 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555567 // applies to it or not, so inform all the delegates.
5568 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5569 for (plugin_it = plugin_delegates_.begin();
5570 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135571 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555572 }
5573}
[email protected]6ce7abc52010-02-02 18:40:145574#endif // OS_MACOSX
5575
[email protected]310ebd6302011-10-10 19:06:285576void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595577 // We need to grab a pointer to the doomed WebView before we destroy it.
5578 WebView* doomed = webview();
5579 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495580 g_view_map.Get().erase(doomed);
[email protected]058561b2012-12-03 06:48:225581 g_routing_id_view_map.Get().erase(routing_id_);
[email protected]60c42a8c72009-10-09 04:08:595582}
5583
[email protected]310ebd6302011-10-10 19:06:285584void RenderViewImpl::DidHandleKeyEvent() {
[email protected]b2324b092012-11-01 10:34:115585 ClearEditCommands();
[email protected]446705872009-09-10 07:22:485586}
5587
[email protected]310ebd6302011-10-10 19:06:285588bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035589 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]41d86852012-11-07 12:23:245590 possible_drag_event_info_.event_source =
5591 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
5592 possible_drag_event_info_.event_location =
5593 gfx::Point(event.globalX, event.globalY);
[email protected]6d17f6392012-12-05 05:24:545594 pepper_helper_->WillHandleMouseEvent();
[email protected]217690d2012-01-27 07:33:115595
5596 // If the mouse is locked, only the current owner of the mouse lock can
5597 // process mouse events.
5598 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375599}
5600
[email protected]f56c7872013-06-18 12:31:575601bool RenderViewImpl::WillHandleKeyEvent(const WebKit::WebKeyboardEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035602 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]f56c7872013-06-18 12:31:575603 return false;
5604}
5605
[email protected]41d86852012-11-07 12:23:245606bool RenderViewImpl::WillHandleGestureEvent(
5607 const WebKit::WebGestureEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035608 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:245609 possible_drag_event_info_.event_source =
5610 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
5611 possible_drag_event_info_.event_location =
5612 gfx::Point(event.globalX, event.globalY);
5613 return false;
5614}
5615
[email protected]2b942c332012-04-25 16:26:265616void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515617 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065618}
5619
[email protected]310ebd6302011-10-10 19:06:285620void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245621 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5622}
5623
[email protected]3d5c243b2012-11-30 00:26:015624bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const {
5625 if (!webview())
5626 return false;
5627 return webview()->hasTouchEventHandlersAt(point);
5628}
5629
[email protected]310ebd6302011-10-10 19:06:285630void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435631 RenderWidget::OnWasHidden();
5632
[email protected]2d7b82c2012-06-01 05:57:505633#if defined(OS_ANDROID)
[email protected]bc427442013-07-13 02:53:085634 // Inform RendererMediaPlayerManager to release all media player resources.
[email protected]1c36bea2013-07-01 13:43:015635 // unless some audio is playing.
[email protected]263135d2012-11-15 13:01:565636 // If something is in progress the resource will not be freed, it will
5637 // only be freed once the tab is destroyed or if the user navigates away
5638 // via WebMediaPlayerAndroid::Destroy
[email protected]1c36bea2013-07-01 13:43:015639 media_player_manager_->ReleaseMediaResources();
[email protected]6392d982013-04-16 16:59:225640
5641#if defined(ENABLE_WEBRTC)
5642 RenderThreadImpl::current()->video_capture_impl_manager()->
5643 SuspendDevices(true);
5644#endif
[email protected]2d7b82c2012-06-01 05:57:505645#endif
5646
[email protected]8869d392013-05-07 15:34:265647 if (webview())
[email protected]f59203a2011-06-07 10:01:445648 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075649
[email protected]204f1df2012-01-04 20:21:135650 // Inform PPAPI plugins that their page is no longer visible.
[email protected]6d17f6392012-12-05 05:24:545651 pepper_helper_->PageVisibilityChanged(false);
[email protected]204f1df2012-01-04 20:21:135652
[email protected]a6939ca42011-02-18 17:58:075653#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135654 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435655 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5656 for (plugin_it = plugin_delegates_.begin();
5657 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5658 (*plugin_it)->SetContainerVisibility(false);
5659 }
[email protected]a6939ca42011-02-18 17:58:075660#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435661}
5662
[email protected]9e2e4632012-07-27 16:38:415663void RenderViewImpl::OnWasShown(bool needs_repainting) {
5664 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435665
[email protected]6392d982013-04-16 16:59:225666#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
5667 RenderThreadImpl::current()->video_capture_impl_manager()->
5668 SuspendDevices(false);
5669#endif
5670
[email protected]8869d392013-05-07 15:34:265671 if (webview())
[email protected]f59203a2011-06-07 10:01:445672 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075673
[email protected]204f1df2012-01-04 20:21:135674 // Inform PPAPI plugins that their page is visible.
[email protected]6d17f6392012-12-05 05:24:545675 pepper_helper_->PageVisibilityChanged(true);
[email protected]204f1df2012-01-04 20:21:135676
[email protected]a6939ca42011-02-18 17:58:075677#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135678 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435679 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5680 for (plugin_it = plugin_delegates_.begin();
5681 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5682 (*plugin_it)->SetContainerVisibility(true);
5683 }
[email protected]784ea1ab2010-09-18 00:02:345684#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075685}
[email protected]1e6e3c992010-02-08 15:52:135686
[email protected]ed7defa2013-03-12 21:29:595687GURL RenderViewImpl::GetURLForGraphicsContext3D() {
5688 DCHECK(webview());
5689 if (webview()->mainFrame())
5690 return GURL(webview()->mainFrame()->document().url());
5691 else
5692 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:245693}
5694
[email protected]479b0172012-10-29 19:27:095695bool RenderViewImpl::ForceCompositingModeEnabled() {
5696 return webkit_preferences_.force_compositing_mode;
5697}
5698
[email protected]310ebd6302011-10-10 19:06:285699void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135700 RenderWidget::OnSetFocus(enable);
5701
[email protected]7d3c02c2010-05-05 23:10:315702 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075703 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135704 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5705 for (plugin_it = plugin_delegates_.begin();
5706 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345707#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315708 // RenderWidget's call to setFocus can cause the underlying webview's
5709 // activation state to change just like a call to setIsActive.
5710 if (enable)
5711 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345712#endif
[email protected]7d3c02c2010-05-05 23:10:315713 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135714 }
5715 }
[email protected]a01da5682012-06-30 00:37:315716 // Notify all Pepper plugins.
[email protected]6d17f6392012-12-05 05:24:545717 pepper_helper_->OnSetFocus(enable);
[email protected]321032992012-11-08 01:01:275718 // Notify all BrowserPlugins of the RenderView's focus state.
[email protected]fc72bb12013-06-02 21:13:465719 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:325720 browser_plugin_manager_->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:135721}
[email protected]941e4552010-02-01 21:23:435722
[email protected]310ebd6302011-10-10 19:06:285723void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]cb9e2632013-06-18 11:26:475724 UpdateTextInputType();
[email protected]3f783362011-10-21 22:40:505725 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575726}
5727
[email protected]73bf95812011-10-12 11:38:325728void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]cb9e2632013-06-18 11:26:475729 UpdateTextInputType();
[email protected]8fe8f742012-06-14 00:36:085730 if (renderer_accessibility_)
5731 renderer_accessibility_->FocusedNodeChanged(WebNode());
[email protected]73bf95812011-10-12 11:38:325732}
5733
[email protected]3f783362011-10-21 22:40:505734void RenderViewImpl::PpapiPluginCaretPositionChanged() {
5735 UpdateSelectionBounds();
5736}
5737
[email protected]b25b3ee2012-01-13 05:19:545738bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
[email protected]6d17f6392012-12-05 05:24:545739 if (!pepper_helper_->IsPluginFocused())
[email protected]b25b3ee2012-01-13 05:19:545740 return false;
[email protected]6d17f6392012-12-05 05:24:545741 *rect = pepper_helper_->GetCaretBounds();
[email protected]b25b3ee2012-01-13 05:19:545742 return true;
5743}
5744
[email protected]397c23962012-05-21 07:09:325745void RenderViewImpl::SimulateImeSetComposition(
5746 const string16& text,
5747 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5748 int selection_start,
5749 int selection_end) {
5750 OnImeSetComposition(text, underlines, selection_start, selection_end);
5751}
5752
5753void RenderViewImpl::SimulateImeConfirmComposition(
5754 const string16& text,
5755 const ui::Range& replacement_range) {
[email protected]0e45bd02013-07-12 20:20:025756 OnImeConfirmComposition(text, replacement_range, false);
[email protected]397c23962012-05-21 07:09:325757}
5758
[email protected]73bf95812011-10-12 11:38:325759void RenderViewImpl::PpapiPluginCancelComposition() {
[email protected]88dbe32f2013-06-20 23:31:365760 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));;
[email protected]501ea13d2013-07-09 17:03:295761#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]88dbe32f2013-06-20 23:31:365762 UpdateCompositionInfo(true);
[email protected]501ea13d2013-07-09 17:03:295763#endif
[email protected]73bf95812011-10-12 11:38:325764}
5765
[email protected]3c8c74c2012-03-15 07:34:525766void RenderViewImpl::PpapiPluginSelectionChanged() {
5767 SyncSelectionIfRequired();
5768}
5769
[email protected]e9ff79c2012-10-19 21:31:265770void RenderViewImpl::PpapiPluginCreated(RendererPpapiHost* host) {
[email protected]236bf852012-07-27 22:49:365771 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
5772 DidCreatePepperPlugin(host));
5773}
5774
[email protected]310ebd6302011-10-10 19:06:285775void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575776 const string16& text,
5777 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5778 int selection_start,
5779 int selection_end) {
[email protected]6d17f6392012-12-05 05:24:545780 if (pepper_helper_->IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325781 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]6d17f6392012-12-05 05:24:545782 pepper_helper_->OnImeSetComposition(text,
5783 underlines,
5784 selection_start,
5785 selection_end);
[email protected]73bf95812011-10-12 11:38:325786 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235787#if defined(OS_WIN)
5788 // When a plug-in has focus, we create platform-specific IME data used by
5789 // our IME emulator and send it directly to the focused plug-in, i.e. we
5790 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5791 // instance ID is the same one as the specified ID.)
5792 if (focused_plugin_id_ >= 0) {
5793 std::vector<int> clauses;
5794 std::vector<int> target;
5795 for (size_t i = 0; i < underlines.size(); ++i) {
5796 clauses.push_back(underlines[i].startOffset);
5797 clauses.push_back(underlines[i].endOffset);
5798 if (underlines[i].thick) {
5799 target.clear();
5800 target.push_back(underlines[i].startOffset);
5801 target.push_back(underlines[i].endOffset);
5802 }
5803 }
5804 std::set<WebPluginDelegateProxy*>::iterator it;
5805 for (it = plugin_delegates_.begin();
5806 it != plugin_delegates_.end(); ++it) {
5807 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5808 focused_plugin_id_);
5809 }
5810 return;
5811 }
5812#endif
[email protected]56ea1a62011-05-30 07:05:575813 RenderWidget::OnImeSetComposition(text,
5814 underlines,
5815 selection_start,
5816 selection_end);
5817 }
5818}
5819
[email protected]0e45bd02013-07-12 20:20:025820void RenderViewImpl::OnImeConfirmComposition(const string16& text,
5821 const ui::Range& replacement_range,
5822 bool keep_selection) {
[email protected]6d17f6392012-12-05 05:24:545823 if (pepper_helper_->IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325824 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]6d17f6392012-12-05 05:24:545825 pepper_helper_->OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:575826 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235827#if defined(OS_WIN)
5828 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5829 // plug-ins. When we send IME text directly to plug-ins, we should not send
5830 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:445831 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:235832 if (focused_plugin_id_ >= 0) {
5833 std::set<WebPluginDelegateProxy*>::iterator it;
5834 for (it = plugin_delegates_.begin();
5835 it != plugin_delegates_.end(); ++it) {
5836 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5837 }
5838 return;
5839 }
5840#endif
[email protected]ebd28ac2011-10-13 18:49:055841 if (replacement_range.IsValid() && webview()) {
5842 // Select the text in |replacement_range|, it will then be replaced by
5843 // text added by the call to RenderWidget::OnImeConfirmComposition().
5844 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:165845 WebRange webrange = WebRange::fromDocumentRange(
5846 frame, replacement_range.start(), replacement_range.length());
5847 if (!webrange.isNull())
[email protected]884f9002012-08-21 19:33:585848 frame->selectRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:055849 }
5850 }
[email protected]0e45bd02013-07-12 20:20:025851 RenderWidget::OnImeConfirmComposition(text,
5852 replacement_range,
5853 keep_selection);
[email protected]56ea1a62011-05-30 07:05:575854 }
5855}
5856
[email protected]468ac582012-11-20 00:53:195857void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) {
5858 RenderWidget::SetDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:045859 if (webview()) {
[email protected]dea5e7682012-06-14 05:21:245860 webview()->setDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:045861 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
5862 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]c162ced82013-06-29 01:24:535863 webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
5864 ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:435865 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
5866 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]06fc4d3b2013-07-08 21:07:245867 webview()->settings()->
5868 setAcceleratedCompositingForFixedRootBackgroundEnabled(
5869 ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:045870 }
[email protected]3a1c8a8032013-03-18 22:35:325871 if (auto_resize_mode_)
5872 AutoResizeCompositor();
[email protected]caaf2482013-05-01 20:33:325873
[email protected]fc72bb12013-06-02 21:13:465874 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:325875 browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_);
[email protected]dea5e7682012-06-14 05:21:245876}
5877
[email protected]310ebd6302011-10-10 19:06:285878ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]6d17f6392012-12-05 05:24:545879 return pepper_helper_->IsPluginFocused() ?
5880 pepper_helper_->GetTextInputType() : RenderWidget::GetTextInputType();
[email protected]73bf95812011-10-12 11:38:325881}
5882
[email protected]3f783362011-10-21 22:40:505883void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
[email protected]6d17f6392012-12-05 05:24:545884 if (pepper_helper_->IsPluginFocused()) {
[email protected]3f783362011-10-21 22:40:505885 // TODO(kinaba) http://crbug.com/101101
5886 // Current Pepper IME API does not handle selection bounds. So we simply
5887 // use the caret position as an empty range for now. It will be updated
5888 // after Pepper API equips features related to surrounding text retrieval.
[email protected]6d17f6392012-12-05 05:24:545889 gfx::Rect caret = pepper_helper_->GetCaretBounds();
[email protected]3f783362011-10-21 22:40:505890 *start = caret;
5891 *end = caret;
5892 return;
5893 }
5894 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455895}
5896
[email protected]501ea13d2013-07-09 17:03:295897#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]58b48a0d2012-06-13 07:01:355898void RenderViewImpl::GetCompositionCharacterBounds(
5899 std::vector<gfx::Rect>* bounds) {
5900 DCHECK(bounds);
5901 bounds->clear();
5902
[email protected]88dbe32f2013-06-20 23:31:365903 if (pepper_helper_->IsPluginFocused()) {
5904 return;
5905 }
[email protected]58b48a0d2012-06-13 07:01:355906 if (!webview())
5907 return;
5908 size_t start_offset = 0;
5909 size_t character_count = 0;
5910 if (!webview()->compositionRange(&start_offset, &character_count))
5911 return;
5912 if (character_count == 0)
5913 return;
5914
5915 WebKit::WebFrame* frame = webview()->focusedFrame();
5916 if (!frame)
5917 return;
5918
5919 bounds->reserve(character_count);
5920 WebKit::WebRect webrect;
5921 for (size_t i = 0; i < character_count; ++i) {
5922 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
5923 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
5924 bounds->clear();
5925 return;
5926 }
5927 bounds->push_back(webrect);
5928 }
5929}
5930
[email protected]88dbe32f2013-06-20 23:31:365931void RenderViewImpl::GetCompositionRange(ui::Range* range) {
5932 if (pepper_helper_->IsPluginFocused()) {
5933 return;
5934 }
5935 RenderWidget::GetCompositionRange(range);
5936}
[email protected]501ea13d2013-07-09 17:03:295937#endif
[email protected]88dbe32f2013-06-20 23:31:365938
[email protected]310ebd6302011-10-10 19:06:285939bool RenderViewImpl::CanComposeInline() {
[email protected]6d17f6392012-12-05 05:24:545940 return pepper_helper_->IsPluginFocused() ?
5941 pepper_helper_->CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:575942}
5943
[email protected]35134e12013-02-22 20:07:405944void RenderViewImpl::InstrumentWillBeginFrame() {
5945 if (!webview())
5946 return;
5947 if (!webview()->devToolsAgent())
5948 return;
5949 webview()->devToolsAgent()->didBeginFrame();
5950}
5951
5952void RenderViewImpl::InstrumentDidBeginFrame() {
5953 if (!webview())
5954 return;
5955 if (!webview()->devToolsAgent())
5956 return;
5957 // TODO(jamesr/caseq): Decide if this needs to be renamed.
5958 webview()->devToolsAgent()->didComposite();
5959}
5960
5961void RenderViewImpl::InstrumentDidCancelFrame() {
5962 if (!webview())
5963 return;
5964 if (!webview()->devToolsAgent())
5965 return;
5966 webview()->devToolsAgent()->didCancelFrame();
5967}
5968
5969void RenderViewImpl::InstrumentWillComposite() {
5970 if (!webview())
5971 return;
5972 if (!webview()->devToolsAgent())
5973 return;
5974 webview()->devToolsAgent()->willComposite();
5975}
5976
[email protected]34bb3ac2013-03-08 02:41:285977bool RenderViewImpl::AllowPartialSwap() const {
5978 return allow_partial_swap_;
5979}
5980
[email protected]e6ae0f6c2011-10-04 10:39:235981#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:285982void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:235983 if (focused)
5984 focused_plugin_id_ = plugin_id;
5985 else
5986 focused_plugin_id_ = -1;
5987}
5988#endif
5989
[email protected]43f28f832010-02-03 02:28:485990#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285991void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:415992 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:135993}
5994
[email protected]310ebd6302011-10-10 19:06:285995void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:135996 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555997 // This message can be sent during event-handling, and needs to be delivered
5998 // within that context.
5999 msg->set_unblock(true);
6000 Send(msg);
6001}
[email protected]82114f52012-03-20 22:53:416002#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:286003
[email protected]310ebd6302011-10-10 19:06:286004bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:266005 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476006 WebFileChooserCompletion* completion) {
6007 static const size_t kMaximumPendingFileChooseRequests = 4;
6008 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6009 // This sanity check prevents too many file choose requests from getting
6010 // queued which could DoS the user. Getting these is most likely a
6011 // programming error (there are many ways to DoS the user so it's not
6012 // considered a "real" security check), either in JS requesting many file
6013 // choosers to pop up, or in a plugin.
6014 //
6015 // TODO(brettw) we might possibly want to require a user gesture to open
6016 // a file picker, which will address this issue in a better way.
6017 return false;
6018 }
6019
6020 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6021 new PendingFileChooser(params, completion)));
6022 if (file_chooser_completions_.size() == 1) {
6023 // Actually show the browse dialog when this is the first request.
6024 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6025 }
6026 return true;
6027}
6028
[email protected]310ebd6302011-10-10 19:06:286029WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516030 if (!geolocation_dispatcher_)
6031 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6032 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256033}
[email protected]61c9f032010-03-31 23:04:196034
[email protected]310ebd6302011-10-10 19:06:286035WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:116036 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226037#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026038 if (!input_tag_speech_dispatcher_)
6039 input_tag_speech_dispatcher_ =
6040 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226041#endif
[email protected]c52b2892012-03-07 11:01:026042 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116043}
6044
[email protected]64d09222012-05-25 10:10:346045WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
[email protected]64d09222012-05-25 10:10:346046 if (!speech_recognition_dispatcher_)
6047 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:346048 return speech_recognition_dispatcher_;
6049}
6050
[email protected]310ebd6302011-10-10 19:06:286051WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:516052 if (!device_orientation_dispatcher_)
6053 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
6054 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:536055}
6056
[email protected]310ebd6302011-10-10 19:06:286057void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6058 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256059 // For now, don't remember plugin zoom values. We don't want to mix them with
6060 // normal web content (i.e. a fixed layout plugin would usually want them
6061 // different).
6062 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6063
[email protected]b75b8292010-10-01 07:28:256064 int minimum_percent = static_cast<int>(
6065 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
6066 int maximum_percent = static_cast<int>(
6067 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256068
6069 Send(new ViewHostMsg_UpdateZoomLimits(
6070 routing_id_, minimum_percent, maximum_percent, remember));
6071}
6072
[email protected]310ebd6302011-10-10 19:06:286073void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256074 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086075 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266076
6077 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6078
[email protected]b75b8292010-10-01 07:28:256079 // Tell the browser which url got zoomed so it can update the menu and the
6080 // saved values if necessary
6081 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086082 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416083 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256084}
6085
[email protected]310ebd6302011-10-10 19:06:286086void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6087 const WebString& base_url,
6088 const WebString& url,
6089 const WebString& title) {
[email protected]af15bf22013-03-08 01:18:176090 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]a6d36cc2011-02-23 00:39:486091 GURL base(base_url);
6092 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6093 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6094 return;
6095 }
[email protected]f1a29a02011-10-06 23:08:446096 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6097 UTF16ToUTF8(scheme),
6098 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366099 title,
6100 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486101}
6102
[email protected]310ebd6302011-10-10 19:06:286103WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:446104 WebKit::WebPageVisibilityState current_state = is_hidden() ?
6105 WebKit::WebPageVisibilityStateHidden :
6106 WebKit::WebPageVisibilityStateVisible;
6107 WebKit::WebPageVisibilityState override_state = current_state;
[email protected]e9ff79c2012-10-19 21:31:266108 if (GetContentClient()->renderer()->
[email protected]f59203a2011-06-07 10:01:446109 ShouldOverridePageVisibilityState(this,
6110 &override_state))
6111 return override_state;
6112 return current_state;
[email protected]94dec932011-05-26 20:04:216113}
6114
[email protected]273558fb2012-01-12 15:03:516115WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]c3bdce152013-07-10 04:56:346116 EnsureMediaStreamClient();
6117 return web_user_media_client_;
[email protected]273558fb2012-01-12 15:03:516118}
6119
[email protected]a0629af92012-08-08 00:39:376120void RenderViewImpl::draggableRegionsChanged() {
6121 FOR_EACH_OBSERVER(
6122 RenderViewObserver,
6123 observers_,
6124 DraggableRegionsChanged(webview()->mainFrame()));
6125}
6126
[email protected]20657a82012-08-21 20:23:036127#if defined(OS_ANDROID)
6128WebContentDetectionResult RenderViewImpl::detectContentAround(
6129 const WebHitTestResult& touch_hit) {
6130 DCHECK(!touch_hit.isNull());
6131 DCHECK(!touch_hit.node().isNull());
6132 DCHECK(touch_hit.node().isTextNode());
6133
6134 // Process the position with all the registered content detectors until
6135 // a match is found. Priority is provided by their relative order.
6136 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6137 it != content_detectors_.end(); ++it) {
6138 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6139 if (content.valid) {
6140 return WebContentDetectionResult(content.content_boundaries,
6141 UTF8ToUTF16(content.text), content.intent_url);
6142 }
6143 }
6144 return WebContentDetectionResult();
6145}
6146
6147void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6148 // Introduce a short delay so that the user can notice the content.
[email protected]dd32b1272013-05-04 14:17:116149 base::MessageLoop::current()->PostDelayedTask(
[email protected]20657a82012-08-21 20:23:036150 FROM_HERE,
[email protected]dd32b1272013-05-04 14:17:116151 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent,
6152 AsWeakPtr(),
6153 intent,
6154 expected_content_intent_id_),
[email protected]20657a82012-08-21 20:23:036155 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6156}
6157
6158void RenderViewImpl::cancelScheduledContentIntents() {
6159 ++expected_content_intent_id_;
6160}
6161
6162void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6163 size_t request_id) {
6164 if (request_id != expected_content_intent_id_)
6165 return;
6166
6167 // Remove the content highlighting if any.
6168 scheduleComposite();
6169
6170 if (!intent.is_empty())
6171 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6172}
[email protected]b18583c2012-12-18 06:55:276173
6174bool RenderViewImpl::openDateTimeChooser(
6175 const WebKit::WebDateTimeChooserParams& params,
6176 WebKit::WebDateTimeChooserCompletion* completion) {
6177 date_time_picker_client_.reset(
6178 new RendererDateTimePicker(this, params, completion));
6179 return date_time_picker_client_->Open();
6180}
6181
[email protected]6d17f6392012-12-05 05:24:546182#endif // defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:036183
[email protected]310ebd6302011-10-10 19:06:286184void RenderViewImpl::OnAsyncFileOpened(
6185 base::PlatformFileError error_code,
6186 IPC::PlatformFileForTransit file_for_transit,
6187 int message_id) {
[email protected]6d17f6392012-12-05 05:24:546188 pepper_helper_->OnAsyncFileOpened(
[email protected]27a9ef32010-09-10 04:06:246189 error_code,
6190 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
6191 message_id);
6192}
[email protected]caf706f2010-10-26 17:54:086193
[email protected]310ebd6302011-10-10 19:06:286194void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:476195 int request_id,
[email protected]108fd342013-01-04 20:46:546196 base::ProcessId broker_pid,
[email protected]d54305072011-06-22 20:58:436197 const IPC::ChannelHandle& handle) {
[email protected]108fd342013-01-04 20:46:546198 pepper_helper_->OnPpapiBrokerChannelCreated(request_id, broker_pid, handle);
[email protected]eb415bf0e2011-04-14 02:45:426199}
6200
[email protected]d8415ad92012-08-23 14:40:506201void RenderViewImpl::OnPpapiBrokerPermissionResult(
6202 int request_id,
6203 bool result) {
[email protected]6d17f6392012-12-05 05:24:546204 pepper_helper_->OnPpapiBrokerPermissionResult(request_id, result);
[email protected]d8415ad92012-08-23 14:40:506205}
6206
[email protected]caf706f2010-10-26 17:54:086207#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286208void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156209 if (external_popup_menu_ == NULL) {
6210 // Crash reports from the field indicate that we can be notified with a
6211 // NULL external popup menu (we probably get notified twice).
6212 // If you hit this please file a bug against jcivelli and include the page
6213 // and steps to repro.
6214 NOTREACHED();
6215 return;
6216 }
[email protected]caf706f2010-10-26 17:54:086217 external_popup_menu_->DidSelectItem(selected_index);
6218 external_popup_menu_.reset();
6219}
6220#endif
[email protected]bb461532010-11-26 21:50:236221
[email protected]24d2b172012-05-26 00:54:126222#if defined(OS_ANDROID)
6223void RenderViewImpl::OnSelectPopupMenuItems(
6224 bool canceled,
6225 const std::vector<int>& selected_indices) {
6226 // It is possible to receive more than one of these calls if the user presses
6227 // a select faster than it takes for the show-select-popup IPC message to make
6228 // it to the browser UI thread. Ignore the extra-messages.
6229 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
[email protected]59383c782013-04-17 16:43:276230 if (!external_popup_menu_)
[email protected]24d2b172012-05-26 00:54:126231 return;
6232
6233 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6234 external_popup_menu_.reset();
6235}
6236#endif
6237
[email protected]310ebd6302011-10-10 19:06:286238void RenderViewImpl::OnContextMenuClosed(
[email protected]e9ff79c2012-10-19 21:31:266239 const CustomContextMenuContext& custom_context) {
[email protected]860ee642012-10-13 03:46:256240 if (custom_context.request_id) {
6241 // External request, should be in our map.
[email protected]e9ff79c2012-10-19 21:31:266242 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:256243 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:466244 if (client) {
6245 client->OnMenuClosed(custom_context.request_id);
6246 pending_context_menus_.Remove(custom_context.request_id);
6247 }
[email protected]860ee642012-10-13 03:46:256248 } else {
6249 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:086250 context_menu_node_.reset();
[email protected]860ee642012-10-13 03:46:256251 }
[email protected]521b2482011-01-15 00:10:106252}
[email protected]5a7b15a2011-08-22 22:48:186253
[email protected]f56c7872013-06-18 12:31:576254void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) {
[email protected]a14ddcd2013-06-21 22:53:036255 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU;
[email protected]f56c7872013-06-18 12:31:576256 touch_editing_context_menu_location_ = location;
[email protected]47822262013-04-23 17:22:366257 if (webview())
6258 webview()->showContextMenu();
6259}
6260
[email protected]310ebd6302011-10-10 19:06:286261void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186262 if (!webview())
6263 return;
6264 WebFrame* main_frame = webview()->mainFrame();
6265 if (!main_frame)
6266 return;
6267 main_frame->enableViewSourceMode(true);
6268}
[email protected]67bfb83f2011-09-22 03:36:376269
[email protected]c7654a232013-06-12 21:04:446270#if defined(OS_ANDROID)
[email protected]64d0e192011-12-09 14:44:206271void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:316272 DCHECK(!java_bridge_dispatcher_);
[email protected]7e9c5bb02012-05-14 13:58:316273 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]7f3c7af2011-10-20 22:52:516274}
[email protected]da816272013-05-15 21:31:176275#endif
[email protected]0720b532012-08-28 19:23:376276
[email protected]7cc78902012-12-06 02:32:266277void RenderViewImpl::OnDisownOpener() {
6278 if (!webview())
6279 return;
6280
6281 WebFrame* main_frame = webview()->mainFrame();
6282 if (main_frame && main_frame->opener())
6283 main_frame->setOpener(NULL);
6284}
6285
[email protected]efd7e47f2012-10-19 20:37:516286#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:036287bool RenderViewImpl::didTapMultipleTargets(
6288 const WebKit::WebGestureEvent& event,
6289 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:336290 // Never show a disambiguation popup when accessibility is enabled,
6291 // as this interferes with "touch exploration".
6292 if (accessibility_mode_ == AccessibilityModeComplete)
6293 return false;
6294
[email protected]f9526d12012-10-18 01:55:036295 gfx::Rect finger_rect(
6296 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
6297 event.data.tap.width, event.data.tap.height);
6298 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:076299 float new_total_scale =
6300 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
6301 finger_rect, target_rects, GetSize(),
6302 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
6303 device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect);
6304 if (!new_total_scale)
[email protected]f9526d12012-10-18 01:55:036305 return false;
6306
[email protected]70221f02013-01-31 22:17:076307 gfx::Size canvas_size = gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(),
6308 new_total_scale));
[email protected]f9526d12012-10-18 01:55:036309 TransportDIB* transport_dib = NULL;
6310 {
6311 scoped_ptr<skia::PlatformCanvas> canvas(
6312 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
6313 gfx::Rect(canvas_size)));
[email protected]59383c782013-04-17 16:43:276314 if (!canvas)
[email protected]f9526d12012-10-18 01:55:036315 return false;
6316
[email protected]70221f02013-01-31 22:17:076317 // TODO(trchen): Cleanup the device scale factor mess.
6318 // device scale will be applied in WebKit
6319 // --> zoom_rect doesn't include device scale,
6320 // but WebKit will still draw on zoom_rect * device_scale_factor_
6321 canvas->scale(new_total_scale / device_scale_factor_,
6322 new_total_scale / device_scale_factor_);
6323 canvas->translate(-zoom_rect.x() * device_scale_factor_,
6324 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:036325
[email protected]f9526d12012-10-18 01:55:036326 webwidget_->paint(webkit_glue::ToWebCanvas(canvas.get()), zoom_rect,
6327 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
6328 }
[email protected]70221f02013-01-31 22:17:076329
6330 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
6331 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect)));
[email protected]f9526d12012-10-18 01:55:036332 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
[email protected]70221f02013-01-31 22:17:076333 physical_window_zoom_rect,
[email protected]f9526d12012-10-18 01:55:036334 canvas_size,
6335 transport_dib->id()));
6336
6337 return true;
6338}
[email protected]efd7e47f2012-10-19 20:37:516339#endif
[email protected]f9526d12012-10-18 01:55:036340
[email protected]b283d292013-02-21 08:40:346341unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
6342 return history_list_length_;
6343}
6344
[email protected]cc290f902013-03-04 20:06:026345void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
6346 if (enable) {
6347 if (has_focus())
6348 return;
6349 OnSetActive(true);
6350 OnSetFocus(true);
6351 } else {
6352 if (!has_focus())
6353 return;
6354 OnSetFocus(false);
6355 OnSetActive(false);
6356 }
6357}
6358
[email protected]3a1c8a8032013-03-18 22:35:326359void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
[email protected]b54fe452013-06-07 14:01:536360 ViewMsg_Resize_Params params;
6361 params.screen_info = screen_info_;
6362 params.screen_info.deviceScaleFactor = factor;
6363 params.new_size = size();
6364 params.physical_backing_size =
6365 gfx::ToCeiledSize(gfx::ScaleSize(size(), factor));
6366 params.overdraw_bottom_height = 0.f;
6367 params.resizer_rect = WebRect();
6368 params.is_fullscreen = is_fullscreen();
6369 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:326370}
6371
[email protected]eac2b362013-05-22 07:01:456372void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
6373 const gfx::Size& max_size) {
6374 OnEnableAutoResize(min_size, max_size);
6375}
6376
6377void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
6378 OnDisableAutoResize(new_size);
6379}
6380
[email protected]c3bdce152013-07-10 04:56:346381void RenderViewImpl::SetMediaStreamClientForTesting(
[email protected]5e35a8d2013-07-10 19:37:216382 MediaStreamClient* media_stream_client) {
[email protected]c3bdce152013-07-10 04:56:346383 DCHECK(!media_stream_client_);
6384 DCHECK(!web_user_media_client_);
6385 media_stream_client_ = media_stream_client;
6386}
6387
[email protected]f9526d12012-10-18 01:55:036388void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6389 TransportDIB::Handle dib_handle) {
6390 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6391 RenderProcess::current()->ReleaseTransportDIB(dib);
6392}
[email protected]e9ff79c2012-10-19 21:31:266393
[email protected]6fceb912013-02-15 06:24:156394void RenderViewImpl::DidCommitCompositorFrame() {
6395 RenderWidget::DidCommitCompositorFrame();
6396 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
6397}
6398
[email protected]41225fe2013-03-29 05:32:026399void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
6400 if (!urls.empty())
6401 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls));
6402}
6403
6404void RenderViewImpl::DidStopLoadingIcons() {
6405 int icon_types = WebIconURL::TypeFavicon;
6406 if (TouchEnabled())
6407 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
6408
6409 WebVector<WebIconURL> icon_urls =
6410 webview()->mainFrame()->iconURLs(icon_types);
6411
6412 std::vector<FaviconURL> urls;
6413 for (size_t i = 0; i < icon_urls.size(); i++) {
6414 WebURL url = icon_urls[i].iconURL();
6415 if (!url.isEmpty())
6416 urls.push_back(FaviconURL(url,
6417 ToFaviconType(icon_urls[i].iconType())));
6418 }
6419 SendUpdateFaviconURL(urls);
6420}
6421
6422
[email protected]e9ff79c2012-10-19 21:31:266423} // namespace content