blob: e5740cd4273cefac710c001877646c08a1d3d187 [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]e7ca2892012-09-01 00:52:1515#include "base/debug/trace_event.h"
[email protected]b1cf3372011-04-20 21:28:1016#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4917#include "base/lazy_instance.h"
[email protected]cffd7522012-10-23 19:10:5818#include "base/memory/scoped_ptr.h"
[email protected]084c8552012-08-12 22:51:2019#include "base/message_loop_proxy.h"
[email protected]835d7c82010-10-14 04:38:3820#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2821#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5122#include "base/process_util.h"
[email protected]7ddea9802012-02-22 23:08:0523#include "base/string_number_conversions.h"
initial.commit09911bf2008-07-26 23:55:2924#include "base/string_util.h"
[email protected]b9e7c479f2013-04-12 04:33:2425#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4926#include "base/strings/string_split.h"
[email protected]40d11e02013-03-28 17:43:1427#include "base/strings/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2628#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2229#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1030#include "content/common/appcache/appcache_dispatcher.h"
[email protected]14392a52012-05-02 20:28:4431#include "content/common/child_thread.h"
[email protected]127dd582011-03-16 21:32:1032#include "content/common/clipboard_messages.h"
[email protected]37666cf2011-03-13 21:51:4233#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5534#include "content/common/drag_messages.h"
[email protected]16dd6e22012-03-01 19:08:2035#include "content/common/fileapi/file_system_dispatcher.h"
[email protected]c26ad882012-02-07 06:41:2036#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1537#include "content/common/input_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5138#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1039#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0040#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4041#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0542#include "content/common/request_extra_data.h"
[email protected]5fa3a062012-03-21 15:39:3443#include "content/common/socket_stream_handle_data.h"
[email protected]e4495212012-12-06 03:09:1244#include "content/common/ssl_status_serialization.h"
[email protected]778574e2011-03-21 22:03:5045#include "content/common/view_messages.h"
[email protected]4e1eb3392012-05-18 00:08:0546#include "content/common/webmessageportchannel_impl.h"
[email protected]61d271f32013-05-28 04:59:2347#include "content/common_child/fileapi/webfilesystem_callback_adapters.h"
[email protected]e091df82011-10-11 18:13:2148#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0449#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4850#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2951#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5152#include "content/public/common/context_menu_params.h"
[email protected]41225fe2013-03-29 05:32:0253#include "content/public/common/favicon_url.h"
[email protected]8caadeb2011-11-22 02:45:2354#include "content/public/common/file_chooser_params.h"
[email protected]e4495212012-12-06 03:09:1255#include "content/public/common/ssl_status.h"
[email protected]818915cd2012-11-20 13:14:1156#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0357#include "content/public/common/url_constants.h"
[email protected]3b366ae2013-05-17 21:16:5858#include "content/public/common/url_utils.h"
[email protected]d344114c2011-10-01 01:24:3459#include "content/public/renderer/content_renderer_client.h"
[email protected]97f58132012-11-15 20:41:3260#include "content/public/renderer/context_menu_client.h"
[email protected]007733c2011-11-17 00:34:0761#include "content/public/renderer/document_state.h"
[email protected]691aa2f2013-05-28 22:52:0462#include "content/public/renderer/history_item_serialization.h"
[email protected]82ddba1c2011-10-04 00:15:3263#include "content/public/renderer/navigation_state.h"
[email protected]1ecbe862012-10-05 01:29:1464#include "content/public/renderer/password_form_conversion_utils.h"
[email protected]3a034ebb2011-10-03 19:19:4465#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3666#include "content/public/renderer/render_view_visitor.h"
[email protected]4e4646a52013-02-08 07:23:4167#include "content/renderer/accessibility/renderer_accessibility.h"
68#include "content/renderer/accessibility/renderer_accessibility_complete.h"
69#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
[email protected]e6e56752012-08-10 00:46:0670#include "content/renderer/browser_plugin/browser_plugin.h"
71#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]fb325d122012-11-20 23:58:0572#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
[email protected]3175fea2013-05-16 10:57:4873#include "content/renderer/context_menu_params_builder.h"
[email protected]230b7ef2011-03-16 22:30:1974#include "content/renderer/device_orientation_dispatcher.h"
[email protected]70019152012-12-19 11:44:1975#include "content/renderer/devtools/devtools_agent.h"
[email protected]f9526d12012-10-18 01:55:0376#include "content/renderer/disambiguation_popup_helper.h"
[email protected]766a7082012-02-03 23:39:1577#include "content/renderer/dom_automation_controller.h"
[email protected]1910fe82012-05-10 00:04:1078#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]55722152011-03-22 01:33:5379#include "content/renderer/external_popup_menu.h"
[email protected]f8c700ba2013-05-14 08:25:4980#include "content/renderer/fetchers/alt_error_page_resource_fetcher.h"
[email protected]230b7ef2011-03-16 22:30:1981#include "content/renderer/geolocation_dispatcher.h"
[email protected]ea5f70a2013-03-07 12:30:3682#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ba91a792013-02-06 09:48:2883#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]1784b2f2011-11-24 10:53:4884#include "content/renderer/idle_user_detector.h"
[email protected]41225fe2013-03-29 05:32:0285#include "content/renderer/image_loading_helper.h"
[email protected]66fca5bc2013-05-23 06:58:2986#include "content/renderer/ime_event_guard.h"
[email protected]c52b2892012-03-07 11:01:0287#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]92d457802013-04-01 19:18:4988#include "content/renderer/internal_document_state_data.h"
[email protected]07161902011-11-11 09:57:4289#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0290#include "content/renderer/load_progress_tracker.h"
[email protected]4a914882013-01-10 00:43:4891#include "content/renderer/media/audio_device_factory.h"
92#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]273558fb2012-01-12 15:03:5193#include "content/renderer/media/media_stream_dependency_factory.h"
94#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4095#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:4096#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4897#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]ccee4862012-10-03 18:34:2698#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]6392d982013-04-16 16:59:2299#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]4a19be92011-09-22 14:25:02100#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:19101#include "content/renderer/notification_provider.h"
[email protected]6d17f6392012-12-05 05:24:54102#include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
[email protected]6f516082011-03-17 19:15:35103#include "content/renderer/plugin_channel_host.h"
[email protected]227692c52013-05-31 22:43:04104#include "content/renderer/render_frame_impl.h"
[email protected]8704f89b2011-04-15 00:30:05105#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:44106#include "content/renderer/render_thread_impl.h"
[email protected]8d41d7612012-11-14 20:32:19107#include "content/renderer/render_view_impl_params.h"
[email protected]89054502012-06-03 10:29:24108#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:44109#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]b18583c2012-12-18 06:55:27110#include "content/renderer/renderer_date_time_picker.h"
[email protected]663bd9e2011-03-21 01:07:01111#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:20112#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]12a936d2013-05-15 04:55:49113#include "content/renderer/savable_resources.h"
[email protected]64d09222012-05-25 10:10:34114#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]27c521a2013-05-29 20:44:32115#include "content/renderer/stats_collection_controller.h"
116#include "content/renderer/stats_collection_observer.h"
[email protected]86a7d3c2011-09-12 16:45:32117#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19118#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:21119#include "content/renderer/web_ui_extension.h"
120#include "content/renderer/web_ui_extension_data.h"
[email protected]6f516082011-03-17 19:15:35121#include "content/renderer/webplugin_delegate_proxy.h"
122#include "content/renderer/websharedworker_proxy.h"
[email protected]f5961142013-04-17 23:09:42123#include "media/audio/audio_output_device.h"
[email protected]4a914882013-01-10 00:43:48124#include "media/base/audio_renderer_mixer_input.h"
[email protected]f8db8132010-12-03 00:27:49125#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41126#include "media/base/media_switches.h"
[email protected]37136d162012-04-09 23:39:19127#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:18128#include "media/filters/gpu_video_decoder.h"
[email protected]d1ef81d2012-07-24 11:39:36129#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29130#include "net/base/escape.h"
131#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09132#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04133#include "net/http/http_util.h"
[email protected]5c30b5e02013-05-30 03:46:08134#include "third_party/WebKit/public/platform/WebCString.h"
135#include "third_party/WebKit/public/platform/WebDragData.h"
136#include "third_party/WebKit/public/platform/WebFileSystemType.h"
137#include "third_party/WebKit/public/platform/WebHTTPBody.h"
138#include "third_party/WebKit/public/platform/WebImage.h"
139#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
140#include "third_party/WebKit/public/platform/WebPoint.h"
141#include "third_party/WebKit/public/platform/WebRect.h"
142#include "third_party/WebKit/public/platform/WebSize.h"
143#include "third_party/WebKit/public/platform/WebSocketStreamHandle.h"
144#include "third_party/WebKit/public/platform/WebString.h"
145#include "third_party/WebKit/public/platform/WebURL.h"
146#include "third_party/WebKit/public/platform/WebURLError.h"
147#include "third_party/WebKit/public/platform/WebURLRequest.h"
148#include "third_party/WebKit/public/platform/WebURLResponse.h"
149#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]8bd0fe62011-01-17 06:44:37150#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]97516a02012-10-23 18:19:25151#include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h"
[email protected]35134e12013-02-22 20:07:40152#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
[email protected]be2510c02012-05-28 14:52:14154#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]b18583c2012-12-18 06:55:27155#include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserCompletion.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserParams.h"
[email protected]35134e12013-02-22 20:07:40157#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]be2510c02012-05-28 14:52:14158#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37159#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
160#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37161#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
162#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
163#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
164#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
165#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]4b1146bc2012-07-10 18:46:03166#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]8bd0fe62011-01-17 06:44:37167#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37168#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57169#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]69f110d62011-03-17 19:01:14170#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]48861e22013-01-09 00:27:32171#include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37172#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19173#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]35134e12013-02-22 20:07:40174#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36175#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37176#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
177#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
178#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37179#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37180#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
181#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
182#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17183#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]54177cd2013-01-18 17:10:56184#include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptValue.h"
[email protected]8bd0fe62011-01-17 06:44:37185#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]10e5cf12011-04-13 04:10:40186#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]af15bf22013-03-08 01:18:17187#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserGestureIndicator.h"
[email protected]273558fb2012-01-12 15:03:51188#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08189#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
190#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]35134e12013-02-22 20:07:40191#include "third_party/WebKit/Source/WebKit/chromium/public/default/WebRenderTheme.h"
[email protected]f8c700ba2013-05-14 08:25:49192#include "third_party/skia/include/core/SkBitmap.h"
193#include "third_party/skia/include/core/SkPicture.h"
[email protected]1400e6dc2013-04-27 02:36:27194#include "ui/base/ui_base_switches_util.h"
[email protected]08397d52011-02-05 01:53:38195#include "ui/gfx/native_widget_types.h"
196#include "ui/gfx/point.h"
197#include "ui/gfx/rect.h"
[email protected]70221f02013-01-31 22:17:07198#include "ui/gfx/rect_conversions.h"
[email protected]f9526d12012-10-18 01:55:03199#include "ui/gfx/size_conversions.h"
[email protected]4344a3c2013-01-17 23:49:20200#include "ui/shell_dialogs/selected_file_info.h"
[email protected]c4a9e932011-03-05 04:05:55201#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04202#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]bb0e79472012-10-23 04:36:34203#include "webkit/base/file_path_string_conversions.h"
[email protected]c10680312013-05-31 15:22:05204#include "webkit/common/webdropdata.h"
[email protected]b928936b2012-04-13 01:16:16205#include "webkit/dom_storage/dom_storage_types.h"
initial.commit09911bf2008-07-26 23:55:29206#include "webkit/glue/webkit_glue.h"
[email protected]b9fd01ba2012-02-28 01:50:40207#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]191eb3f72010-12-21 06:27:50208#include "webkit/plugins/npapi/plugin_list.h"
[email protected]1b517202012-12-19 17:16:10209#include "webkit/plugins/npapi/plugin_utils.h"
[email protected]191eb3f72010-12-21 06:27:50210#include "webkit/plugins/npapi/webplugin_delegate.h"
211#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
212#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]85a37afd2013-05-30 22:51:15213#include "webkit/renderer/media/webmediaplayer_impl.h"
214#include "webkit/renderer/media/webmediaplayer_ms.h"
215#include "webkit/renderer/media/webmediaplayer_params.h"
[email protected]fab55e72013-05-31 07:06:18216#include "webkit/renderer/webpreferences_renderer.h"
initial.commit09911bf2008-07-26 23:55:29217
[email protected]25fb9b32012-04-27 03:21:55218#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25219#include <cpu-features.h>
220
[email protected]276e8a322013-01-24 01:50:11221#include "content/common/android/device_telephony_info.h"
[email protected]a45c46e2013-03-07 01:04:46222#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]20657a82012-08-21 20:23:03223#include "content/renderer/android/address_detector.h"
224#include "content/renderer/android/content_detector.h"
225#include "content/renderer/android/email_detector.h"
226#include "content/renderer/android/phone_number_detector.h"
[email protected]dbd3d212012-07-13 02:17:22227#include "content/renderer/media/stream_texture_factory_impl_android.h"
[email protected]780fc8242012-09-19 20:28:52228#include "content/renderer/media/webmediaplayer_proxy_impl_android.h"
[email protected]5c30b5e02013-05-30 03:46:08229#include "third_party/WebKit/public/platform/WebFloatPoint.h"
230#include "third_party/WebKit/public/platform/WebFloatRect.h"
[email protected]20657a82012-08-21 20:23:03231#include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31232#include "ui/gfx/rect_f.h"
[email protected]85a37afd2013-05-30 22:51:15233#include "webkit/renderer/media/android/webmediaplayer_android.h"
234#include "webkit/renderer/media/android/webmediaplayer_manager_android.h"
[email protected]25fb9b32012-04-27 03:21:55235#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57236// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57237// * theming
[email protected]990e6222012-11-16 13:31:18238#include "ui/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03239#elif defined(USE_X11)
[email protected]990e6222012-11-16 13:31:18240#include "ui/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33241#elif defined(OS_MACOSX)
242#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57243#endif
244
[email protected]9892b472010-09-16 00:23:42245using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08246using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21247using WebKit::WebApplicationCacheHost;
248using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26249using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41250using WebKit::WebColor;
251using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59252using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44253using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51254using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55255using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28256using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00257using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49258using WebKit::WebDOMEvent;
259using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58260using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25261using WebKit::WebDragOperation;
262using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51263using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51264using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08265using WebKit::WebExternalPopupMenu;
266using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47267using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22268using WebKit::WebFileSystem;
269using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49270using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59271using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48272using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45273using WebKit::WebFrame;
[email protected]3306f262012-09-21 19:20:42274using WebKit::WebGestureEvent;
[email protected]ca948a22009-06-25 19:36:17275using WebKit::WebHistoryItem;
[email protected]132e281a2012-07-31 18:32:44276using WebKit::WebHTTPBody;
[email protected]42054a252011-05-17 18:02:13277using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41278using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50279using WebKit::WebInputElement;
[email protected]3306f262012-09-21 19:20:42280using WebKit::WebInputEvent;
[email protected]3d9689372009-09-10 04:29:17281using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28282using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17283using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26284using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28285using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28286using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51287using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19288using WebKit::WebPageSerializer;
289using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48290using WebKit::WebPeerConnection00Handler;
291using WebKit::WebPeerConnection00HandlerClient;
292using WebKit::WebPeerConnectionHandler;
293using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17294using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36295using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40296using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49297using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09298using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52299using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59300using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51301using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52302using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15303using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40304using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35305using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29306using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17307using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49308using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59309using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42310using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02311using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34312using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34313using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40314using WebKit::WebStorageQuotaCallbacks;
315using WebKit::WebStorageQuotaError;
316using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28317using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51318using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52319using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24320using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28321using WebKit::WebURL;
322using WebKit::WebURLError;
323using WebKit::WebURLRequest;
324using WebKit::WebURLResponse;
[email protected]af15bf22013-03-08 01:18:17325using WebKit::WebUserGestureIndicator;
[email protected]4873c7d2009-07-16 06:36:28326using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03327using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28328using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26329using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26330using appcache::WebApplicationCacheHostImpl;
331using base::Time;
332using base::TimeDelta;
[email protected]e9ff79c2012-10-19 21:31:26333
[email protected]b9fd01ba2012-02-28 01:50:40334using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33335
[email protected]20657a82012-08-21 20:23:03336#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03337using WebKit::WebContentDetectionResult;
[email protected]59363fc92012-09-05 03:46:31338using WebKit::WebFloatPoint;
339using WebKit::WebFloatRect;
[email protected]20657a82012-08-21 20:23:03340using WebKit::WebHitTestResult;
341#endif
342
[email protected]e9ff79c2012-10-19 21:31:26343namespace content {
344
initial.commit09911bf2008-07-26 23:55:29345//-----------------------------------------------------------------------------
346
[email protected]310ebd6302011-10-10 19:06:28347typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49348static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]058561b2012-12-03 06:48:22349typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap;
350static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map =
351 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02352
[email protected]882daa92009-11-05 16:31:31353// Time, in seconds, we delay before sending content state changes (such as form
354// state and scroll position) to the browser. We delay sending changes to avoid
355// spamming the browser.
356// To avoid having tab/session restore require sending a message to get the
357// current content state during tab closing we use a shorter timeout for the
358// foreground renderer. This means there is a small window of time from which
359// content state is modified and not sent to session restore, but this is
360// better than having to wake up all renderers during shutdown.
361static const int kDelaySecondsForContentStateSyncHidden = 5;
362static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29363
[email protected]e99ef6f2011-10-16 01:13:00364static const size_t kExtraCharsBeforeAndAfterSelection = 100;
365
[email protected]0aa55312008-10-17 21:53:08366// The maximum number of popups that can be spawned from one page.
367static const int kMaximumNumberOfUnacknowledgedPopups = 25;
368
[email protected]c514d6372011-08-16 22:54:44369static const float kScalingIncrement = 0.1f;
370
[email protected]47578fa02011-11-02 19:34:41371static const float kScalingIncrementForGesture = 0.01f;
372
[email protected]20657a82012-08-21 20:23:03373#if defined(OS_ANDROID)
374// Delay between tapping in content and launching the associated android intent.
375// Used to allow users see what has been recognized as content.
376static const size_t kContentIntentDelayMilliseconds = 700;
377#endif
378
[email protected]8d41d7612012-11-14 20:32:19379static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
380 NULL;
381
[email protected]726985e22009-06-18 21:09:28382static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
[email protected]bf692cd2012-11-14 19:10:02383 // Replace any occurrences of swappedout:// with about:blank.
[email protected]081dc522013-05-15 04:59:20384 const WebURL& blank_url = GURL(kAboutBlankURL);
[email protected]726985e22009-06-18 21:09:28385 WebVector<WebURL> urls;
386 ds->redirectChain(urls);
387 result->reserve(urls.size());
[email protected]bf692cd2012-11-14 19:10:02388 for (size_t i = 0; i < urls.size(); ++i) {
389 if (urls[i] != GURL(kSwappedOutURL))
390 result->push_back(urls[i]);
391 else
392 result->push_back(blank_url);
393 }
[email protected]726985e22009-06-18 21:09:28394}
395
[email protected]e20b88d2013-04-09 15:28:37396// If |data_source| is non-null and has an InternalDocumentStateData associated
397// with it, the AltErrorPageResourceFetcher is reset.
[email protected]6a8f5112011-05-13 16:38:44398static void StopAltErrorPageFetcher(WebDataSource* data_source) {
399 if (data_source) {
[email protected]e20b88d2013-04-09 15:28:37400 InternalDocumentStateData* internal_data =
401 InternalDocumentStateData::FromDataSource(data_source);
402 if (internal_data)
403 internal_data->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44404 }
405}
406
[email protected]007733c2011-11-17 00:34:07407static bool IsReload(const ViewMsg_Navigate_Params& params) {
408 return
409 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
[email protected]7c16976c2012-08-04 02:38:23410 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
411 params.navigation_type ==
412 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07413}
414
[email protected]b9fd01ba2012-02-28 01:50:40415static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59416 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15417 const WebURLRequest& request) {
418 return request.extraData() ?
419 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59420 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15421}
422
[email protected]b9fd01ba2012-02-28 01:50:40423static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
424 const WebURLResponse& response) {
425 return static_cast<WebURLResponseExtraDataImpl*>(
426 response.extraData());
427}
428
[email protected]2149cc622012-02-14 01:12:12429NOINLINE static void CrashIntentionally() {
430 // NOTE(shess): Crash directly rather than using NOTREACHED() so
431 // that the signature is easier to triage in crash reports.
432 volatile int* zero = NULL;
433 *zero = 0;
434}
435
[email protected]8bf1048012012-02-08 01:22:18436static void MaybeHandleDebugURL(const GURL& url) {
437 if (!url.SchemeIs(chrome::kChromeUIScheme))
438 return;
[email protected]f8a6d732013-03-02 22:46:03439 if (url == GURL(kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12440 CrashIntentionally();
[email protected]f8a6d732013-03-02 22:46:03441 } else if (url == GURL(kChromeUIKillURL)) {
[email protected]8bf1048012012-02-08 01:22:18442 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
[email protected]f8a6d732013-03-02 22:46:03443 } else if (url == GURL(kChromeUIHangURL)) {
[email protected]8bf1048012012-02-08 01:22:18444 for (;;) {
445 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
446 }
[email protected]50f86bc2012-11-01 19:59:13447 } else if (url == GURL(kChromeUIShorthangURL)) {
[email protected]8bf1048012012-02-08 01:22:18448 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
449 }
450}
451
[email protected]fd3238af2012-05-22 18:55:30452// Returns false unless this is a top-level navigation.
453static bool IsTopLevelNavigation(WebFrame* frame) {
454 return frame->parent() == NULL;
455}
456
457// Returns false unless this is a top-level navigation that crosses origins.
458static bool IsNonLocalTopLevelNavigation(const GURL& url,
459 WebFrame* frame,
460 WebNavigationType type) {
461 if (!IsTopLevelNavigation(frame))
462 return false;
463
464 // Navigations initiated within Webkit are not sent out to the external host
465 // in the following cases.
466 // 1. The url scheme is not http/https
467 // 2. The origin of the url and the opener is the same in which case the
468 // opener relationship is maintained.
469 // 3. Reloads/form submits/back forward navigations
470 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
471 return false;
472
473 // Not interested in reloads/form submits/resubmits/back forward navigations.
474 if (type != WebKit::WebNavigationTypeReload &&
475 type != WebKit::WebNavigationTypeFormSubmitted &&
476 type != WebKit::WebNavigationTypeFormResubmitted &&
477 type != WebKit::WebNavigationTypeBackForward) {
478 // The opener relationship between the new window and the parent allows the
479 // new window to script the parent and vice versa. This is not allowed if
480 // the origins of the two domains are different. This can be treated as a
481 // top level navigation and routed back to the host.
482 WebKit::WebFrame* opener = frame->opener();
483 if (!opener) {
484 return true;
485 }
486
487 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
488 return true;
489 }
490 return false;
491}
492
[email protected]38761452012-10-18 16:31:59493static void NotifyTimezoneChange(WebKit::WebFrame* frame) {
494 v8::HandleScope handle_scope;
495 v8::Context::Scope context_scope(frame->mainWorldScriptContext());
496 v8::Date::DateTimeConfigurationChangeNotification();
497 WebKit::WebFrame* child = frame->firstChild();
498 for (; child; child = child->nextSibling())
499 NotifyTimezoneChange(child);
500}
501
[email protected]48861e22013-01-09 00:27:32502static WindowOpenDisposition NavigationPolicyToDisposition(
503 WebNavigationPolicy policy) {
504 switch (policy) {
505 case WebKit::WebNavigationPolicyIgnore:
506 return IGNORE_ACTION;
507 case WebKit::WebNavigationPolicyDownload:
508 return SAVE_TO_DISK;
509 case WebKit::WebNavigationPolicyCurrentTab:
510 return CURRENT_TAB;
511 case WebKit::WebNavigationPolicyNewBackgroundTab:
512 return NEW_BACKGROUND_TAB;
513 case WebKit::WebNavigationPolicyNewForegroundTab:
514 return NEW_FOREGROUND_TAB;
515 case WebKit::WebNavigationPolicyNewWindow:
516 return NEW_WINDOW;
517 case WebKit::WebNavigationPolicyNewPopup:
518 return NEW_POPUP;
519 default:
520 NOTREACHED() << "Unexpected WebNavigationPolicy";
521 return IGNORE_ACTION;
522 }
523}
524
[email protected]d8221b22013-05-23 05:35:43525// Returns true if the device scale is high enough that losing subpixel
526// antialiasing won't have a noticeable effect on text quality.
527static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
528#if defined(OS_ANDROID)
529 // On Android, we never have subpixel antialiasing.
530 return true;
531#else
532 return device_scale_factor > 1.5f;
533#endif
534
535}
536
[email protected]fb854192013-02-06 01:30:04537static bool ShouldUseFixedPositionCompositing(float device_scale_factor) {
538 // Compositing for fixed-position elements is dependent on
[email protected]d8221b22013-05-23 05:35:43539 // device_scale_factor if no flag is set. http://crbug.com/172738
[email protected]fb854192013-02-06 01:30:04540 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
541
542 if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition))
543 return false;
544
545 if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition))
546 return true;
547
[email protected]d8221b22013-05-23 05:35:43548 return DeviceScaleEnsuresTextQuality(device_scale_factor);
549}
550
551static bool ShouldUseTransitionCompositing(float device_scale_factor) {
552 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
553
554 if (command_line.HasSwitch(switches::kDisableCompositingForTransition))
555 return false;
556
557 if (command_line.HasSwitch(switches::kEnableCompositingForTransition))
[email protected]fb854192013-02-06 01:30:04558 return true;
559
[email protected]d8221b22013-05-23 05:35:43560 return DeviceScaleEnsuresTextQuality(device_scale_factor);
[email protected]fb854192013-02-06 01:30:04561}
562
[email protected]41225fe2013-03-29 05:32:02563static FaviconURL::IconType ToFaviconType(WebKit::WebIconURL::Type type) {
564 switch (type) {
565 case WebKit::WebIconURL::TypeFavicon:
566 return FaviconURL::FAVICON;
567 case WebKit::WebIconURL::TypeTouch:
568 return FaviconURL::TOUCH_ICON;
569 case WebKit::WebIconURL::TypeTouchPrecomposed:
570 return FaviconURL::TOUCH_PRECOMPOSED_ICON;
571 case WebKit::WebIconURL::TypeInvalid:
572 return FaviconURL::INVALID_ICON;
573 }
574 return FaviconURL::INVALID_ICON;
575}
576
initial.commit09911bf2008-07-26 23:55:29577///////////////////////////////////////////////////////////////////////////////
578
[email protected]310ebd6302011-10-10 19:06:28579struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26580 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47581 : params(p),
582 completion(c) {
583 }
[email protected]e9ff79c2012-10-19 21:31:26584 FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47585 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
586};
587
[email protected]217690d2012-01-27 07:33:11588namespace {
589
590class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
591 public:
[email protected]82114f52012-03-20 22:53:41592 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11593 : webwidget_(webwidget) {}
594
595 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
596 if (succeeded)
597 webwidget_->didAcquirePointerLock();
598 else
599 webwidget_->didNotAcquirePointerLock();
600 }
601
602 virtual void OnMouseLockLost() OVERRIDE {
603 webwidget_->didLosePointerLock();
604 }
605
606 virtual bool HandleMouseLockedInputEvent(
607 const WebKit::WebMouseEvent &event) OVERRIDE {
608 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
609 return false;
610 }
611
612 private:
613 WebKit::WebWidget* webwidget_;
614};
615
[email protected]86cd9472012-02-03 19:51:05616int64 ExtractPostId(const WebHistoryItem& item) {
617 if (item.isNull())
618 return -1;
619
620 if (item.httpBody().isNull())
621 return -1;
622
623 return item.httpBody().identifier();
624}
625
[email protected]41225fe2013-03-29 05:32:02626bool TouchEnabled() {
627// Based on the definition of chrome::kEnableTouchIcon.
628#if defined(OS_ANDROID)
629 return true;
630#else
631 return false;
632#endif
633}
634
[email protected]c10680312013-05-31 15:22:05635WebDragData WebDropDataToDragData(const WebDropData& drop_data) {
636 std::vector<WebDragData::Item> item_list;
637
638 // These fields are currently unused when dragging into WebKit.
639 DCHECK(drop_data.download_metadata.empty());
640 DCHECK(drop_data.file_contents.empty());
641 DCHECK(drop_data.file_description_filename.empty());
642
643 if (!drop_data.text.is_null()) {
644 WebDragData::Item item;
645 item.storageType = WebDragData::Item::StorageTypeString;
646 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
647 item.stringData = drop_data.text.string();
648 item_list.push_back(item);
649 }
650
651 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
652 // meaningful to write an empty URL to the clipboard?
653 if (!drop_data.url.is_empty()) {
654 WebDragData::Item item;
655 item.storageType = WebDragData::Item::StorageTypeString;
656 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
657 item.stringData = WebString::fromUTF8(drop_data.url.spec());
658 item.title = drop_data.url_title;
659 item_list.push_back(item);
660 }
661
662 if (!drop_data.html.is_null()) {
663 WebDragData::Item item;
664 item.storageType = WebDragData::Item::StorageTypeString;
665 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
666 item.stringData = drop_data.html.string();
667 item.baseURL = drop_data.html_base_url;
668 item_list.push_back(item);
669 }
670
671 for (std::vector<WebDropData::FileInfo>::const_iterator it =
672 drop_data.filenames.begin();
673 it != drop_data.filenames.end();
674 ++it) {
675 WebDragData::Item item;
676 item.storageType = WebDragData::Item::StorageTypeFilename;
677 item.filenameData = it->path;
678 item.displayNameData = it->display_name;
679 item_list.push_back(item);
680 }
681
682 for (std::map<base::string16, base::string16>::const_iterator it =
683 drop_data.custom_data.begin();
684 it != drop_data.custom_data.end();
685 ++it) {
686 WebDragData::Item item;
687 item.storageType = WebDragData::Item::StorageTypeString;
688 item.stringType = it->first;
689 item.stringData = it->second;
690 item_list.push_back(item);
691 }
692
693 WebDragData result;
694 result.initialize();
695 result.setItems(item_list);
696 result.setFilesystemId(drop_data.filesystem_id);
697 return result;
698}
699
[email protected]217690d2012-01-27 07:33:11700} // namespace
701
[email protected]8d41d7612012-11-14 20:32:19702RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
703 : RenderWidget(WebKit::WebPopupTypeNone,
704 params->screen_info,
705 params->swapped_out),
706 webkit_preferences_(params->webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02707 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09708 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02709 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24710 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21711 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02712 opened_by_user_gesture_(true),
713 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24714 page_id_(-1),
715 last_page_id_sent_to_browser_(-1),
[email protected]8d41d7612012-11-14 20:32:19716 next_page_id_(params->next_page_id),
[email protected]3cc72b12010-03-18 23:03:00717 history_list_offset_(-1),
718 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02719 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55720 selection_text_offset_(0),
[email protected]e017c9c2013-02-20 13:44:52721 selection_range_(ui::Range::InvalidRange()),
[email protected]dd6afca2011-08-13 03:44:31722 cached_is_main_frame_pinned_to_left_(false),
723 cached_is_main_frame_pinned_to_right_(false),
724 cached_has_main_frame_horizontal_scrollbar_(false),
725 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]69e797f2013-04-30 01:10:22726 cookie_jar_(this),
[email protected]8a67aa352013-02-20 02:58:29727 notification_provider_(NULL),
[email protected]676126f72011-01-15 00:03:51728 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02729 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34730 speech_recognition_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51731 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51732 media_stream_dispatcher_(NULL),
[email protected]fb325d122012-11-20 23:58:05733 browser_plugin_manager_(NULL),
[email protected]1bc65a42012-04-23 09:31:25734 media_stream_impl_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41735 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43736 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32737 renderer_accessibility_(NULL),
[email protected]7e9c5bb02012-05-14 13:58:31738 java_bridge_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11739 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03740#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:47741 body_background_color_(SK_ColorWHITE),
[email protected]20657a82012-08-21 20:23:03742 expected_content_intent_id_(0),
[email protected]780fc8242012-09-19 20:28:52743 media_player_proxy_(NULL),
[email protected]a7564272013-04-19 14:24:46744#endif
745#if defined(OS_WIN)
746 focused_plugin_id_(-1),
747#endif
[email protected]8a67aa352013-02-20 02:58:29748 enumeration_completion_id_(0),
[email protected]a7564272013-04-19 14:24:46749#if defined(OS_ANDROID)
[email protected]69e797f2013-04-30 01:10:22750 load_progress_tracker_(new LoadProgressTracker(this)),
[email protected]20657a82012-08-21 20:23:03751#endif
[email protected]8d41d7612012-11-14 20:32:19752 session_storage_namespace_id_(params->session_storage_namespace_id),
[email protected]8a67aa352013-02-20 02:58:29753 decrement_shared_popup_at_destruction_(false),
[email protected]ef5e98e2011-12-06 09:49:18754 handling_select_range_(false),
[email protected]c9bc8f12012-12-15 22:20:09755 next_snapshot_id_(0),
[email protected]bf4a2312013-04-23 00:32:11756 allow_partial_swap_(params->allow_partial_swap) {
[email protected]075366912013-02-18 07:13:24757}
758
759void RenderViewImpl::Initialize(RenderViewImplParams* params) {
[email protected]227692c52013-05-31 22:43:04760 main_render_frame_.reset(new RenderFrameImpl(
761 this, params->main_frame_routing_id));
762
[email protected]6d17f6392012-12-05 05:24:54763#if defined(ENABLE_PLUGINS)
764 pepper_helper_.reset(new PepperPluginDelegateImpl(this));
765#else
766 pepper_helper_.reset(new RenderViewPepperHelper());
767#endif
[email protected]8d41d7612012-11-14 20:32:19768 set_throttle_input_events(params->renderer_prefs.throttle_input_events);
769 routing_id_ = params->routing_id;
770 surface_id_ = params->surface_id;
771 if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created)
772 opener_id_ = params->opener_id;
[email protected]676126f72011-01-15 00:03:51773
[email protected]74ce1ad2011-12-16 21:51:46774 // Ensure we start with a valid next_page_id_ from the browser.
775 DCHECK_GE(next_page_id_, 0);
776
[email protected]21b3a6ae2011-11-30 00:45:29777#if defined(ENABLE_NOTIFICATIONS)
778 notification_provider_ = new NotificationProvider(this);
779#else
780 notification_provider_ = NULL;
781#endif
782
[email protected]11fee2332011-03-29 20:36:35783 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11784 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35785
[email protected]20657a82012-08-21 20:23:03786 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
787
[email protected]27c521a2013-05-29 20:44:32788 if (command_line.HasSwitch(switches::kStatsCollectionController))
789 stats_collection_observer_.reset(new StatsCollectionObserver(this));
790
[email protected]20657a82012-08-21 20:23:03791#if defined(OS_ANDROID)
[email protected]276e8a322013-01-24 01:50:11792 content::DeviceTelephonyInfo device_info;
[email protected]20657a82012-08-21 20:23:03793
794 const std::string region_code =
795 command_line.HasSwitch(switches::kNetworkCountryIso)
796 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
[email protected]276e8a322013-01-24 01:50:11797 : device_info.GetNetworkCountryIso();
[email protected]20657a82012-08-21 20:23:03798 content_detectors_.push_back(linked_ptr<ContentDetector>(
799 new AddressDetector()));
800 content_detectors_.push_back(linked_ptr<ContentDetector>(
801 new PhoneNumberDetector(region_code)));
802 content_detectors_.push_back(linked_ptr<ContentDetector>(
803 new EmailDetector()));
804#endif
805
[email protected]8d41d7612012-11-14 20:32:19806 if (params->counter) {
807 shared_popup_counter_ = params->counter;
[email protected]14392a52012-05-02 20:28:44808 // Only count this if it isn't swapped out upon creation.
[email protected]8d41d7612012-11-14 20:32:19809 if (!params->swapped_out)
[email protected]14392a52012-05-02 20:28:44810 shared_popup_counter_->data++;
[email protected]676126f72011-01-15 00:03:51811 decrement_shared_popup_at_destruction_ = true;
812 } else {
813 shared_popup_counter_ = new SharedRenderViewCounter(0);
814 decrement_shared_popup_at_destruction_ = false;
815 }
816
[email protected]380244092011-10-07 17:26:27817 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51818 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47819 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51820 AddRef();
821
822 // If this is a popup, we must wait for the CreatingNew_ACK message before
823 // completing initialization. Otherwise, we can finish it now.
[email protected]6cd7c6b2012-10-25 03:26:23824 if (opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51825 did_show_ = true;
[email protected]fc4404d2012-11-07 19:53:30826 CompleteInit();
[email protected]676126f72011-01-15 00:03:51827 }
828
[email protected]34c61bd52011-05-02 19:38:33829 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]058561b2012-12-03 06:48:22830 g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this));
[email protected]60051ec2012-06-08 22:40:57831 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]fb854192013-02-06 01:30:04832 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
833 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:43834 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
835 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:04836
[email protected]3184f90b2013-05-01 18:17:53837 webkit_glue::ApplyWebPreferences(webkit_preferences_, webview());
[email protected]34c61bd52011-05-02 19:38:33838 webview()->initializeMainFrame(this);
[email protected]edbea622012-11-28 20:39:38839
[email protected]1400e6dc2013-04-27 02:36:27840 if (switches::IsTouchDragDropEnabled())
[email protected]edbea622012-11-28 20:39:38841 webview()->settings()->setTouchDragDropEnabled(true);
842
[email protected]1400e6dc2013-04-27 02:36:27843 if (switches::IsTouchEditingEnabled())
[email protected]47822262013-04-23 17:22:36844 webview()->settings()->setTouchEditingEnabled(true);
845
[email protected]8d41d7612012-11-14 20:32:19846 if (!params->frame_name.empty())
847 webview()->mainFrame()->setName(params->frame_name);
[email protected]34c61bd52011-05-02 19:38:33848
[email protected]8d41d7612012-11-14 20:32:19849 OnSetRendererPrefs(params->renderer_prefs);
[email protected]34c61bd52011-05-02 19:38:33850
[email protected]4fb0f202012-05-30 22:44:53851#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02852 if (!media_stream_dispatcher_)
853 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32854#endif
[email protected]735873d2012-01-25 23:31:02855
[email protected]8f6a3b852011-07-19 16:48:56856 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32857#if defined(OS_MACOSX)
858 new TextInputClientObserver(this);
859#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56860
[email protected]2d7b82c2012-06-01 05:57:50861#if defined(OS_ANDROID)
862 media_player_manager_.reset(
863 new webkit_media::WebMediaPlayerManagerAndroid());
864#endif
865
[email protected]217690d2012-01-27 07:33:11866 // The next group of objects all implement RenderViewObserver, so are deleted
867 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41868 devtools_agent_ = new DevToolsAgent(this);
[email protected]89054502012-06-03 10:29:24869 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]41225fe2013-03-29 05:32:02870
871 new ImageLoadingHelper(this);
[email protected]063afcb2011-09-29 07:54:32872
[email protected]2a84f9d2012-06-05 21:50:43873 // Create renderer_accessibility_ if needed.
[email protected]8d41d7612012-11-14 20:32:19874 OnSetAccessibilityMode(params->accessibility_mode);
[email protected]2a84f9d2012-06-05 21:50:43875
[email protected]1784b2f2011-11-24 10:53:48876 new IdleUserDetector(this);
877
[email protected]766a7082012-02-03 23:39:15878 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:26879 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]27c521a2013-05-29 20:44:32880 if (command_line.HasSwitch(switches::kStatsCollectionController))
881 enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
[email protected]766a7082012-02-03 23:39:15882
[email protected]5b52cd2f712012-03-28 02:12:48883 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05884
[email protected]e9ff79c2012-10-19 21:31:26885 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44886
887 // If we have an opener_id but we weren't created by a renderer, then
888 // it's the browser asking us to set our opener to another RenderView.
[email protected]8d41d7612012-11-14 20:32:19889 if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) {
890 RenderViewImpl* opener_view = FromRoutingID(params->opener_id);
[email protected]f546640b2012-05-15 00:03:49891 if (opener_view)
892 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44893 }
894
895 // If we are initially swapped out, navigate to kSwappedOutURL.
896 // This ensures we are in a unique origin that others cannot script.
897 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:37898 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29899}
900
[email protected]310ebd6302011-10-10 19:06:28901RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03902 history_page_ids_.clear();
903
[email protected]0aa55312008-10-17 21:53:08904 if (decrement_shared_popup_at_destruction_)
905 shared_popup_counter_->data--;
906
[email protected]a1128322009-10-06 18:38:46907 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47908 while (!file_chooser_completions_.empty()) {
909 if (file_chooser_completions_.front()->completion) {
910 file_chooser_completions_.front()->completion->didChooseFile(
911 WebVector<WebString>());
912 }
913 file_chooser_completions_.pop_front();
914 }
[email protected]a1128322009-10-06 18:38:46915
[email protected]8ed1d3f2013-02-20 11:45:55916#if defined(OS_ANDROID)
917 // The date/time picker client is both a scoped_ptr member of this class and
918 // a RenderViewObserver. Reset it to prevent double deletion.
919 date_time_picker_client_.reset();
920#endif
921
[email protected]60c42a8c72009-10-09 04:08:59922#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22923 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49924 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59925 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
926 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22927 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
928 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
929 it != routing_id_views->end(); ++it)
930 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59931#endif
[email protected]676126f72011-01-15 00:03:51932
[email protected]310ebd6302011-10-10 19:06:28933 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51934 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59935}
936
937/*static*/
[email protected]310ebd6302011-10-10 19:06:28938RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31939 ViewMap* views = g_view_map.Pointer();
940 ViewMap::iterator it = views->find(webview);
941 return it == views->end() ? NULL : it->second;
942}
943
944/*static*/
[email protected]e9ff79c2012-10-19 21:31:26945RenderView* RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28946 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31947}
948
949/*static*/
[email protected]640e303c2012-12-05 01:36:07950RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) {
951 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
952 RoutingIDViewMap::iterator it = views->find(routing_id);
953 return it == views->end() ? NULL : it->second;
954}
955
956/*static*/
957RenderView* RenderView::FromRoutingID(int routing_id) {
958 return RenderViewImpl::FromRoutingID(routing_id);
959}
960
961/*static*/
[email protected]e9ff79c2012-10-19 21:31:26962void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49963 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59964 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
965 if (!visitor->Visit(it->second))
966 return;
967 }
968}
969
970/*static*/
[email protected]310ebd6302011-10-10 19:06:28971RenderViewImpl* RenderViewImpl::Create(
[email protected]0aa55312008-10-17 21:53:08972 int32 opener_id,
[email protected]e9ff79c2012-10-19 21:31:26973 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08974 const WebPreferences& webkit_prefs,
975 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34976 int32 routing_id,
[email protected]227692c52013-05-31 22:43:04977 int32 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:56978 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26979 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46980 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44981 bool is_renderer_created,
982 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41983 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04984 const WebKit::WebScreenInfo& screen_info,
[email protected]34bb3ac2013-03-08 02:41:28985 AccessibilityMode accessibility_mode,
986 bool allow_partial_swap) {
initial.commit09911bf2008-07-26 23:55:29987 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]8d41d7612012-11-14 20:32:19988 RenderViewImplParams params(
[email protected]676126f72011-01-15 00:03:51989 opener_id,
990 renderer_prefs,
991 webkit_prefs,
992 counter,
993 routing_id,
[email protected]227692c52013-05-31 22:43:04994 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:56995 surface_id,
[email protected]676126f72011-01-15 00:03:51996 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46997 frame_name,
[email protected]14392a52012-05-02 20:28:44998 is_renderer_created,
999 swapped_out,
[email protected]6fd35b72012-03-01 19:46:411000 next_page_id,
[email protected]842f10652012-06-06 01:54:041001 screen_info,
[email protected]34bb3ac2013-03-08 02:41:281002 accessibility_mode,
1003 allow_partial_swap);
[email protected]075366912013-02-18 07:13:241004 RenderViewImpl* render_view = NULL;
[email protected]8d41d7612012-11-14 20:32:191005 if (g_create_render_view_impl)
[email protected]075366912013-02-18 07:13:241006 render_view = g_create_render_view_impl(&params);
1007 else
1008 render_view = new RenderViewImpl(&params);
1009 render_view->Initialize(&params);
1010 return render_view;
[email protected]8d41d7612012-11-14 20:32:191011}
1012
1013// static
1014void RenderViewImpl::InstallCreateHook(
1015 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) {
1016 CHECK(!g_create_render_view_impl);
1017 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291018}
1019
[email protected]310ebd6302011-10-10 19:06:281020void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511021 observers_.AddObserver(observer);
1022}
1023
[email protected]310ebd6302011-10-10 19:06:281024void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1025 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511026 observers_.RemoveObserver(observer);
1027}
1028
[email protected]310ebd6302011-10-10 19:06:281029WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:261030 return static_cast<WebKit::WebView*>(webwidget());
1031}
1032
[email protected]c42de732013-02-16 06:26:311033void RenderViewImpl::PluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:421034 base::ProcessId plugin_pid) {
1035 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path, plugin_pid));
initial.commit09911bf2008-07-26 23:55:291036}
1037
[email protected]310ebd6302011-10-10 19:06:281038void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261039 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:301040 // If the renderer is visible, set initial visibility and focus state.
1041 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:341042#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:301043 delegate->SetContainerVisibility(true);
1044 if (webview() && webview()->isActive())
1045 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:341046#endif
[email protected]49232292010-09-03 19:07:301047 }
[email protected]784ea1ab2010-09-18 00:02:341048 // Plugins start assuming the content has focus (so that they work in
1049 // environments where RenderView isn't hosting them), so we always have to
1050 // set the initial state. See webplugin_delegate_impl.h for details.
1051 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:261052}
1053
[email protected]310ebd6302011-10-10 19:06:281054void RenderViewImpl::UnregisterPluginDelegate(
1055 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261056 plugin_delegates_.erase(delegate);
1057}
[email protected]d8fd6fa2010-02-01 15:54:261058
[email protected]310ebd6302011-10-10 19:06:281059bool RenderViewImpl::GetPluginInfo(const GURL& url,
1060 const GURL& page_url,
1061 const std::string& mime_type,
1062 webkit::WebPluginInfo* plugin_info,
1063 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:081064 bool found = false;
1065 Send(new ViewHostMsg_GetPluginInfo(
1066 routing_id_, url, page_url, mime_type, &found, plugin_info,
1067 actual_mime_type));
1068 return found;
1069}
1070
[email protected]7a1ec28a2012-03-28 21:10:241071void RenderViewImpl::TransferActiveWheelFlingAnimation(
1072 const WebKit::WebActiveWheelFlingParameters& params) {
1073 if (webview())
1074 webview()->transferActiveWheelFlingAnimation(params);
1075}
1076
[email protected]8fe8f742012-06-14 00:36:081077bool RenderViewImpl::HasIMETextFocus() {
1078 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
1079}
1080
[email protected]310ebd6302011-10-10 19:06:281081bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:271082 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:271083 if (main_frame)
[email protected]e9ff79c2012-10-19 21:31:261084 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:261085
[email protected]676126f72011-01-15 00:03:511086 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
1087 RenderViewObserver* observer;
1088 while ((observer = it.GetNext()) != NULL)
1089 if (observer->OnMessageReceived(message))
1090 return true;
[email protected]b2abac72009-02-26 12:39:281091
[email protected]a95986a82010-12-24 06:19:281092 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:401093 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:281094 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
[email protected]c084330e02013-04-27 01:08:151095 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy)
1096 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut)
1097 IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete)
1098 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
1099 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
1100 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste)
1101 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
1102 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo)
1103 IPC_MESSAGE_HANDLER(InputMsg_Replace, OnReplace)
1104 IPC_MESSAGE_HANDLER(InputMsg_ReplaceMisspelling, OnReplaceMisspelling)
1105 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
1106 OnScrollFocusedEditableNodeIntoRect)
1107 IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll)
1108 IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange)
1109 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
1110 OnSetEditCommandsForNextKeyEvent)
1111 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo)
1112 IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect)
initial.commit09911bf2008-07-26 23:55:291113 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
1114 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:561115 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
[email protected]25bcc8f2013-01-09 02:49:251116 IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName)
[email protected]45a599062012-09-07 20:09:061117 IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets,
1118 OnSetEditableSelectionOffsets)
1119 IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText,
1120 OnSetCompositionFromExistingText)
1121 IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete,
1122 OnExtendSelectionAndDelete)
initial.commit09911bf2008-07-26 23:55:291123 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
1124 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491125 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:171126 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:171127 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:411128 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:541129 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1130 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291131 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181132 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1133 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:291134 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:491135 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:481136 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:551137 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1138 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1139 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1140 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
1141 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
1142 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1143 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:451144 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291145 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291146 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1147 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]38761452012-10-18 16:31:591148 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone)
initial.commit09911bf2008-07-26 23:55:291149 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:511150 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1151 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291152 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:041153 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:151154 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:291155 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1156 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:081157 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1158 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:001159 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:161160 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141161 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251162 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1163 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471164 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341165 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101166 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1167 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511168 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561169 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:171170 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
1171 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:361172 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341173 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]a0c7153e2009-12-09 14:36:331174 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1175 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:241176 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:421177 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
1178 OnPpapiBrokerChannelCreated)
[email protected]d8415ad92012-08-23 14:40:501179 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
1180 OnPpapiBrokerPermissionResult)
[email protected]18d5be92011-07-25 18:00:191181 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1182 OnGetAllSavableResourceLinksForCurrentPage)
1183 IPC_MESSAGE_HANDLER(
1184 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1185 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]521b2482011-01-15 00:10:101186 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]47822262013-04-23 17:22:361187 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]f0557932011-01-25 20:20:511188 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:191189 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
1190 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:181191 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]da816272013-05-15 21:31:171192#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7f3c7af2011-10-20 22:52:511193 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]da816272013-05-15 21:31:171194#endif
[email protected]2a84f9d2012-06-05 21:50:431195 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]7cc78902012-12-06 02:32:261196 IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener)
[email protected]55750b32012-09-21 14:05:031197#if defined(OS_ANDROID)
[email protected]c084330e02013-04-27 01:08:151198 IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult,
[email protected]55750b32012-09-21 14:05:031199 OnActivateNearestFindResult)
1200 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
1201 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
[email protected]9b7d11e2012-10-08 19:24:141202 IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView,
1203 OnUndoScrollFocusedEditableNodeIntoRect)
[email protected]452b4a92013-03-28 21:24:381204 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState,
1205 OnUpdateTopControlsState)
[email protected]55750b32012-09-21 14:05:031206#elif defined(OS_MACOSX)
[email protected]c084330e02013-04-27 01:08:151207 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]55750b32012-09-21 14:05:031208 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1209 OnPluginImeCompositionCompleted)
1210 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1211 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1212 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1213 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1214#endif
[email protected]f9526d12012-10-18 01:55:031215 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB,
1216 OnReleaseDisambiguationPopupDIB)
[email protected]c9bc8f12012-12-15 22:20:091217 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted,
1218 OnWindowSnapshotCompleted)
[email protected]9e1ad4b2011-08-14 16:49:191219
initial.commit09911bf2008-07-26 23:55:291220 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281221 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291222 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401223
1224 if (!msg_is_ok) {
1225 // The message had a handler, but its deserialization failed.
1226 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281227 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401228 }
1229
[email protected]a95986a82010-12-24 06:19:281230 return handled;
initial.commit09911bf2008-07-26 23:55:291231}
1232
[email protected]310ebd6302011-10-10 19:06:281233void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:181234 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291235 if (!webview())
1236 return;
1237
[email protected]440a0e52011-09-13 17:38:581238 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1239
[email protected]007733c2011-11-17 00:34:071240 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031241
1242 // If this is a stale back/forward (due to a recent navigation the browser
1243 // didn't know about), ignore it.
1244 if (IsBackForwardToStaleEntry(params, is_reload))
1245 return;
1246
[email protected]992db4c2011-05-12 15:37:151247 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281248 if (is_swapped_out_) {
1249 // We marked the view as hidden when swapping the view out, so be sure to
1250 // reset the visibility state before navigating to the new URL.
1251 webview()->setVisibilityState(visibilityState(), false);
[email protected]890b06ca2012-12-13 21:07:361252
1253 // If this is an attempt to reload while we are swapped out, we should not
1254 // reload swappedout://, but the previous page, which is stored in
1255 // params.state. Setting is_reload to false will treat this like a back
1256 // navigation to accomplish that.
1257 is_reload = false;
1258
[email protected]992db4c2011-05-12 15:37:151259 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281260 }
[email protected]992db4c2011-05-12 15:37:151261
[email protected]60d6cca2013-04-30 08:47:131262 if (params.should_clear_history_list) {
1263 CHECK_EQ(params.pending_history_list_offset, -1);
1264 CHECK_EQ(params.current_history_list_offset, -1);
1265 CHECK_EQ(params.current_history_list_length, 0);
1266 }
[email protected]3cc72b12010-03-18 23:03:001267 history_list_offset_ = params.current_history_list_offset;
1268 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031269 if (history_list_length_ >= 0)
1270 history_page_ids_.resize(history_list_length_, -1);
1271 if (params.pending_history_list_offset >= 0 &&
1272 params.pending_history_list_offset < history_list_length_)
1273 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001274
[email protected]e9ff79c2012-10-19 21:31:261275 GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291276
[email protected]3027cf02013-01-24 08:16:581277 WebFrame* frame = webview()->mainFrame();
1278 if (!params.frame_to_navigate.empty()) {
1279 frame = webview()->findFrameByName(
1280 WebString::fromUTF8(params.frame_to_navigate));
1281 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate;
1282 }
1283
1284 if (is_reload && frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291285 // We cannot reload if we do not have any history state. This happens, for
1286 // example, when recovering from a crash. Our workaround here is a bit of
1287 // a hack since it means that reload after a crashed tab does not cause an
1288 // end-to-end cache validation.
1289 is_reload = false;
1290 }
1291
[email protected]3d2fd592012-11-30 02:05:501292 pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params));
[email protected]48a5c772011-04-18 23:50:501293
[email protected]04d3c6e2009-05-22 17:00:131294 // If we are reloading, then WebKit will use the history state of the current
1295 // page, so we should just ignore any given history state. Otherwise, if we
1296 // have history state, then we need to navigate to it, which corresponds to a
1297 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551298 if (is_reload) {
[email protected]7c16976c2012-08-04 02:38:231299 bool reload_original_url =
1300 (params.navigation_type ==
1301 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]ecbf10d2010-02-18 13:03:291302 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021303 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]7c16976c2012-08-04 02:38:231304
1305 if (reload_original_url)
[email protected]3027cf02013-01-24 08:16:581306 frame->reloadWithOverrideURL(params.url, true);
[email protected]7c16976c2012-08-04 02:38:231307 else
[email protected]3027cf02013-01-24 08:16:581308 frame->reload(ignore_cache);
[email protected]691aa2f2013-05-28 22:52:041309 } else if (params.page_state.IsValid()) {
[email protected]04d3c6e2009-05-22 17:00:131310 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581311 DCHECK_NE(params.page_id, -1);
[email protected]691aa2f2013-05-28 22:52:041312 WebHistoryItem item = PageStateToHistoryItem(params.page_state);
[email protected]bf692cd2012-11-14 19:10:021313 if (!item.isNull()) {
1314 // Ensure we didn't save the swapped out URL in UpdateState, since the
1315 // browser should never be telling us to navigate to swappedout://.
1316 CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL));
[email protected]3027cf02013-01-24 08:16:581317 frame->loadHistoryItem(item);
[email protected]bf692cd2012-11-14 19:10:021318 }
[email protected]d1ef81d2012-07-24 11:39:361319 } else if (!params.base_url_for_data_url.is_empty()) {
1320 // A loadData request with a specified base URL.
1321 std::string mime_type, charset, data;
1322 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
[email protected]3027cf02013-01-24 08:16:581323 frame->loadData(
[email protected]d1ef81d2012-07-24 11:39:361324 WebData(data.c_str(), data.length()),
1325 WebString::fromUTF8(mime_type),
1326 WebString::fromUTF8(charset),
1327 params.base_url_for_data_url,
1328 params.history_url_for_data_url,
1329 false);
1330 } else {
1331 CHECK(false) <<
1332 "Invalid URL passed: " << params.url.possibly_invalid_spec();
1333 }
[email protected]04d3c6e2009-05-22 17:00:131334 } else {
1335 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281336 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291337
[email protected]e6f546c32009-07-01 17:12:551338 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231339 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131340
[email protected]3027cf02013-01-24 08:16:581341 if (frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551342 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131343
[email protected]445e1042011-12-03 21:03:151344 if (params.referrer.url.is_valid()) {
1345 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1346 params.referrer.policy,
1347 params.url,
1348 WebString::fromUTF8(params.referrer.url.spec()));
1349 if (!referrer.isEmpty())
1350 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281351 }
[email protected]04d3c6e2009-05-22 17:00:131352
[email protected]52c68652010-12-07 17:47:041353 if (!params.extra_headers.empty()) {
1354 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1355 params.extra_headers.end(), "\n");
1356 i.GetNext(); ) {
1357 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1358 WebString::fromUTF8(i.values()));
1359 }
1360 }
[email protected]132e281a2012-07-31 18:32:441361
1362 if (params.is_post) {
1363 request.setHTTPMethod(WebString::fromUTF8("POST"));
1364
1365 // Set post data.
1366 WebHTTPBody http_body;
1367 http_body.initialize();
1368 http_body.appendData(WebData(
1369 reinterpret_cast<const char*>(
1370 &params.browser_initiated_post_data.front()),
1371 params.browser_initiated_post_data.size()));
1372 request.setHTTPBody(http_body);
1373 }
1374
[email protected]3027cf02013-01-24 08:16:581375 frame->loadRequest(request);
[email protected]198a95d62013-04-11 00:44:211376
1377 // If this is a cross-process navigation, the browser process will send
1378 // along the proper navigation start value.
1379 if (!params.browser_navigation_start.is_null() &&
1380 frame->provisionalDataSource()) {
1381 // browser_navigation_start is likely before this process existed, so we
1382 // can't use InterProcessTimeTicksConverter. Instead, the best we can do
1383 // is just ensure we don't report a bogus value in the future.
1384 base::TimeTicks navigation_start = std::min(
1385 base::TimeTicks::Now(), params.browser_navigation_start);
1386 double navigation_start_seconds =
1387 (navigation_start - base::TimeTicks()).InSecondsF();
1388 frame->provisionalDataSource()->setNavigationStartTime(
1389 navigation_start_seconds);
1390 }
[email protected]c0588052008-10-27 23:01:501391 }
1392
[email protected]77f17a82009-05-21 04:42:541393 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071394 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291395}
1396
[email protected]310ebd6302011-10-10 19:06:281397bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031398 const ViewMsg_Navigate_Params& params,
1399 bool is_reload) {
1400 // Make sure this isn't a back/forward to an entry we have already cropped
1401 // or replaced from our history, before the browser knew about it. If so,
1402 // a new navigation has committed in the mean time, and we can ignore this.
[email protected]691aa2f2013-05-28 22:52:041403 bool is_back_forward = !is_reload && params.page_state.IsValid();
[email protected]d466b8a2011-07-15 21:48:031404
1405 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1406 // restoring from a previous session. We'll update our state in OnNavigate.
1407 if (!is_back_forward || history_list_length_ <= 0)
1408 return false;
1409
1410 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1411
1412 // Check for whether the forward history has been cropped due to a recent
1413 // navigation the browser didn't know about.
1414 if (params.pending_history_list_offset >= history_list_length_)
1415 return true;
1416
1417 // Check for whether this entry has been replaced with a new one.
1418 int expected_page_id =
1419 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441420 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1421 if (params.page_id < expected_page_id)
1422 return true;
1423
1424 // Otherwise we've removed an earlier entry and should have shifted all
1425 // entries left. For now, it's ok to lazily update the list.
1426 // TODO(creis): Notify all live renderers when we remove entries from
1427 // the front of the list, so that we don't hit this case.
1428 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1429 }
[email protected]d466b8a2011-07-15 21:48:031430
1431 return false;
1432}
1433
initial.commit09911bf2008-07-26 23:55:291434// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281435void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441436 if (webview()) {
1437 WebFrame* main_frame = webview()->mainFrame();
1438 // Stop the alt error page fetcher. If we let it continue it may complete
1439 // and cause RenderViewHostManager to swap to this RenderView, even though
1440 // it may no longer be active.
1441 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1442 StopAltErrorPageFetcher(main_frame->dataSource());
1443 main_frame->stopLoading();
1444 }
initial.commit09911bf2008-07-26 23:55:291445}
1446
[email protected]ecbf10d2010-02-18 13:03:291447// Reload current focused frame.
1448// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281449void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291450 if (webview() && webview()->focusedFrame()) {
1451 // We always obey the cache (ignore_cache=false) here.
1452 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1453 // a cache-ignoring reload of the frame.
1454 webview()->focusedFrame()->reload(false);
1455 }
[email protected]1dda4022010-01-28 18:24:561456}
1457
[email protected]310ebd6302011-10-10 19:06:281458void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271459 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291460}
1461
[email protected]310ebd6302011-10-10 19:06:281462void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291463 // Check if there is a targeturl waiting to be sent.
1464 if (target_url_status_ == TARGET_PENDING) {
1465 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1466 pending_target_url_));
1467 }
1468
1469 target_url_status_ = TARGET_NONE;
1470}
1471
[email protected]310ebd6302011-10-10 19:06:281472void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291473 if (!webview())
1474 return;
1475
[email protected]5d4e36d2013-02-15 15:18:201476 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101477 WebNode current_node = context_menu_node_.isNull() ?
1478 GetFocusedNode() : context_menu_node_;
[email protected]f6b1856b2011-06-29 22:02:531479 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
[email protected]6dd17a8a2013-05-01 05:50:101480 current_node);
initial.commit09911bf2008-07-26 23:55:291481}
1482
[email protected]c084330e02013-04-27 01:08:151483void RenderViewImpl::OnCut() {
[email protected]a954bf72009-09-12 07:30:351484 if (!webview())
1485 return;
1486
[email protected]c084330e02013-04-27 01:08:151487 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101488 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"),
1489 GetFocusedNode());
[email protected]a954bf72009-09-12 07:30:351490}
[email protected]c084330e02013-04-27 01:08:151491
1492void RenderViewImpl::OnDelete() {
1493 if (!webview())
1494 return;
1495
[email protected]6dd17a8a2013-05-01 05:50:101496 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"),
1497 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151498}
1499
1500void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1501 const std::string& value) {
1502 if (!webview() || !webview()->focusedFrame())
1503 return;
1504
1505 webview()->focusedFrame()->executeCommand(
1506 WebString::fromUTF8(name), WebString::fromUTF8(value));
1507}
1508
1509void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1510 if (!webview())
1511 return;
1512
1513 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_));
1514
1515 webview()->focusedFrame()->moveCaretSelectionTowardsWindowPoint(point);
1516}
[email protected]a954bf72009-09-12 07:30:351517
[email protected]310ebd6302011-10-10 19:06:281518void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291519 if (!webview())
1520 return;
1521
[email protected]5d4e36d2013-02-15 15:18:201522 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101523 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"),
1524 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291525}
1526
[email protected]44bf7002011-10-16 02:46:151527void RenderViewImpl::OnPasteAndMatchStyle() {
1528 if (!webview())
1529 return;
1530
[email protected]5d4e36d2013-02-15 15:18:201531 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]44bf7002011-10-16 02:46:151532 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101533 WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode());
[email protected]44bf7002011-10-16 02:46:151534}
1535
[email protected]c084330e02013-04-27 01:08:151536void RenderViewImpl::OnRedo() {
1537 if (!webview())
1538 return;
1539
[email protected]6dd17a8a2013-05-01 05:50:101540 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"),
1541 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151542}
1543
[email protected]310ebd6302011-10-10 19:06:281544void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291545 if (!webview())
1546 return;
1547
[email protected]1ff7a032010-02-03 02:46:031548 WebFrame* frame = webview()->focusedFrame();
1549 if (!frame->hasSelection())
1550 frame->selectWordAroundCaret();
[email protected]2365c642013-02-12 19:16:471551
[email protected]1ff7a032010-02-03 02:46:031552 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291553}
1554
[email protected]2365c642013-02-12 19:16:471555void RenderViewImpl::OnReplaceMisspelling(const string16& text) {
1556 if (!webview())
1557 return;
1558
1559 WebFrame* frame = webview()->focusedFrame();
1560 if (!frame->hasSelection())
1561 return;
1562
1563 frame->replaceMisspelledRange(text);
1564}
1565
[email protected]c084330e02013-04-27 01:08:151566void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1567 const gfx::Rect& rect) {
1568 WebKit::WebNode node = GetFocusedNode();
1569 if (!node.isNull()) {
1570 if (IsEditableNode(node)) {
1571 webview()->saveScrollAndScaleState();
1572 webview()->scrollFocusedNodeIntoRect(rect);
1573 }
1574 }
[email protected]25bcc8f2013-01-09 02:49:251575}
1576
[email protected]310ebd6302011-10-10 19:06:281577void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291578 if (!webview())
1579 return;
1580
[email protected]5d4e36d2013-02-15 15:18:201581 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]26aa0482009-09-30 16:55:271582 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101583 WebString::fromUTF8("SelectAll"), GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291584}
1585
[email protected]c084330e02013-04-27 01:08:151586void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1587 const gfx::Point& end) {
1588 if (!webview())
1589 return;
1590
1591 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1592
1593 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1594 webview()->focusedFrame()->selectRange(start, end);
1595}
1596
1597void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1598 const EditCommands& edit_commands) {
1599 edit_commands_ = edit_commands;
1600}
1601
1602void RenderViewImpl::OnUndo() {
1603 if (!webview())
1604 return;
1605
[email protected]6dd17a8a2013-05-01 05:50:101606 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"),
1607 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151608}
1609
[email protected]45a599062012-09-07 20:09:061610void RenderViewImpl::OnUnselect() {
1611 if (!webview())
1612 return;
1613
[email protected]5d4e36d2013-02-15 15:18:201614 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101615 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
1616 GetFocusedNode());
[email protected]45a599062012-09-07 20:09:061617}
1618
[email protected]c084330e02013-04-27 01:08:151619#if defined(OS_MACOSX)
1620void RenderViewImpl::OnCopyToFindPboard() {
1621 if (!webview())
1622 return;
1623
1624 // Since the find pasteboard supports only plain text, this can be simpler
1625 // than the |OnCopy()| case.
1626 WebFrame* frame = webview()->focusedFrame();
1627 if (frame->hasSelection()) {
1628 string16 selection = frame->selectionAsText();
1629 RenderThread::Get()->Send(
1630 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
1631 }
1632}
1633#endif
1634
1635void RenderViewImpl::OnSetName(const std::string& name) {
1636 if (!webview())
1637 return;
1638
1639 webview()->mainFrame()->setName(WebString::fromUTF8(name));
1640}
1641
[email protected]45a599062012-09-07 20:09:061642void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) {
[email protected]5d4e36d2013-02-15 15:18:201643 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]66fca5bc2013-05-23 06:58:291644 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061645 webview()->setEditableSelectionOffsets(start, end);
1646}
1647
1648void RenderViewImpl::OnSetCompositionFromExistingText(
1649 int start, int end,
1650 const std::vector<WebKit::WebCompositionUnderline>& underlines) {
1651 if (!webview())
1652 return;
[email protected]66fca5bc2013-05-23 06:58:291653 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061654 webview()->setCompositionFromExistingText(start, end, underlines);
1655}
1656
1657void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) {
1658 if (!webview())
1659 return;
[email protected]66fca5bc2013-05-23 06:58:291660 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061661 webview()->extendSelectionAndDelete(before, after);
1662}
1663
[email protected]310ebd6302011-10-10 19:06:281664void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1665 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441666 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191667 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441668 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191669
1670 // Generate the new list.
1671 std::vector<int32> new_history_page_ids(history_length, -1);
1672 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1673 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1674 continue;
1675 new_history_page_ids.push_back(history_page_ids_[i]);
1676 }
1677 new_history_page_ids.swap(history_page_ids_);
1678
1679 // Update indexes.
1680 history_list_length_ = history_page_ids_.size();
1681 history_list_offset_ = history_list_length_ - 1;
1682}
1683
1684
[email protected]310ebd6302011-10-10 19:06:281685void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291686 if (!webview())
1687 return;
[email protected]26aa0482009-09-30 16:55:271688 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291689}
1690
[email protected]54ca3ca892011-06-07 21:14:541691#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281692void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331693 if (!webview())
1694 return;
1695 if (in_live_resize)
1696 webview()->willStartLiveResize();
1697 else
1698 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541699}
1700#endif
1701
[email protected]9b7d11e2012-10-08 19:24:141702#if defined(OS_ANDROID)
1703void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1704 const WebNode node = GetFocusedNode();
1705 if (!node.isNull() && IsEditableNode(node))
1706 webview()->restoreScrollAndScaleState();
1707}
1708#endif
1709
initial.commit09911bf2008-07-26 23:55:291710///////////////////////////////////////////////////////////////////////////////
1711
1712// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281713void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451714 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291715 DCHECK(ds);
1716
[email protected]726985e22009-06-18 21:09:281717 const WebURLRequest& request = ds->request();
1718 const WebURLRequest& original_request = ds->originalRequest();
1719 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291720
[email protected]007733c2011-11-17 00:34:071721 DocumentState* document_state = DocumentState::FromDataSource(ds);
1722 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:371723 InternalDocumentStateData* internal_data =
1724 InternalDocumentStateData::FromDocumentState(document_state);
initial.commit09911bf2008-07-26 23:55:291725
1726 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281727 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291728 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051729 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291730 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071731 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191732 params.socket_address.set_host(response.remoteIPAddress().utf8());
1733 params.socket_address.set_port(response.remotePort());
[email protected]e07ddafe2013-03-05 21:03:361734 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
1735 if (extra_data) {
1736 params.was_fetched_via_proxy = extra_data->was_fetched_via_proxy();
1737 }
[email protected]af15bed2010-08-25 21:12:091738 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e20b88d2013-04-09 15:28:371739 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291740
1741 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311742 params.url = GetLoadingUrl(frame);
[email protected]809be032013-03-19 01:56:561743 DCHECK(!is_swapped_out_ || params.url == GURL(kSwappedOutURL));
initial.commit09911bf2008-07-26 23:55:291744
[email protected]5f9b8712011-11-23 08:55:571745 if (frame->document().baseURL() != params.url)
1746 params.base_url = frame->document().baseURL();
1747
[email protected]726985e22009-06-18 21:09:281748 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241749 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041750 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291751
[email protected]e20b88d2013-04-09 15:28:371752 params.searchable_form_url = internal_data->searchable_form_url();
1753 params.searchable_form_encoding = internal_data->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291754
[email protected]e20b88d2013-04-09 15:28:371755 const PasswordForm* password_form_data = document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291756 if (password_form_data)
1757 params.password_form = *password_form_data;
1758
1759 params.gesture = navigation_gesture_;
1760 navigation_gesture_ = NavigationGestureUnknown;
1761
[email protected]0f38dc4552011-02-25 11:24:001762 // Make navigation state a part of the FrameNavigate message so that commited
1763 // entry had it at all times.
[email protected]691aa2f2013-05-28 22:52:041764 WebHistoryItem item = frame->currentHistoryItem();
1765 if (item.isNull()) {
1766 item.initialize();
1767 item.setURLString(request.url().spec().utf16());
[email protected]0f38dc4552011-02-25 11:24:001768 }
[email protected]691aa2f2013-05-28 22:52:041769 params.page_state = HistoryItemToPageState(item);
[email protected]0f38dc4552011-02-25 11:24:001770
[email protected]dd7daa82009-08-10 05:46:451771 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291772 // Top-level navigation.
1773
[email protected]d00a7972012-08-07 06:09:581774 // Reset the zoom limits in case a plugin had changed them previously. This
1775 // will also call us back which will cause us to send a message to
1776 // update WebContentsImpl.
1777 webview()->zoomLimitsChanged(
[email protected]e9ff79c2012-10-19 21:31:261778 WebView::zoomFactorToZoomLevel(kMinimumZoomFactor),
1779 WebView::zoomFactorToZoomLevel(kMaximumZoomFactor));
[email protected]d00a7972012-08-07 06:09:581780
[email protected]b75b8292010-10-01 07:28:251781 // Set zoom level, but don't do it for full-page plugin since they don't use
1782 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011783 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541784 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251785 if (webview()->mainFrame()->document().isPluginDocument()) {
1786 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251787 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251788 } else {
1789 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251790 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251791 }
1792
[email protected]f85f0702010-01-30 09:31:011793 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511794 // This zoom level was merely recorded transiently for this load. We can
1795 // erase it now. If at some point we reload this page, the browser will
1796 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011797 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511798 }
1799
initial.commit09911bf2008-07-26 23:55:291800 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551801 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291802
[email protected]daa8c58e2009-06-15 17:21:101803 params.transition = navigation_state->transition_type();
[email protected]e9ff79c2012-10-19 21:31:261804 if (!PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291805 // If the main frame does a load, it should not be reported as a subframe
1806 // navigation. This can occur in the following case:
1807 // 1. You're on a site with frames.
1808 // 2. You do a subframe navigation. This is stored with transition type
1809 // MANUAL_SUBFRAME.
1810 // 3. You navigate to some non-frame site, say, google.com.
1811 // 4. You navigate back to the page from step 2. Since it was initially
1812 // MANUAL_SUBFRAME, it will be that same transition type here.
1813 // We don't want that, because any navigation that changes the toplevel
1814 // frame should be tracked as a toplevel navigation (this allows us to
1815 // update the URL bar, etc).
[email protected]e9ff79c2012-10-19 21:31:261816 params.transition = PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291817 }
1818
initial.commit09911bf2008-07-26 23:55:291819 // If we have a valid consumed client redirect source,
1820 // the page contained a client redirect (meta refresh, document.loc...),
1821 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151822 if (completed_client_redirect_src_.url.is_valid()) {
1823 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291824 params.referrer = completed_client_redirect_src_;
[email protected]e9ff79c2012-10-19 21:31:261825 params.transition = static_cast<PageTransition>(
1826 params.transition | PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291827 } else {
1828 // Bug 654101: the referrer will be empty on https->http transitions. It
1829 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151830 params.referrer = Referrer(GURL(
1831 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:591832 GetReferrerPolicyFromRequest(frame, original_request));
initial.commit09911bf2008-07-26 23:55:291833 }
1834
[email protected]726985e22009-06-18 21:09:281835 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051836 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291837 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051838 params.post_id = ExtractPostId(item);
1839 }
initial.commit09911bf2008-07-26 23:55:291840
[email protected]bf70edce2012-06-20 22:32:221841 // Send the user agent override back.
[email protected]e20b88d2013-04-09 15:28:371842 params.is_overriding_user_agent = internal_data->is_overriding_user_agent();
[email protected]bf70edce2012-06-20 22:32:221843
[email protected]7c16976c2012-08-04 02:38:231844 // Track the URL of the original request.
1845 params.original_request_url = original_request.url();
1846
[email protected]60d6cca2013-04-30 08:47:131847 params.history_list_was_cleared =
1848 navigation_state->history_list_was_cleared();
1849
[email protected]c2a797d2009-09-21 16:46:321850 // Save some histogram data so we can compute the average memory used per
1851 // page load of the glyphs.
1852 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1853 webkit_glue::GetGlyphPageCount());
1854
[email protected]15cf526b2010-02-12 06:33:491855 // This message needs to be sent before any of allowScripts(),
1856 // allowImages(), allowPlugins() is called for the new page, so that when
1857 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1858 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291859 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1860 } else {
1861 // Subframe navigation: the type depends on whether this navigation
1862 // generated a new session history entry. When they do generate a session
1863 // history entry, it means the user initiated the navigation and we should
1864 // mark it as such. This test checks if this is the first time UpdateURL
1865 // has been called since WillNavigateToURL was called to initiate the load.
1866 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]e9ff79c2012-10-19 21:31:261867 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291868 else
[email protected]e9ff79c2012-10-19 21:31:261869 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291870
[email protected]60d6cca2013-04-30 08:47:131871 DCHECK(!navigation_state->history_list_was_cleared());
1872 params.history_list_was_cleared = false;
1873
initial.commit09911bf2008-07-26 23:55:291874 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1875 }
1876
1877 last_page_id_sent_to_browser_ =
1878 std::max(last_page_id_sent_to_browser_, page_id_);
1879
1880 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101881 // we don't want the transition type to persist. Just clear it.
[email protected]e9ff79c2012-10-19 21:31:261882 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291883}
1884
1885// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281886void RenderViewImpl::UpdateTitle(WebFrame* frame,
1887 const string16& title,
1888 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461889 // Ignore all but top level navigations.
1890 if (frame->parent())
1891 return;
1892
[email protected]e9ff79c2012-10-19 21:31:261893 string16 shortened_title = title.substr(0, kMaxTitleChars);
[email protected]a49e10b2011-08-01 23:57:461894 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1895 title_direction));
initial.commit09911bf2008-07-26 23:55:291896}
1897
[email protected]310ebd6302011-10-10 19:06:281898void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1899 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291900 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271901 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291902 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301903 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291904 last_encoding_name_ = encoding_name;
1905
[email protected]e38f40152008-09-12 23:08:301906 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291907 }
1908}
1909
[email protected]e15f680732010-11-23 22:30:201910// Sends the last committed session history state to the browser so it will be
1911// saved before we navigate to a new page. This must be called *before* the
1912// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281913void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291914 // If we have a valid page ID at this point, then it corresponds to the page
1915 // we are navigating away from. Otherwise, this is the first navigation, so
1916 // there is no past session history to record.
1917 if (page_id_ == -1)
1918 return;
1919
[email protected]ca948a22009-06-25 19:36:171920 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271921 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051922 SendUpdateState(item);
1923}
1924
1925void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171926 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291927 return;
[email protected]ca948a22009-06-25 19:36:171928
[email protected]e9ff79c2012-10-19 21:31:261929 // Don't send state updates for kSwappedOutURL.
1930 if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051931 return;
1932
[email protected]ca948a22009-06-25 19:36:171933 Send(new ViewHostMsg_UpdateState(
[email protected]691aa2f2013-05-28 22:52:041934 routing_id_, page_id_, HistoryItemToPageState(item)));
initial.commit09911bf2008-07-26 23:55:291935}
1936
[email protected]310ebd6302011-10-10 19:06:281937void RenderViewImpl::OpenURL(WebFrame* frame,
1938 const GURL& url,
[email protected]445e1042011-12-03 21:03:151939 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281940 WebNavigationPolicy policy) {
[email protected]e2caa032012-11-15 23:29:181941 ViewHostMsg_OpenURL_Params params;
1942 params.url = url;
1943 params.referrer = referrer;
1944 params.disposition = NavigationPolicyToDisposition(policy);
1945 params.frame_id = frame->identifier();
[email protected]b4c09692012-12-13 19:15:461946 WebDataSource* ds = frame->provisionalDataSource();
1947 if (ds) {
1948 params.is_cross_site_redirect = ds->isClientRedirect();
1949 } else {
1950 params.is_cross_site_redirect = false;
1951 }
[email protected]e2caa032012-11-15 23:29:181952
1953 Send(new ViewHostMsg_OpenURL(routing_id_, params));
[email protected]3d9689372009-09-10 04:29:171954}
1955
[email protected]79dbc662009-09-04 05:42:511956// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291957
[email protected]310ebd6302011-10-10 19:06:281958void RenderViewImpl::LoadNavigationErrorPage(
1959 WebFrame* frame,
1960 const WebURLRequest& failed_request,
1961 const WebURLError& error,
1962 const std::string& html,
1963 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581964 std::string alt_html;
1965 const std::string* error_html;
1966
1967 if (!html.empty()) {
1968 error_html = &html;
1969 } else {
[email protected]e9ff79c2012-10-19 21:31:261970 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:531971 frame, failed_request, error, &alt_html, NULL);
[email protected]d7b175e2011-10-11 15:31:581972 error_html = &alt_html;
1973 }
1974
1975 frame->loadHTMLString(*error_html,
[email protected]e9ff79c2012-10-19 21:31:261976 GURL(kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251977 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551978 replace);
initial.commit09911bf2008-07-26 23:55:291979}
1980
[email protected]e9ff79c2012-10-19 21:31:261981bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281982 const string16& message,
1983 const string16& default_value,
1984 const GURL& frame_url,
1985 string16* result) {
initial.commit09911bf2008-07-26 23:55:291986 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411987 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291988 if (!result)
1989 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291990
[email protected]12636df2009-09-28 22:32:211991 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1992 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291993 return success;
1994}
1995
[email protected]310ebd6302011-10-10 19:06:281996bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571997 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1998 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1999 // it is particularly important that we do not call willEnterModalLoop as
2000 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:442001 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2002 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:572003
2004 message->EnableMessagePumping(); // Runs a nested message loop.
2005 return Send(message);
2006}
2007
[email protected]c9bc8f12012-12-15 22:20:092008void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) {
2009 int id = next_snapshot_id_++;
2010 pending_snapshots_.insert(std::make_pair(id, callback));
2011 Send(new ViewHostMsg_GetWindowSnapshot(routing_id_, id));
2012}
2013
2014void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id,
2015 const gfx::Size& size, const std::vector<unsigned char>& png) {
2016 PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id);
2017 DCHECK(it != pending_snapshots_.end());
2018 it->second.Run(size, png);
2019 pending_snapshots_.erase(it);
2020}
2021
[email protected]48c9cf2d2009-09-16 16:47:522022// WebKit::WebViewClient ------------------------------------------------------
2023
[email protected]916dfb62012-03-05 03:39:372024WebView* RenderViewImpl::createView(
2025 WebFrame* creator,
2026 const WebURLRequest& request,
2027 const WebWindowFeatures& features,
2028 const WebString& frame_name,
2029 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:522030 // Check to make sure we aren't overloading on popups.
2031 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2032 return NULL;
2033
[email protected]8ab04652010-06-12 02:47:262034 ViewHostMsg_CreateWindow_Params params;
2035 params.opener_id = routing_id_;
[email protected]af15bf22013-03-08 01:18:172036 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]8ab04652010-06-12 02:47:262037 params.window_container_type = WindowFeaturesToContainerType(features);
2038 params.session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:212039 if (frame_name != "_blank")
2040 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112041 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:412042 params.opener_url = creator->document().url();
[email protected]7f48b712013-01-25 01:48:302043 GURL security_url(creator->document().securityOrigin().toString().utf8());
2044 if (!security_url.is_valid())
2045 security_url = GURL();
2046 params.opener_security_origin = security_url;
[email protected]f92ce2b2012-03-06 18:02:592047 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
2048 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:112049 if (!request.isNull())
2050 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:262051
[email protected]48c9cf2d2009-09-16 16:47:522052 int32 routing_id = MSG_ROUTING_NONE;
[email protected]227692c52013-05-31 22:43:042053 int32 main_frame_routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:562054 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:342055 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:522056
[email protected]380244092011-10-07 17:26:272057 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:262058 new ViewHostMsg_CreateWindow(params,
2059 &routing_id,
[email protected]227692c52013-05-31 22:43:042060 &main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562061 &surface_id,
[email protected]8ab04652010-06-12 02:47:262062 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212063 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522064 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522065
[email protected]af15bf22013-03-08 01:18:172066 WebUserGestureIndicator::consumeUserGesture();
[email protected]c59262422012-11-30 21:20:522067
[email protected]3184f90b2013-05-01 18:17:532068 WebPreferences transferred_preferences = webkit_preferences_;
[email protected]9115d5f2013-03-24 04:37:412069
2070 // Unless accelerated compositing has been explicitly disabled from the
2071 // command line (e.g. via the blacklist or about:flags) re-enable it for
2072 // new views that get spawned by this view. This gets around the issue that
2073 // background extension pages disable accelerated compositing via web prefs
2074 // but can themselves spawn a visible render view which should be allowed
2075 // use gpu acceleration.
2076 if (!webkit_preferences_.accelerated_compositing_enabled) {
2077 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2078 if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
2079 transferred_preferences.accelerated_compositing_enabled = true;
2080 }
2081
[email protected]310ebd6302011-10-10 19:06:282082 RenderViewImpl* view = RenderViewImpl::Create(
[email protected]310ebd6302011-10-10 19:06:282083 routing_id_,
2084 renderer_preferences_,
[email protected]9115d5f2013-03-24 04:37:412085 transferred_preferences,
[email protected]310ebd6302011-10-10 19:06:282086 shared_popup_counter_,
2087 routing_id,
[email protected]227692c52013-05-31 22:43:042088 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562089 surface_id,
[email protected]310ebd6302011-10-10 19:06:282090 cloned_session_storage_namespace_id,
[email protected]5cef23d2013-02-27 13:11:212091 string16(), // WebCore will take care of setting the correct name.
[email protected]14392a52012-05-02 20:28:442092 true,
2093 false,
[email protected]6fd35b72012-03-01 19:46:412094 1,
[email protected]842f10652012-06-06 01:54:042095 screen_info_,
[email protected]34bb3ac2013-03-08 02:41:282096 accessibility_mode_,
2097 allow_partial_swap_);
[email protected]8ab04652010-06-12 02:47:262098 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522099
[email protected]007a848b2009-10-26 15:55:462100 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:592101 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:462102
[email protected]48c9cf2d2009-09-16 16:47:522103 // Copy over the alternate error page URL so we can have alt error pages in
2104 // the new render view (we don't need the browser to send the URL back down).
2105 view->alternate_error_page_url_ = alternate_error_page_url_;
2106
2107 return view->webview();
2108}
2109
[email protected]310ebd6302011-10-10 19:06:282110WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:412111 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:042112 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:522113 return widget->webwidget();
2114}
2115
[email protected]310ebd6302011-10-10 19:06:282116WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:082117 const WebPopupMenuInfo& popup_menu_info,
2118 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:272119 // An IPC message is sent to the browser to build and display the actual
2120 // popup. The user could have time to click a different select by the time
2121 // the popup is shown. In that case external_popup_menu_ is non NULL.
2122 // By returning NULL in that case, we instruct WebKit to cancel that new
2123 // popup. So from the user perspective, only the first one will show, and
2124 // will have to close the first one before another one can be shown.
[email protected]59383c782013-04-17 16:43:272125 if (external_popup_menu_)
[email protected]8de2f882012-05-30 00:32:272126 return NULL;
[email protected]caf706f2010-10-26 17:54:082127 external_popup_menu_.reset(
2128 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2129 return external_popup_menu_.get();
2130}
2131
[email protected]310ebd6302011-10-10 19:06:282132RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:522133 webkit::ppapi::PluginInstance* plugin) {
[email protected]ebd71962012-12-20 02:56:552134#if defined(ENABLE_PLUGINS)
[email protected]d91233b7e2011-03-29 20:33:532135 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:422136 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:412137 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:532138 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]bee6eb72012-07-26 03:47:322139 routing_id_, plugin, active_url, screen_info_);
[email protected]79c7bed2010-09-14 22:28:392140 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:562141 return widget;
[email protected]ebd71962012-12-20 02:56:552142#else // defined(ENABLE_PLUGINS)
2143 NOTREACHED() << "CreatePepperFullscreenContainer: plugins disabled";
2144 return NULL;
2145#endif
[email protected]79c7bed2010-09-14 22:28:392146}
2147
[email protected]310ebd6302011-10-10 19:06:282148WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
2149 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:162150 CHECK(session_storage_namespace_id_ !=
2151 dom_storage::kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:102152 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342153}
2154
[email protected]310ebd6302011-10-10 19:06:282155void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:522156 const WebConsoleMessage& message, const WebString& source_name,
2157 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:082158 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:512159 switch (message.level) {
[email protected]80ac8942013-01-30 22:53:222160 case WebConsoleMessage::LevelDebug:
[email protected]d09df4b2011-04-11 19:01:082161 log_severity = logging::LOG_VERBOSE;
2162 break;
2163 case WebConsoleMessage::LevelLog:
2164 log_severity = logging::LOG_INFO;
2165 break;
2166 case WebConsoleMessage::LevelWarning:
2167 log_severity = logging::LOG_WARNING;
2168 break;
2169 case WebConsoleMessage::LevelError:
2170 log_severity = logging::LOG_ERROR;
2171 break;
2172 default:
2173 NOTREACHED();
2174 }
2175
[email protected]48c9cf2d2009-09-16 16:47:522176 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:082177 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:312178 message.text,
[email protected]48c9cf2d2009-09-16 16:47:522179 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:312180 source_name));
[email protected]48c9cf2d2009-09-16 16:47:522181}
2182
[email protected]310ebd6302011-10-10 19:06:282183void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:112184 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2185 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:522186}
2187
[email protected]310ebd6302011-10-10 19:06:282188WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512189 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022190}
2191
[email protected]310ebd6302011-10-10 19:06:282192bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:122193 const WebString& path,
2194 WebFileChooserCompletion* chooser_completion) {
2195 int id = enumeration_completion_id_++;
2196 enumeration_completions_[id] = chooser_completion;
2197 return Send(new ViewHostMsg_EnumerateDirectory(
2198 routing_id_,
2199 id,
[email protected]bb0e79472012-10-23 04:36:342200 webkit_base::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:122201}
2202
[email protected]4b1146bc2012-07-10 18:46:032203void RenderViewImpl::initializeHelperPluginWebFrame(
2204 WebKit::WebHelperPlugin* plugin) {
2205 plugin->initializeFrame(this);
2206}
2207
[email protected]310ebd6302011-10-10 19:06:282208void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522209 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:142210 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:522211 return;
2212 }
2213
2214 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:522215
2216 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:312217
2218 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:522219}
2220
[email protected]310ebd6302011-10-10 19:06:282221void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522222 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:142223 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:522224 return;
2225 }
2226
2227 is_loading_ = false;
2228
2229 // NOTE: For now we're doing the safest thing, and sending out notification
2230 // when done loading. This currently isn't an issue as the favicon is only
2231 // displayed when done loading. Ideally we would send notification when
2232 // finished parsing the head, but webkit doesn't support that yet.
2233 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:522234 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2235
[email protected]90109412010-12-15 17:14:242236 if (load_progress_tracker_ != NULL)
2237 load_progress_tracker_->DidStopLoading();
2238
[email protected]41225fe2013-03-29 05:32:022239 DidStopLoadingIcons();
2240
[email protected]93b9d692011-04-13 00:44:312241 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:522242}
2243
[email protected]310ebd6302011-10-10 19:06:282244void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
2245 double load_progress) {
[email protected]90109412010-12-15 17:14:242246 if (load_progress_tracker_ != NULL)
2247 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2248}
2249
[email protected]550b0c92013-02-04 05:09:152250void RenderViewImpl::didCancelCompositionOnSelectionChange() {
2251 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2252}
2253
[email protected]310ebd6302011-10-10 19:06:282254void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:082255 if (!handling_input_event_ && !handling_select_range_)
[email protected]5d4e36d2013-02-15 15:18:202256 return;
[email protected]d4cff272011-05-02 15:46:012257
[email protected]fca52022012-04-03 17:00:502258 if (is_empty_selection)
2259 selection_text_.clear();
2260
[email protected]b781ff282011-08-20 06:19:362261 SyncSelectionIfRequired();
[email protected]5d4e36d2013-02-15 15:18:202262 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]04fc9482009-09-18 22:13:032263}
2264
[email protected]310ebd6302011-10-10 19:06:282265void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122266 const std::string& name = UTF16ToUTF8(command_name);
2267 if (StartsWithASCII(name, "Move", true) ||
2268 StartsWithASCII(name, "Insert", true) ||
2269 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032270 return;
[email protected]f1a29a02011-10-06 23:08:442271 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:032272}
2273
[email protected]310ebd6302011-10-10 19:06:282274bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:102275 if (edit_commands_.empty())
2276 return false;
2277
[email protected]26aa0482009-09-30 16:55:272278 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102279 if (!frame)
2280 return false;
2281
2282 EditCommands::iterator it = edit_commands_.begin();
2283 EditCommands::iterator end = edit_commands_.end();
2284
[email protected]507b33ea2009-09-29 03:56:512285 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102286 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332287 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2288 // key (but it's the exception). Once one edit command is not executed, it
2289 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102290 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2291 WebString::fromUTF8(it->value)))
2292 break;
[email protected]507b33ea2009-09-29 03:56:512293 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102294 }
2295
[email protected]507b33ea2009-09-29 03:56:512296 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102297}
2298
[email protected]da8543762012-03-20 08:52:202299WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
2300 WebKit::WebColorChooserClient* client,
2301 const WebKit::WebColor& initial_color) {
2302 RendererWebColorChooserImpl* color_chooser =
2303 new RendererWebColorChooserImpl(this, client);
2304 color_chooser->Open(static_cast<SkColor>(initial_color));
2305 return color_chooser;
2306}
2307
[email protected]310ebd6302011-10-10 19:06:282308bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:352309 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472310 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352311 // Do not open the file dialog in a hidden RenderView.
2312 if (is_hidden())
2313 return false;
[email protected]e9ff79c2012-10-19 21:31:262314 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262315 if (params.directory)
[email protected]e9ff79c2012-10-19 21:31:262316 ipc_params.mode = FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:262317 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:262318 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502319 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:262320 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262321 else
[email protected]e9ff79c2012-10-19 21:31:262322 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472323 ipc_params.title = params.title;
2324 ipc_params.default_file_name =
[email protected]bb0e79472012-10-23 04:36:342325 webkit_base::WebStringToFilePath(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322326 ipc_params.accept_types.reserve(params.acceptTypes.size());
2327 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2328 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]2fdf2352012-11-01 19:23:022329#if defined(OS_ANDROID)
2330 ipc_params.capture = params.capture;
2331#endif
[email protected]cdaf8d02010-03-30 19:52:472332
2333 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462334}
2335
[email protected]269f86d2011-12-07 02:43:472336void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2337 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262338 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412339 message,
2340 string16(),
[email protected]b6cb3a842011-06-24 18:28:412341 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522342 NULL);
2343}
2344
[email protected]269f86d2011-12-07 02:43:472345bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2346 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262347 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412348 message,
2349 string16(),
[email protected]b6cb3a842011-06-24 18:28:412350 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522351 NULL);
2352}
2353
[email protected]269f86d2011-12-07 02:43:472354bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2355 const WebString& message,
2356 const WebString& default_value,
2357 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412358 string16 result;
[email protected]e9ff79c2012-10-19 21:31:262359 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412360 message,
2361 default_value,
[email protected]b6cb3a842011-06-24 18:28:412362 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522363 &result);
2364 if (ok)
[email protected]4f5ce842011-05-27 19:34:412365 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522366 return ok;
2367}
2368
[email protected]310ebd6302011-10-10 19:06:282369bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522370 WebFrame* frame, const WebString& message) {
[email protected]ab533826b2013-05-10 23:54:562371 bool is_reload = false;
2372 WebDataSource* ds = frame->provisionalDataSource();
2373 if (ds)
2374 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
2375 return runModalBeforeUnloadDialog(frame, is_reload, message);
2376}
2377
2378bool RenderViewImpl::runModalBeforeUnloadDialog(
2379 WebFrame* frame, bool is_reload, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152380 // If we are swapping out, we have already run the beforeunload handler.
2381 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2382 // at all, to avoid running it twice.
2383 if (is_swapped_out_)
2384 return true;
2385
[email protected]48c9cf2d2009-09-16 16:47:522386 bool success = false;
2387 // This is an ignored return value, but is included so we can accept the same
2388 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412389 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212390 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322391 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412392 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522393 return success;
2394}
2395
[email protected]310ebd6302011-10-10 19:06:282396void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442397 WebFrame* frame, const WebContextMenuData& data) {
[email protected]3175fea2013-05-16 10:57:482398 ContextMenuParams params = ContextMenuParamsBuilder::Build(data);
[email protected]7fcd9b72011-07-27 16:52:372399
[email protected]329266d2012-09-27 06:20:572400 // Plugins, e.g. PDF, don't currently update the render view when their
2401 // selected text changes, but the context menu params do contain the updated
2402 // selection. If that's the case, update the render view's state just prior
2403 // to showing the context menu.
2404 // TODO(asvitkine): http://crbug.com/152432
[email protected]432c9a72013-02-27 01:51:032405 if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_,
2406 selection_text_offset_,
2407 selection_range_,
2408 params)) {
[email protected]329266d2012-09-27 06:20:572409 selection_text_ = params.selection_text;
2410 // TODO(asvitkine): Text offset and range is not available in this case.
2411 selection_text_offset_ = 0;
2412 selection_range_ = ui::Range(0, selection_text_.length());
2413 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2414 selection_text_,
2415 selection_text_offset_,
2416 selection_range_));
2417 }
2418
[email protected]7fcd9b72011-07-27 16:52:372419 // frame is NULL if invoked by BlockedPlugin.
2420 if (frame)
2421 params.frame_id = frame->identifier();
2422
[email protected]e9ff79c2012-10-19 21:31:262423 // Serializing a GURL longer than kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272424 // it. We replace it with an empty GURL so the appropriate items are disabled
2425 // in the context menu.
2426 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2427 // data encoded images. We should have a way to save them.
[email protected]e9ff79c2012-10-19 21:31:262428 if (params.src_url.spec().size() > kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272429 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102430 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412431
2432#if defined(OS_ANDROID)
2433 gfx::Rect start_rect;
2434 gfx::Rect end_rect;
2435 GetSelectionBounds(&start_rect, &end_rect);
[email protected]326a2342013-02-15 15:47:512436 params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom());
2437 params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom());
[email protected]44daa3b2012-09-27 19:26:412438#endif
2439
[email protected]c27324b2009-11-19 22:44:292440 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]b2324b092012-11-01 10:34:112441
2442 FOR_EACH_OBSERVER(
2443 RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data));
[email protected]79e37442009-10-09 18:17:442444}
2445
[email protected]310ebd6302011-10-10 19:06:282446void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522447}
2448
[email protected]310ebd6302011-10-10 19:06:282449void RenderViewImpl::UpdateTargetURL(const GURL& url,
2450 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582451 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522452 if (latest_url == target_url_)
2453 return;
[email protected]163f8242009-10-30 20:19:552454
[email protected]48c9cf2d2009-09-16 16:47:522455 // Tell the browser to display a destination link.
2456 if (target_url_status_ == TARGET_INFLIGHT ||
2457 target_url_status_ == TARGET_PENDING) {
2458 // If we have a request in-flight, save the URL to be sent when we
2459 // receive an ACK to the in-flight request. We can happily overwrite
2460 // any existing pending sends.
2461 pending_target_url_ = latest_url;
2462 target_url_status_ = TARGET_PENDING;
2463 } else {
[email protected]e9ff79c2012-10-19 21:31:262464 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:412465 // see |ParamTraits<GURL>|.
[email protected]e9ff79c2012-10-19 21:31:262466 if (latest_url.possibly_invalid_spec().size() > kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:412467 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522468 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2469 target_url_ = latest_url;
2470 target_url_status_ = TARGET_INFLIGHT;
2471 }
2472}
2473
[email protected]70221f02013-01-31 22:17:072474gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
2475 const gfx::RectF& rect) const {
2476 gfx::RectF window_rect = rect;
2477 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
2478 return window_rect;
2479}
2480
[email protected]310ebd6302011-10-10 19:06:282481void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]a183fb82012-12-14 04:46:222482 // No need to update state if no page has committed yet.
2483 if (page_id_ == -1)
2484 return;
2485
[email protected]882daa92009-11-05 16:31:312486 int delay;
2487 if (send_content_state_immediately_)
2488 delay = 0;
2489 else if (is_hidden())
2490 delay = kDelaySecondsForContentStateSyncHidden;
2491 else
2492 delay = kDelaySecondsForContentStateSync;
2493
2494 if (nav_state_sync_timer_.IsRunning()) {
2495 // The timer is already running. If the delay of the timer maches the amount
2496 // we want to delay by, then return. Otherwise stop the timer so that it
2497 // gets started with the right delay.
2498 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2499 return;
2500 nav_state_sync_timer_.Stop();
2501 }
2502
[email protected]d323a172011-09-02 18:23:022503 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282504 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312505}
2506
[email protected]310ebd6302011-10-10 19:06:282507void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552508 mouse_over_url_ = GURL(url);
2509 UpdateTargetURL(mouse_over_url_, focus_url_);
2510}
2511
[email protected]310ebd6302011-10-10 19:06:282512void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552513 focus_url_ = GURL(url);
2514 UpdateTargetURL(focus_url_, mouse_over_url_);
2515}
2516
[email protected]0407e422012-05-18 19:51:252517void RenderViewImpl::startDragging(WebFrame* frame,
2518 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282519 WebDragOperationsMask mask,
2520 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:242521 const WebPoint& webImageOffset) {
[email protected]b67151d2012-05-25 23:23:242522 WebDropData drop_data(data);
2523 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:242524 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:552525 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242526 drop_data,
[email protected]c27ae592010-03-18 15:24:412527 mask,
[email protected]976127072012-05-10 20:08:112528 image.getSkBitmap(),
[email protected]41d86852012-11-07 12:23:242529 imageOffset,
2530 possible_drag_event_info_));
[email protected]48c9cf2d2009-09-16 16:47:522531}
2532
[email protected]310ebd6302011-10-10 19:06:282533bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452534 return renderer_preferences_.can_accept_load_drops;
2535}
2536
[email protected]310ebd6302011-10-10 19:06:282537void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522538 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2539}
2540
[email protected]310ebd6302011-10-10 19:06:282541void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522542 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2543}
2544
[email protected]310ebd6302011-10-10 19:06:282545void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512546 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072547
[email protected]38b592902011-04-16 02:08:422548 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492549}
2550
[email protected]572a6ca2012-10-11 19:38:012551void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2552 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2553}
2554
[email protected]169d4282011-11-30 19:33:592555void RenderViewImpl::didUpdateLayout() {
2556 // We don't always want to set up a timer, only if we've been put in that
2557 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2558 // message.
2559 if (!send_preferred_size_changes_ || !webview())
2560 return;
2561
2562 if (check_preferred_size_timer_.IsRunning())
2563 return;
2564 check_preferred_size_timer_.Start(FROM_HERE,
2565 TimeDelta::FromMilliseconds(0), this,
2566 &RenderViewImpl::CheckPreferredSize);
2567}
2568
[email protected]310ebd6302011-10-10 19:06:282569void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522570 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2571}
2572
[email protected]310ebd6302011-10-10 19:06:282573int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002574 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522575}
2576
[email protected]310ebd6302011-10-10 19:06:282577int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002578 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522579}
2580
[email protected]310ebd6302011-10-10 19:06:282581void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322582 const WebAccessibilityObject& obj,
2583 WebAccessibilityNotification notification) {
[email protected]2a84f9d2012-06-05 21:50:432584 if (renderer_accessibility_) {
2585 renderer_accessibility_->HandleWebAccessibilityNotification(
2586 obj, notification);
2587 }
[email protected]063afcb2011-09-29 07:54:322588}
2589
[email protected]310ebd6302011-10-10 19:06:282590void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142591 const WebString& value) {
2592 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2593 key.utf8(),
2594 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262595}
2596
[email protected]79dbc662009-09-04 05:42:512597// WebKit::WebWidgetClient ----------------------------------------------------
2598
[email protected]310ebd6302011-10-10 19:06:282599void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122600 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2601 // we won't have to test for user gesture anymore and we can
2602 // move that code back to render_widget.cc
[email protected]af15bf22013-03-08 01:18:172603 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302604 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442605 Send(new ViewHostMsg_Focus(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122606 }
2607}
2608
[email protected]310ebd6302011-10-10 19:06:282609void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122610 // TODO(jcivelli): see TODO above in didFocus().
[email protected]af15bf22013-03-08 01:18:172611 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302612 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442613 Send(new ViewHostMsg_Blur(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122614 }
2615}
2616
initial.commit09911bf2008-07-26 23:55:292617// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282618// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292619// point to dispatch the ShowView message.
2620//
2621// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282622// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292623//
[email protected]310ebd6302011-10-10 19:06:282624void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:252625 if (did_show_) {
[email protected]b2142e962012-10-30 13:59:252626 // When supports_multiple_windows is disabled, popups are reusing
2627 // the same view. In some scenarios, this makes WebKit to call show() twice.
[email protected]c9edabd2013-05-23 13:56:242628 if (webkit_preferences_.supports_multiple_windows)
2629 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:292630 return;
[email protected]b2142e962012-10-30 13:59:252631 }
initial.commit09911bf2008-07-26 23:55:292632 did_show_ = true;
2633
[email protected]b2142e962012-10-30 13:59:252634 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2635
[email protected]434bc9b2012-11-27 21:22:142636 if (GetContentClient()->renderer()->AllowPopup())
[email protected]4026ce1e2010-09-14 19:35:042637 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042638
[email protected]28295ec2009-10-16 05:34:332639 // Force new windows to a popup if they were not opened with a user gesture.
2640 if (!opened_by_user_gesture_) {
2641 // We exempt background tabs for compat with older versions of Chrome.
2642 // TODO(darin): This seems bogus. These should have a user gesture, so
2643 // we probably don't need this check.
2644 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2645 policy = WebKit::WebNavigationPolicyNewPopup;
2646 }
2647
initial.commit09911bf2008-07-26 23:55:292648 // NOTE: initial_pos_ may still have its default values at this point, but
2649 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2650 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282651 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2652 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292653 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242654 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292655}
2656
[email protected]310ebd6302011-10-10 19:06:282657void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292658 DCHECK(did_show_) << "should already have shown the view";
2659
[email protected]c1f50aa2010-02-18 03:46:572660 // We must keep WebKit's shared timer running in this case in order to allow
2661 // showModalDialog to function properly.
2662 //
2663 // TODO(darin): WebKit should really be smarter about suppressing events and
2664 // timers so that we do not need to manage the shared timer in such a heavy
2665 // handed manner.
2666 //
[email protected]f1a29a02011-10-06 23:08:442667 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2668 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572669
[email protected]08a1c8102012-05-11 23:14:262670 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2671 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292672}
2673
[email protected]2b624c562011-10-27 22:58:262674bool RenderViewImpl::enterFullScreen() {
2675 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2676 return true;
2677}
2678
2679void RenderViewImpl::exitFullScreen() {
2680 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2681}
2682
[email protected]217690d2012-01-27 07:33:112683bool RenderViewImpl::requestPointerLock() {
2684 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2685}
2686
2687void RenderViewImpl::requestPointerUnlock() {
2688 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2689}
2690
2691bool RenderViewImpl::isPointerLocked() {
2692 return mouse_lock_dispatcher_->IsMouseLockedTo(
2693 webwidget_mouse_lock_target_.get());
2694}
2695
[email protected]7a1ec28a2012-03-28 21:10:242696void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
[email protected]0cd50aa2013-02-12 22:28:012697#if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003
[email protected]ea5f70a2013-03-07 12:30:362698 InputHandlerManager* input_handler_manager =
2699 RenderThreadImpl::current()->input_handler_manager();
[email protected]200a9c062013-05-20 04:34:372700 if (input_handler_manager) {
2701 input_handler_manager->AddInputHandler(
2702 routing_id_,
2703 compositor_->GetInputHandler(),
2704 AsWeakPtr());
2705 }
[email protected]70cff27502013-01-17 09:16:492706#endif
[email protected]7a1ec28a2012-03-28 21:10:242707
2708 RenderWidget::didActivateCompositor(input_handler_identifier);
2709}
2710
[email protected]c68c3e4e2013-01-24 00:36:562711void RenderViewImpl::didHandleGestureEvent(
2712 const WebGestureEvent& event,
2713 bool event_cancelled) {
2714 RenderWidget::didHandleGestureEvent(event, event_cancelled);
2715 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2716 DidHandleGestureEvent(event));
2717}
2718
[email protected]3d9689372009-09-10 04:29:172719// WebKit::WebFrameClient -----------------------------------------------------
2720
[email protected]310ebd6302011-10-10 19:06:282721WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2722 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552723 WebPlugin* plugin = NULL;
[email protected]e9ff79c2012-10-19 21:31:262724 if (GetContentClient()->renderer()->OverrideCreatePlugin(
[email protected]eaacd1f2011-09-23 02:32:552725 this, frame, params, &plugin)) {
2726 return plugin;
2727 }
2728
[email protected]463ba65fd2013-01-03 23:16:432729#if defined(ENABLE_PLUGINS)
[email protected]e9ff79c2012-10-19 21:31:262730 if (UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType) {
[email protected]caaf2482013-05-01 20:33:322731 return GetBrowserPluginManager()->CreateBrowserPlugin(this, frame, params);
[email protected]e6e56752012-08-10 00:46:062732 }
2733
[email protected]a813c8e2011-10-08 01:34:112734 webkit::WebPluginInfo info;
2735 std::string mime_type;
2736 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2737 params.mimeType.utf8(), &info, &mime_type);
2738 if (!found)
2739 return NULL;
2740
2741 WebPluginParams params_to_use = params;
2742 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312743 return CreatePlugin(frame, info, params_to_use);
[email protected]ebd71962012-12-20 02:56:552744#else
2745 return NULL;
2746#endif // defined(ENABLE_PLUGINS)
[email protected]3d9689372009-09-10 04:29:172747}
2748
[email protected]310ebd6302011-10-10 19:06:282749WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422750 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372751 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422752
[email protected]30447b62009-11-13 01:13:372753 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512754 bool exists = false;
[email protected]30447b62009-11-13 01:13:372755 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512756 ViewHostMsg_CreateWorker_Params params;
2757 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512758 params.name = name;
2759 params.document_id = document_id;
2760 params.render_view_route_id = routing_id_;
2761 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232762 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372763 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512764 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372765 if (url_mismatch) {
2766 return NULL;
2767 } else {
[email protected]f1a29a02011-10-06 23:08:442768 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492769 document_id,
[email protected]6de0bcf2010-02-17 22:00:512770 exists,
[email protected]30447b62009-11-13 01:13:372771 route_id,
2772 routing_id_);
2773 }
[email protected]9c00f002009-11-05 22:37:422774}
2775
[email protected]97b150db2012-08-16 18:26:022776WebMediaPlayer* RenderViewImpl::createMediaPlayer(
2777 WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442778 FOR_EACH_OBSERVER(
2779 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172780
[email protected]780fc8242012-09-19 20:28:522781 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]d05e2162012-11-16 22:21:462782#if defined(ENABLE_WEBRTC)
[email protected]b3d080fc2013-03-01 04:17:322783 if (MediaStreamImpl::CheckMediaStream(url)) {
[email protected]befe54782013-04-23 00:49:252784#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
2785 bool found_neon =
2786 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
2787 UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon);
2788#endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
[email protected]d05e2162012-11-16 22:21:462789 EnsureMediaStreamImpl();
2790 return new webkit_media::WebMediaPlayerMS(
2791 frame, client, AsWeakPtr(), media_stream_impl_, new RenderMediaLog());
2792 }
2793#endif
2794
[email protected]25fb9b32012-04-27 03:21:552795#if defined(OS_ANDROID)
[email protected]855623ed2012-09-24 18:59:552796 GpuChannelHost* gpu_channel_host =
2797 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262798 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]855623ed2012-09-24 18:59:552799 if (!gpu_channel_host) {
2800 LOG(ERROR) << "Failed to establish GPU channel for media player";
2801 return NULL;
2802 }
2803
[email protected]a45c46e2013-03-07 01:04:462804 scoped_refptr<cc::ContextProvider> context_provider =
2805 RenderThreadImpl::current()->OffscreenContextProviderForMainThread();
[email protected]e06e1122013-03-15 17:12:382806 if (!context_provider) {
[email protected]a45c46e2013-03-07 01:04:462807 LOG(ERROR) << "Failed to get context3d for media player";
2808 return NULL;
2809 }
2810
[email protected]780fc8242012-09-19 20:28:522811 if (!media_player_proxy_) {
[email protected]e9ff79c2012-10-19 21:31:262812 media_player_proxy_ = new WebMediaPlayerProxyImplAndroid(
[email protected]780fc8242012-09-19 20:28:522813 this, media_player_manager_.get());
2814 }
[email protected]10514432013-04-26 23:32:192815 return new webkit_media::WebMediaPlayerAndroid(
[email protected]780fc8242012-09-19 20:28:522816 frame,
2817 client,
2818 media_player_manager_.get(),
2819 media_player_proxy_,
[email protected]e9ff79c2012-10-19 21:31:262820 new StreamTextureFactoryImpl(
[email protected]1e04260f22013-04-27 20:45:422821 context_provider->Context3d(), gpu_channel_host, routing_id_),
2822 new RenderMediaLog());
[email protected]25fb9b32012-04-27 03:21:552823#endif
2824
[email protected]4a914882013-01-10 00:43:482825 scoped_refptr<media::AudioRendererSink> sink;
[email protected]3d9689372009-09-10 04:29:172826 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]17c4ce62f2013-05-03 19:54:022827 sink = RenderThreadImpl::current()->GetAudioRendererMixerManager()->
2828 CreateInput(routing_id_);
2829 DVLOG(1) << "Using AudioRendererMixerManager-provided sink: " << sink;
[email protected]3d9689372009-09-10 04:29:172830 }
2831
[email protected]e82b2bd2013-01-02 17:47:572832 scoped_refptr<media::GpuVideoDecoder::Factories> gpu_factories;
[email protected]15d206e2012-08-17 22:35:132833 WebGraphicsContext3DCommandBufferImpl* context3d = NULL;
[email protected]5f04c3532012-09-25 01:28:392834 if (!cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
[email protected]15d206e2012-08-17 22:35:132835 context3d = RenderThreadImpl::current()->GetGpuVDAContext3D();
[email protected]851334d2012-06-15 22:39:312836 if (context3d) {
[email protected]ea5f70a2013-03-07 12:30:362837 scoped_refptr<base::MessageLoopProxy> factories_loop =
2838 RenderThreadImpl::current()->compositor_message_loop_proxy();
2839 if (!factories_loop)
[email protected]7f1f63f2013-03-07 06:07:292840 factories_loop = base::MessageLoopProxy::current();
[email protected]e1d69d762011-12-13 05:12:182841 GpuChannelHost* gpu_channel_host =
2842 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262843 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]e82b2bd2013-01-02 17:47:572844 gpu_factories = new RendererGpuVideoDecoderFactories(
2845 gpu_channel_host, factories_loop, context3d);
[email protected]e1d69d762011-12-13 05:12:182846 }
[email protected]e1d69d762011-12-13 05:12:182847
[email protected]e82b2bd2013-01-02 17:47:572848 webkit_media::WebMediaPlayerParams params(
[email protected]b3d080fc2013-03-01 04:17:322849 sink, gpu_factories, new RenderMediaLog());
[email protected]5d65fe92012-06-02 00:48:552850 WebMediaPlayer* media_player =
[email protected]e9ff79c2012-10-19 21:31:262851 GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
[email protected]e82b2bd2013-01-02 17:47:572852 this, frame, client, AsWeakPtr(), params);
[email protected]da952fd2012-01-13 03:49:252853 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562854 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]e82b2bd2013-01-02 17:47:572855 frame, client, AsWeakPtr(), params);
[email protected]bb6fd402011-12-09 02:45:442856 }
[email protected]cec4eb82012-01-12 17:51:562857 return media_player;
[email protected]3d9689372009-09-10 04:29:172858}
2859
[email protected]310ebd6302011-10-10 19:06:282860WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212861 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232862 if (!frame || !frame->view())
2863 return NULL;
[email protected]035545f2010-04-09 13:10:212864 return new RendererWebApplicationCacheHostImpl(
2865 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442866 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212867}
2868
[email protected]310ebd6302011-10-10 19:06:282869WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382870 return &cookie_jar_;
2871}
2872
[email protected]0720b532012-08-28 19:23:372873void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) {
[email protected]50904452013-05-09 02:05:122874 Send(new ViewHostMsg_FrameAttached(routing_id_, parent->identifier(),
2875 child->identifier(), UTF16ToUTF8(child->assignedName())));
[email protected]0720b532012-08-28 19:23:372876}
2877
[email protected]7cc78902012-12-06 02:32:262878void RenderViewImpl::didDisownOpener(WebKit::WebFrame* frame) {
[email protected]29ece2e2013-04-03 04:53:522879 // We only need to notify the browser if the active, top-level frame clears
2880 // its opener. We can ignore cases where a swapped out frame clears its
2881 // opener after hearing about it from the browser, and the browser does not
2882 // (yet) care about subframe openers.
2883 if (is_swapped_out_ || frame->parent())
[email protected]7cc78902012-12-06 02:32:262884 return;
2885
2886 // Notify WebContents and all its swapped out RenderViews.
2887 Send(new ViewHostMsg_DidDisownOpener(routing_id_));
2888}
2889
[email protected]310ebd6302011-10-10 19:06:282890void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]50904452013-05-09 02:05:122891 int64 parent_frame_id = -1;
2892 if (frame->parent())
2893 parent_frame_id = frame->parent()->identifier();
2894
2895 Send(new ViewHostMsg_FrameDetached(routing_id_, parent_frame_id,
2896 frame->identifier()));
[email protected]8607c832013-01-18 14:11:572897
[email protected]676126f72011-01-15 00:03:512898 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452899}
2900
[email protected]310ebd6302011-10-10 19:06:282901void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512902 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172903}
2904
[email protected]25bcc8f2013-01-09 02:49:252905void RenderViewImpl::didChangeName(WebFrame* frame,
2906 const WebString& name) {
[email protected]34cdde092013-01-10 02:29:032907 if (!renderer_preferences_.report_frame_name_changes)
2908 return;
2909
[email protected]25bcc8f2013-01-09 02:49:252910 Send(new ViewHostMsg_UpdateFrameName(routing_id_,
2911 frame->identifier(),
2912 !frame->parent(),
2913 UTF16ToUTF8(name)));
2914}
2915
[email protected]310ebd6302011-10-10 19:06:282916void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172917 WebFrame* frame, const WebURLRequest& request,
2918 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342919 loadURLExternally(frame, request, policy, WebString());
2920}
2921
[email protected]5e92282f2012-08-17 08:11:572922void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:252923 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:572924}
2925
[email protected]b2324b092012-11-01 10:34:112926void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
2927 const std::string& value) {
2928 EditCommands edit_commands;
2929 edit_commands.push_back(EditCommand(name, value));
2930 OnSetEditCommandsForNextKeyEvent(edit_commands);
2931}
2932
2933void RenderViewImpl::ClearEditCommands() {
2934 edit_commands_.clear();
2935}
2936
[email protected]e4495212012-12-06 03:09:122937SSLStatus RenderViewImpl::GetSSLStatusOfFrame(WebKit::WebFrame* frame) const {
[email protected]e20b88d2013-04-09 15:28:372938 return SSLStatus();
[email protected]e4495212012-12-06 03:09:122939}
2940
[email protected]310ebd6302011-10-10 19:06:282941void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342942 WebFrame* frame, const WebURLRequest& request,
2943 WebNavigationPolicy policy,
2944 const WebString& suggested_name) {
[email protected]56505542012-05-12 00:25:372945 Referrer referrer(
2946 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2947 GetReferrerPolicyFromRequest(frame, request));
[email protected]efce17b2009-09-11 18:04:592948 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342949 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2950 suggested_name));
[email protected]efce17b2009-09-11 18:04:592951 } else {
[email protected]56505542012-05-12 00:25:372952 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:592953 }
[email protected]3d9689372009-09-10 04:29:172954}
2955
[email protected]310ebd6302011-10-10 19:06:282956WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]0d8f04b2013-04-29 20:05:312957 WebFrame* frame, WebDataSource::ExtraData* extraData,
2958 const WebURLRequest& request, WebNavigationType type,
2959 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]099df81cf2012-11-14 17:44:042960 if (request.url() != GURL(kSwappedOutURL) &&
2961 GetContentClient()->renderer()->HandleNavigation(frame, request, type,
2962 default_policy,
2963 is_redirect)) {
2964 return WebKit::WebNavigationPolicyIgnore;
2965 }
2966
[email protected]0639c063a2012-03-22 20:55:332967 Referrer referrer(
2968 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:592969 GetReferrerPolicyFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:332970
[email protected]992db4c2011-05-12 15:37:152971 if (is_swapped_out_) {
[email protected]e9ff79c2012-10-19 21:31:262972 if (request.url() != GURL(kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332973 // Targeted links may try to navigate a swapped out frame. Allow the
2974 // browser process to navigate the tab instead. Note that it is also
2975 // possible for non-targeted navigations (from this view) to arrive
2976 // here just after we are swapped out. It's ok to send them to the
2977 // browser, as long as they're for the top level frame.
2978 // TODO(creis): Ensure this supports targeted form submissions when
2979 // fixing http://crbug.com/101395.
2980 if (frame->parent() == NULL) {
2981 OpenURL(frame, request.url(), referrer, default_policy);
2982 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2983 }
2984
2985 // We should otherwise ignore in-process iframe navigations, if they
2986 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552987 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332988 }
[email protected]73eb2602012-02-09 19:50:552989
[email protected]e9ff79c2012-10-19 21:31:262990 // Allow kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152991 return default_policy;
2992 }
2993
[email protected]3d9689372009-09-10 04:29:172994 // Webkit is asking whether to navigate to a new URL.
2995 // This is fine normally, except if we're showing UI from one security
2996 // context and they're trying to navigate to a different context.
2997 const GURL& url = request.url();
2998
[email protected]d19ea342011-04-20 20:31:132999 // A content initiated navigation may have originated from a link-click,
3000 // script, drag-n-drop operation, etc.
[email protected]0d8f04b2013-04-29 20:05:313001 bool is_content_initiated = static_cast<DocumentState*>(extraData)->
[email protected]007733c2011-11-17 00:34:073002 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:133003
[email protected]a8c269a2011-10-25 20:17:223004 // Experimental:
[email protected]c6f2e672012-11-15 01:47:023005 // If --enable-strict-site-isolation or --site-per-process is enabled, send
3006 // all top-level navigations to the browser to let it swap processes when
3007 // crossing site boundaries. This is currently expected to break some script
3008 // calls and navigations, such as form submissions.
[email protected]a8c269a2011-10-25 20:17:223009 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]c6f2e672012-11-15 01:47:023010 bool force_swap_due_to_flag =
3011 command_line.HasSwitch(switches::kEnableStrictSiteIsolation) ||
3012 command_line.HasSwitch(switches::kSitePerProcess);
3013 if (force_swap_due_to_flag &&
[email protected]313b80bd2011-11-23 03:49:103014 !frame->parent() && (is_content_initiated || is_redirect)) {
3015 WebString origin_str = frame->document().securityOrigin().toString();
3016 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:093017 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:103018 // crbug.com/101395 is fixed.
[email protected]ed32c212013-05-14 20:49:293019 bool same_domain_or_host =
3020 net::registry_controlled_domains::SameDomainOrHost(
3021 frame_url,
3022 url,
3023 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
3024 if (!same_domain_or_host || frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:103025 OpenURL(frame, url, referrer, default_policy);
3026 return WebKit::WebNavigationPolicyIgnore;
3027 }
[email protected]a8c269a2011-10-25 20:17:223028 }
3029
[email protected]fd3238af2012-05-22 18:55:303030 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:083031 if (is_content_initiated) {
[email protected]fd3238af2012-05-22 18:55:303032 bool browser_handles_request =
3033 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]5f000f272012-01-19 05:25:083034 IsNonLocalTopLevelNavigation(url, frame, type);
[email protected]fd3238af2012-05-22 18:55:303035 if (!browser_handles_request) {
3036 browser_handles_request =
3037 renderer_preferences_.browser_handles_all_top_level_requests &&
3038 IsTopLevelNavigation(frame);
3039 }
3040
3041 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:083042 // Reset these counters as the RenderView could be reused for the next
3043 // navigation.
3044 page_id_ = -1;
3045 last_page_id_sent_to_browser_ = -1;
3046 OpenURL(frame, url, referrer, default_policy);
3047 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3048 }
[email protected]3d9689372009-09-10 04:29:173049 }
3050
[email protected]dc67e1c32012-06-08 00:10:403051 // Use the frame's original request's URL rather than the document's URL for
3052 // subsequent checks. For a popup, the document's URL may become the opener
3053 // window's URL if the opener has called document.write().
3054 // See http://crbug.com/93517.
3055 GURL old_url(frame->dataSource()->request().url());
3056
[email protected]6101c342010-12-16 22:44:373057 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:553058 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:043059 // top-level navigations (not iframes). But we sometimes navigate to
3060 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:373061 //
[email protected]744c2a22012-03-15 18:42:043062 // Note: this is known to break POST submissions when crossing process
3063 // boundaries until http://crbug.com/101395 is fixed. This is better for
3064 // security than loading a WebUI, extension or app page in the wrong process.
3065 // POST requests don't work because this mechanism does not preserve form
3066 // POST data. We will need to send the request's httpBody data up to the
3067 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:573068 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
3069 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:223070 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:043071 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:373072 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:043073
[email protected]0a57375a2013-03-07 22:18:593074 // All navigations to or from WebUI URLs or within WebUI-enabled
3075 // RenderProcesses must be handled by the browser process so that the
3076 // correct bindings and data sources can be registered.
[email protected]744c2a22012-03-15 18:42:043077 // Similarly, navigations to view-source URLs or within ViewSource mode
[email protected]1c210f692012-11-06 22:31:473078 // must be handled by the browser process (except for reloads - those are
3079 // safe to leave within the renderer).
[email protected]dc67e1c32012-06-08 00:10:403080 // Lastly, access to file:// URLs from non-file:// URL pages must be
3081 // handled by the browser so that ordinary renderer processes don't get
3082 // blessed with file permissions.
3083 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
3084 bool is_initial_navigation = page_id_ == -1;
[email protected]0a57375a2013-03-07 22:18:593085 bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) ||
[email protected]e9ff79c2012-10-19 21:31:263086 (cumulative_bindings & BINDINGS_POLICY_WEB_UI) ||
[email protected]dbdda5402013-05-30 22:13:483087 url.SchemeIs(kViewSourceScheme) ||
[email protected]1c210f692012-11-06 22:31:473088 (frame->isViewSourceModeEnabled() &&
3089 type != WebKit::WebNavigationTypeReload);
[email protected]5351dbc2010-08-27 15:22:113090
[email protected]dc67e1c32012-06-08 00:10:403091 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
3092 // Fork non-file to file opens. Check the opener URL if this is the
3093 // initial navigation in a newly opened window.
3094 GURL source_url(old_url);
3095 if (is_initial_navigation && source_url.is_empty() && frame->opener())
3096 source_url = frame->opener()->top()->document().url();
3097 DCHECK(!source_url.is_empty());
3098 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
3099 }
3100
[email protected]e48869a2011-04-01 19:56:033101 if (!should_fork) {
3102 // Give the embedder a chance.
[email protected]c5dec6292013-01-25 04:54:523103 should_fork = GetContentClient()->renderer()->ShouldFork(
3104 frame, url, request.httpMethod().utf8(), is_initial_navigation,
[email protected]b0a29f22013-05-30 23:00:093105 is_redirect, &send_referrer);
[email protected]6101c342010-12-16 22:44:373106 }
3107
3108 if (should_fork) {
[email protected]445e1042011-12-03 21:03:153109 OpenURL(
3110 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:113111 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3112 }
[email protected]3d9689372009-09-10 04:29:173113 }
3114
3115 // Detect when a page is "forking" a new tab that can be safely rendered in
3116 // its own process. This is done by sites like Gmail that try to open links
3117 // in new windows without script connections back to the original page. We
3118 // treat such cases as browser navigations (in which we will create a new
3119 // renderer for a cross-site navigation), rather than WebKit navigations.
3120 //
3121 // We use the following heuristic to decide whether to fork a new page in its
3122 // own process:
3123 // The parent page must open a new tab to about:blank, set the new tab's
3124 // window.opener to null, and then redirect the tab to a cross-site URL using
3125 // JavaScript.
[email protected]007a848b2009-10-26 15:55:463126 //
3127 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
3128 // (see below).
[email protected]3d9689372009-09-10 04:29:173129 bool is_fork =
3130 // Must start from a tab showing about:blank, which is later redirected.
[email protected]081dc522013-05-15 04:59:203131 old_url == GURL(kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173132 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523133 historyBackListCount() < 1 &&
3134 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173135 // The parent page must have set the child's window.opener to null before
3136 // redirecting to the desired URL.
3137 frame->opener() == NULL &&
3138 // Must be a top-level frame.
3139 frame->parent() == NULL &&
3140 // Must not have issued the request from this page.
3141 is_content_initiated &&
3142 // Must be targeted at the current tab.
3143 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3144 // Must be a JavaScript navigation, which appears as "other".
3145 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463146
[email protected]f92ce2b2012-03-06 18:02:593147 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:173148 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:153149 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:173150 return WebKit::WebNavigationPolicyIgnore;
3151 }
3152
3153 return default_policy;
3154}
3155
[email protected]f4f40a052013-04-19 15:28:113156WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
3157 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]89bc54c62013-04-24 01:51:333158 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0d8f04b2013-04-29 20:05:313159 return decidePolicyForNavigation(frame,
3160 frame->provisionalDataSource()->extraData(),
[email protected]89bc54c62013-04-24 01:51:333161 request, type, default_policy, is_redirect);
[email protected]f4f40a052013-04-19 15:28:113162}
3163
[email protected]310ebd6302011-10-10 19:06:283164bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:493165 WebFrame* frame, const WebURLRequest& request) {
3166 // We allow WebKit to think that everything can be handled even though
3167 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:343168 return true;
3169}
3170
[email protected]310ebd6302011-10-10 19:06:283171WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:493172 WebFrame* frame, const WebURLRequest& request) {
3173 NOTREACHED(); // Since we said we can handle all requests.
3174 return WebURLError();
3175}
3176
[email protected]310ebd6302011-10-10 19:06:283177WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:493178 WebFrame* frame, const WebURLRequest& request) {
3179 WebURLError error;
3180 error.domain = WebString::fromUTF8(net::kErrorDomain);
3181 error.reason = net::ERR_ABORTED;
3182 error.unreachableURL = request.url();
3183 return error;
[email protected]7b7a7dc2009-10-19 02:23:343184}
3185
[email protected]310ebd6302011-10-10 19:06:283186void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:493187 WebFrame*, const WebURLError&) {
3188 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:343189}
3190
[email protected]310ebd6302011-10-10 19:06:283191void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:433192 const WebKit::WebFormElement& form) {
3193 // Some login forms have onSubmit handlers that put a hash of the password
3194 // into a hidden field and then clear the password. (Issue 28910.)
3195 // This method gets called before any of those handlers run, so save away
3196 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:073197 DocumentState* document_state =
3198 DocumentState::FromDataSource(frame->dataSource());
[email protected]e9ff79c2012-10-19 21:31:263199 document_state->set_password_form_data(CreatePasswordForm(form));
[email protected]90eeddb2010-05-06 21:06:433200}
3201
[email protected]310ebd6302011-10-10 19:06:283202void RenderViewImpl::willSubmitForm(WebFrame* frame,
3203 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:073204 DocumentState* document_state =
3205 DocumentState::FromDataSource(frame->provisionalDataSource());
3206 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:373207 InternalDocumentStateData* internal_data =
3208 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]3d9689372009-09-10 04:29:173209
[email protected]e9ff79c2012-10-19 21:31:263210 if (navigation_state->transition_type() == PAGE_TRANSITION_LINK)
3211 navigation_state->set_transition_type(PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:173212
3213 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:353214 WebSearchableFormData web_searchable_form_data(form);
[email protected]e20b88d2013-04-09 15:28:373215 internal_data->set_searchable_form_url(web_searchable_form_data.url());
3216 internal_data->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:213217 web_searchable_form_data.encoding().utf8());
[email protected]a045f4e32012-08-31 09:36:073218 scoped_ptr<PasswordForm> password_form_data =
[email protected]e9ff79c2012-10-19 21:31:263219 CreatePasswordForm(form);
[email protected]90eeddb2010-05-06 21:06:433220
[email protected]098c95cb2011-04-28 16:49:013221 // In order to save the password that the user actually typed and not one
3222 // that may have gotten transformed by the site prior to submit, recover it
3223 // from the form contents already stored by |willSendSubmitEvent| into the
3224 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
3225 // which is what we're storing into now.)
[email protected]59383c782013-04-17 16:43:273226 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:073227 DocumentState* old_document_state =
3228 DocumentState::FromDataSource(frame->dataSource());
3229 if (old_document_state) {
3230 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:433231 if (old_form_data && old_form_data->action == password_form_data->action)
3232 password_form_data->password_value = old_form_data->password_value;
3233 }
3234 }
[email protected]3d9689372009-09-10 04:29:173235
[email protected]a045f4e32012-08-31 09:36:073236 document_state->set_password_form_data(password_form_data.Pass());
3237
[email protected]2a5b1732011-04-01 23:55:553238 FOR_EACH_OBSERVER(
3239 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:173240}
3241
[email protected]310ebd6302011-10-10 19:06:283242void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:173243 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3244 double fire_time) {
[email protected]bf692cd2012-11-14 19:10:023245 // Replace any occurrences of swappedout:// with about:blank.
[email protected]081dc522013-05-15 04:59:203246 const WebURL& blank_url = GURL(kAboutBlankURL);
[email protected]e2caa032012-11-15 23:29:183247
[email protected]eb0bff942011-04-07 22:08:383248 FOR_EACH_OBSERVER(
3249 RenderViewObserver, observers_,
[email protected]bf692cd2012-11-14 19:10:023250 WillPerformClientRedirect(frame,
3251 from == GURL(kSwappedOutURL) ? blank_url : from,
3252 to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:173253}
3254
[email protected]310ebd6302011-10-10 19:06:283255void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:383256 FOR_EACH_OBSERVER(
3257 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:173258}
3259
[email protected]310ebd6302011-10-10 19:06:283260void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:173261 WebFrame* frame, const WebURL& from) {
[email protected]bf692cd2012-11-14 19:10:023262 // Replace any occurrences of swappedout:// with about:blank.
[email protected]081dc522013-05-15 04:59:203263 const WebURL& blank_url = GURL(kAboutBlankURL);
[email protected]445e1042011-12-03 21:03:153264 if (!frame->parent()) {
3265 WebDataSource* ds = frame->provisionalDataSource();
3266 // If there's no provisional data source, it's a reference fragment
3267 // navigation.
3268 completed_client_redirect_src_ = Referrer(
[email protected]bf692cd2012-11-14 19:10:023269 from == GURL(kSwappedOutURL) ? blank_url : from,
3270 ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:043271 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:153272 }
[email protected]eb0bff942011-04-07 22:08:383273 FOR_EACH_OBSERVER(
[email protected]bf692cd2012-11-14 19:10:023274 RenderViewObserver, observers_, DidCompleteClientRedirect(
3275 frame, from == GURL(kSwappedOutURL) ? blank_url : from));
[email protected]3d9689372009-09-10 04:29:173276}
3277
[email protected]310ebd6302011-10-10 19:06:283278void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:573279 bool content_initiated = !pending_navigation_params_.get();
3280
[email protected]007733c2011-11-17 00:34:073281 DocumentState* document_state = DocumentState::FromDataSource(ds);
3282 if (!document_state) {
3283 document_state = new DocumentState;
3284 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:573285 if (!content_initiated)
3286 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:073287 }
3288
[email protected]bf70edce2012-06-20 22:32:223289 // Carry over the user agent override flag, if it exists.
3290 if (content_initiated && webview() && webview()->mainFrame() &&
3291 webview()->mainFrame()->dataSource()) {
3292 DocumentState* old_document_state =
3293 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
3294 if (old_document_state) {
[email protected]e20b88d2013-04-09 15:28:373295 InternalDocumentStateData* internal_data =
3296 InternalDocumentStateData::FromDocumentState(document_state);
3297 InternalDocumentStateData* old_internal_data =
3298 InternalDocumentStateData::FromDocumentState(old_document_state);
3299 internal_data->set_is_overriding_user_agent(
3300 old_internal_data->is_overriding_user_agent());
[email protected]bf70edce2012-06-20 22:32:223301 }
3302 }
3303
[email protected]3d9689372009-09-10 04:29:173304 // The rest of RenderView assumes that a WebDataSource will always have a
3305 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:443306 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:073307 document_state->set_navigation_state(
3308 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:443309 } else {
[email protected]45d83a12012-04-06 22:57:573310 document_state->set_navigation_state(CreateNavigationStateFromPending());
3311 pending_navigation_params_.reset();
3312 }
[email protected]8a3125a712010-08-09 18:58:513313
[email protected]007733c2011-11-17 00:34:073314 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:513315 // navigating from a page that used prefetching using a link on that
3316 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:073317 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:513318 // this value appropriately.
3319 // TODO(gavinp): catch the important case of navigation in a new
3320 // renderer process.
3321 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303322 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523323 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513324 const GURL referrer(
3325 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3326 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:073327 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:513328 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413329 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513330 WebDataSource* old_frame_ds = old_frame->dataSource();
3331 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073332 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513333 break;
3334 }
3335 }
3336 }
3337 }
3338 }
3339
[email protected]4c1b6f0b2010-02-07 16:38:183340 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523341 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513342 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183343 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073344 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183345 break;
3346 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073347 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183348 break;
3349 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073350 document_state->set_load_type(
3351 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183352 break;
3353 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073354 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183355 break;
3356 }
3357 }
[email protected]fa7b6b542009-11-03 05:02:303358
[email protected]946a0032011-03-31 18:42:283359 FOR_EACH_OBSERVER(
3360 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173361}
3362
[email protected]45d83a12012-04-06 22:57:573363void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073364 DocumentState* document_state) {
3365 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573366 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073367
[email protected]e20b88d2013-04-09 15:28:373368 InternalDocumentStateData* internal_data =
3369 InternalDocumentStateData::FromDocumentState(document_state);
3370
[email protected]45d83a12012-04-06 22:57:573371 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
3372 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3373 // We're doing a load of a page that was restored from the last session. By
3374 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3375 // can result in stale data for pages that are set to expire. We explicitly
3376 // override that by setting the policy here so that as necessary we load
3377 // from the network.
[email protected]e20b88d2013-04-09 15:28:373378 internal_data->set_cache_policy_override(
[email protected]45d83a12012-04-06 22:57:573379 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073380 }
3381
3382 if (IsReload(params))
3383 document_state->set_load_type(DocumentState::RELOAD);
[email protected]691aa2f2013-05-28 22:52:043384 else if (params.page_state.IsValid())
[email protected]007733c2011-11-17 00:34:073385 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3386 else
3387 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593388
[email protected]e20b88d2013-04-09 15:28:373389 internal_data->set_referrer_policy(params.referrer.policy);
3390 internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent);
3391 internal_data->set_must_reset_scroll_and_scale_state(
[email protected]a3a5397d2012-09-12 06:50:343392 params.navigation_type ==
3393 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373394 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573395}
[email protected]007733c2011-11-17 00:34:073396
[email protected]45d83a12012-04-06 22:57:573397NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3398 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3399 NavigationState* navigation_state = NULL;
3400
3401 // A navigation resulting from loading a javascript URL should not be treated
3402 // as a browser initiated event. Instead, we want it to look as if the page
3403 // initiated any load resulting from JS execution.
3404 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
3405 navigation_state = NavigationState::CreateBrowserInitiated(
3406 params.page_id,
3407 params.pending_history_list_offset,
[email protected]60d6cca2013-04-30 08:47:133408 params.should_clear_history_list,
[email protected]45d83a12012-04-06 22:57:573409 params.transition);
3410 navigation_state->set_transferred_request_child_id(
3411 params.transferred_request_child_id);
3412 navigation_state->set_transferred_request_request_id(
3413 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003414 navigation_state->set_allow_download(params.allow_download);
[email protected]f050fde2013-03-21 00:40:453415 navigation_state->set_extra_headers(params.extra_headers);
[email protected]45d83a12012-04-06 22:57:573416 } else {
3417 navigation_state = NavigationState::CreateContentInitiated();
3418 }
3419 return navigation_state;
[email protected]007733c2011-11-17 00:34:073420}
3421
[email protected]5b52cd2f712012-03-28 02:12:483422void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3423 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103424 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483425 bool enable_fixed_layout =
3426 command_line.HasSwitch(switches::kEnableFixedLayout);
3427
3428 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
[email protected]5b52cd2f712012-03-28 02:12:483429
[email protected]47e932da2013-03-07 00:11:243430 // If viewport tag is enabled, then the WebKit side will take care
3431 // of setting the fixed layout size and page scale limits.
3432 if (enable_viewport)
3433 return;
3434
3435 if (enable_fixed_layout) {
[email protected]5b52cd2f712012-03-28 02:12:483436 std::string str =
3437 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
3438 std::vector<std::string> tokens;
3439 base::SplitString(str, ',', &tokens);
3440 if (tokens.size() == 2) {
3441 int width, height;
3442 if (base::StringToInt(tokens[0], &width) &&
3443 base::StringToInt(tokens[1], &height))
[email protected]e1ed5a12012-08-08 19:57:443444 webview()->setFixedLayoutSize(WebSize(width, height));
[email protected]5b52cd2f712012-03-28 02:12:483445 }
3446 }
[email protected]e4cd82e2013-04-10 15:20:383447 float maxPageScaleFactor =
3448 command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ;
3449 webview()->setPageScaleFactorLimits(1, maxPageScaleFactor);
[email protected]5b52cd2f712012-03-28 02:12:483450}
3451
[email protected]310ebd6302011-10-10 19:06:283452void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173453 WebDataSource* ds = frame->provisionalDataSource();
[email protected]09c48ef52013-01-09 12:25:073454
3455 // In fast/loader/stop-provisional-loads.html, we abort the load before this
3456 // callback is invoked.
3457 if (!ds)
3458 return;
3459
[email protected]007733c2011-11-17 00:34:073460 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:173461
[email protected]890b06ca2012-12-13 21:07:363462 // We should only navigate to swappedout:// when is_swapped_out_ is true.
3463 CHECK((ds->request().url() != GURL(kSwappedOutURL)) ||
3464 is_swapped_out_) << "Heard swappedout:// when not swapped out.";
3465
[email protected]3d9689372009-09-10 04:29:173466 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:073467 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:173468 double event_time = ds->triggeringEventTime();
3469 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:073470 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:173471 }
3472
[email protected]05c8e502010-08-15 15:13:523473 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:073474 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:523475
[email protected]3d9689372009-09-10 04:29:173476 bool is_top_most = !frame->parent();
3477 if (is_top_most) {
[email protected]af15bf22013-03-08 01:18:173478 navigation_gesture_ = WebUserGestureIndicator::isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133479 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173480
[email protected]d06bcac2013-03-27 21:17:573481 // If the navigation is not triggered by a user gesture, e.g. by some ajax
3482 // callback, then inherit the submitted password form from the previous
3483 // state. This fixes the no password save issue for ajax login, tracked in
3484 // [http://crbug/43219]. Note that there are still some sites that this
3485 // fails for because they use some element other than a submit button to
3486 // trigger submission.
3487 if (navigation_gesture_ == NavigationGestureAuto) {
3488 DocumentState* old_document_state = DocumentState::FromDataSource(
3489 frame->dataSource());
3490 const content::PasswordForm* old_password_form =
3491 old_document_state->password_form_data();
3492 if (old_password_form) {
3493 document_state->set_password_form_data(
3494 make_scoped_ptr(new content::PasswordForm(*old_password_form)));
3495 }
3496 }
3497
[email protected]3d9689372009-09-10 04:29:173498 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:153499 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173500 } else if (frame->parent()->isLoading()) {
3501 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003502 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:073503 document_state->navigation_state()->set_transition_type(
[email protected]e9ff79c2012-10-19 21:31:263504 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173505 }
3506
[email protected]28685da92011-02-07 21:49:173507 FOR_EACH_OBSERVER(
3508 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3509
[email protected]3d9689372009-09-10 04:29:173510 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]d37c33e2012-10-12 13:35:133511 routing_id_, frame->identifier(),
3512 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]434bc9b2012-11-27 21:22:143513 is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173514}
3515
[email protected]400992b2012-06-14 00:03:543516void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3517 WebFrame* frame) {
3518 if (frame->parent())
3519 return;
3520 // Received a redirect on the main frame.
3521 WebDataSource* data_source = frame->provisionalDataSource();
3522 if (!data_source) {
3523 // Should only be invoked when we have a data source.
3524 NOTREACHED();
3525 return;
3526 }
3527 std::vector<GURL> redirects;
3528 GetRedirectChain(data_source, &redirects);
3529 if (redirects.size() >= 2) {
3530 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]434bc9b2012-11-27 21:22:143531 redirects[redirects.size() - 2], redirects.back()));
[email protected]400992b2012-06-14 00:03:543532 }
3533}
3534
[email protected]310ebd6302011-10-10 19:06:283535void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3536 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173537 // Notify the browser that we failed a provisional load with an error.
3538 //
3539 // Note: It is important this notification occur before DidStopLoading so the
3540 // SSL manager can react to the provisional load failure before being
3541 // notified the load stopped.
3542 //
3543 WebDataSource* ds = frame->provisionalDataSource();
3544 DCHECK(ds);
3545
3546 const WebURLRequest& failed_request = ds->request();
3547
[email protected]28685da92011-02-07 21:49:173548 FOR_EACH_OBSERVER(
3549 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3550
[email protected]3d9689372009-09-10 04:29:173551 bool show_repost_interstitial =
3552 (error.reason == net::ERR_CACHE_MISS &&
3553 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583554
3555 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3556 params.frame_id = frame->identifier();
3557 params.is_main_frame = !frame->parent();
3558 params.error_code = error.reason;
[email protected]e9ff79c2012-10-19 21:31:263559 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533560 frame,
[email protected]d7b175e2011-10-11 15:31:583561 failed_request,
3562 error,
3563 NULL,
3564 &params.error_description);
3565 params.url = error.unreachableURL;
3566 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173567 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583568 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173569
3570 // Don't display an error page if this is simply a cancelled load. Aside
3571 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3572 if (error.reason == net::ERR_ABORTED)
3573 return;
3574
[email protected]70dee7e2013-05-29 18:28:303575 if (RenderThreadImpl::current()->layout_test_mode())
[email protected]ac7f5a02013-03-16 16:14:413576 return;
3577
[email protected]3d9689372009-09-10 04:29:173578 // Make sure we never show errors in view source mode.
3579 frame->enableViewSourceMode(false);
3580
[email protected]007733c2011-11-17 00:34:073581 DocumentState* document_state = DocumentState::FromDataSource(ds);
3582 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173583
3584 // If this is a failed back/forward/reload navigation, then we need to do a
3585 // 'replace' load. This is necessary to avoid messing up session history.
3586 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3587 // as session history is concerned.
3588 //
3589 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3590 // the page id.
3591 //
3592 bool replace =
3593 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:583594 navigation_state->transition_type() ==
[email protected]e9ff79c2012-10-19 21:31:263595 PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:173596
3597 // If we failed on a browser initiated request, then make sure that our error
3598 // page load is regarded as the same browser initiated request.
3599 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073600 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3601 pending_navigation_params_->page_id =
3602 navigation_state->pending_page_id();
3603 pending_navigation_params_->pending_history_list_offset =
3604 navigation_state->pending_history_list_offset();
[email protected]60d6cca2013-04-30 08:47:133605 pending_navigation_params_->should_clear_history_list =
3606 navigation_state->history_list_was_cleared();
[email protected]007733c2011-11-17 00:34:073607 pending_navigation_params_->transition =
3608 navigation_state->transition_type();
3609 pending_navigation_params_->request_time =
3610 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173611 }
3612
3613 // Provide the user with a more helpful error page?
3614 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3615 return;
3616
3617 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083618 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173619}
3620
[email protected]310ebd6302011-10-10 19:06:283621void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:173622 WebFrame* frame, const char* data, size_t data_len,
3623 bool& prevent_default) {
[email protected]e20b88d2013-04-09 15:28:373624 InternalDocumentStateData* internal_data =
3625 InternalDocumentStateData::FromDataSource(frame->dataSource());
3626 internal_data->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173627}
3628
[email protected]310ebd6302011-10-10 19:06:283629void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3630 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073631 DocumentState* document_state =
3632 DocumentState::FromDataSource(frame->dataSource());
3633 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:373634 InternalDocumentStateData* internal_data =
3635 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]3d9689372009-09-10 04:29:173636
[email protected]007733c2011-11-17 00:34:073637 if (document_state->commit_load_time().is_null())
3638 document_state->set_commit_load_time(Time::Now());
3639
[email protected]e20b88d2013-04-09 15:28:373640 if (internal_data->must_reset_scroll_and_scale_state()) {
[email protected]06c7ba022012-12-17 19:24:123641 webview()->resetScrollAndScaleState();
[email protected]e20b88d2013-04-09 15:28:373642 internal_data->set_must_reset_scroll_and_scale_state(false);
[email protected]a3a5397d2012-09-12 06:50:343643 }
3644
[email protected]3d9689372009-09-10 04:29:173645 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203646 // When we perform a new navigation, we need to update the last committed
3647 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173648 UpdateSessionHistory(frame);
3649
3650 // We bump our Page ID to correspond with the new session history entry.
3651 page_id_ = next_page_id_++;
3652
[email protected]e9ff79c2012-10-19 21:31:263653 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263654 // we don't want to forget the entry that was there, and since we will
[email protected]e9ff79c2012-10-19 21:31:263655 // never come back to kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313656 // UpdateSessionHistory and update page_id_ even in this case, so that
3657 // the current entry gets a state update and so that we don't send a
3658 // state update to the wrong entry when we swap back in.
[email protected]e9ff79c2012-10-19 21:31:263659 if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313660 // Advance our offset in session history, applying the length limit.
3661 // There is now no forward history.
3662 history_list_offset_++;
[email protected]e9ff79c2012-10-19 21:31:263663 if (history_list_offset_ >= kMaxSessionHistoryEntries)
3664 history_list_offset_ = kMaxSessionHistoryEntries - 1;
[email protected]69ddf852012-02-21 23:21:313665 history_list_length_ = history_list_offset_ + 1;
3666 history_page_ids_.resize(history_list_length_, -1);
3667 history_page_ids_[history_list_offset_] = page_id_;
3668 }
[email protected]3d9689372009-09-10 04:29:173669 } else {
3670 // Inspect the navigation_state on this frame to see if the navigation
3671 // corresponds to a session history navigation... Note: |frame| may or
3672 // may not be the toplevel frame, but for the case of capturing session
3673 // history, the first committed frame suffices. We keep track of whether
3674 // we've seen this commit before so that only capture session history once
3675 // per navigation.
3676 //
3677 // Note that we need to check if the page ID changed. In the case of a
3678 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3679 // previous URL and the current page ID, which would be wrong.
3680 if (navigation_state->pending_page_id() != -1 &&
3681 navigation_state->pending_page_id() != page_id_ &&
3682 !navigation_state->request_committed()) {
3683 // This is a successful session history navigation!
3684 UpdateSessionHistory(frame);
3685 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003686
3687 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033688
3689 // If the history list is valid, our list of page IDs should be correct.
3690 DCHECK(history_list_length_ <= 0 ||
3691 history_list_offset_ < 0 ||
3692 history_list_offset_ >= history_list_length_ ||
3693 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173694 }
3695 }
3696
[email protected]28685da92011-02-07 21:49:173697 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3698 DidCommitProvisionalLoad(frame, is_new_navigation));
3699
[email protected]3d9689372009-09-10 04:29:173700 // Remember that we've already processed this request, so we don't update
3701 // the session history again. We do this regardless of whether this is
3702 // a session history navigation, because if we attempted a session history
3703 // navigation without valid HistoryItem state, WebCore will think it is a
3704 // new navigation.
3705 navigation_state->set_request_committed(true);
3706
3707 UpdateURL(frame);
3708
3709 // If this committed load was initiated by a client redirect, we're
3710 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153711 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173712
3713 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273714 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063715
3716 if (!frame->parent()) { // Only for top frames.
3717 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3718 if (render_thread_impl) { // Can be NULL in tests.
3719 render_thread_impl->histogram_customizer()->
3720 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3721 g_view_map.Get().size());
3722 }
3723 }
[email protected]3d9689372009-09-10 04:29:173724}
3725
[email protected]310ebd6302011-10-10 19:06:283726void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103727 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3728 DidClearWindowObject(frame));
3729
[email protected]e9ff79c2012-10-19 21:31:263730 if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) {
[email protected]59383c782013-04-17 16:43:273731 if (!dom_automation_controller_)
[email protected]766a7082012-02-03 23:39:153732 dom_automation_controller_.reset(new DomAutomationController());
3733 dom_automation_controller_->set_message_sender(
[email protected]e9ff79c2012-10-19 21:31:263734 static_cast<RenderView*>(this));
[email protected]766a7082012-02-03 23:39:153735 dom_automation_controller_->set_routing_id(routing_id());
3736 dom_automation_controller_->BindToJavascript(frame,
3737 "domAutomationController");
3738 }
[email protected]27c521a2013-05-29 20:44:323739
3740 if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) {
3741 if (!stats_collection_controller_.get())
3742 stats_collection_controller_.reset(new StatsCollectionController());
3743 stats_collection_controller_->set_message_sender(
3744 static_cast<RenderView*>(this));
3745 stats_collection_controller_->BindToJavascript(frame,
3746 "statsCollectionController");
3747 }
[email protected]3d9689372009-09-10 04:29:173748}
3749
[email protected]310ebd6302011-10-10 19:06:283750void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173751 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:413752 GURL url = frame->document().url();
[email protected]081dc522013-05-15 04:59:203753 if (url.is_valid() && url.spec() != kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:433754 if (frame == webview()->mainFrame())
3755 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173756 }
[email protected]e48869a2011-04-01 19:56:033757
3758 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3759 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173760}
3761
[email protected]310ebd6302011-10-10 19:06:283762void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3763 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463764 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173765
3766 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273767 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173768}
3769
[email protected]41225fe2013-03-29 05:32:023770void RenderViewImpl::didChangeIcon(WebFrame* frame,
3771 WebIconURL::Type icon_type) {
3772 if (frame->parent())
3773 return;
3774
3775 if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
3776 return;
3777
3778 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
3779 std::vector<FaviconURL> urls;
3780 for (size_t i = 0; i < icon_urls.size(); i++) {
3781 urls.push_back(FaviconURL(icon_urls[i].iconURL(),
3782 ToFaviconType(icon_urls[i].iconType())));
3783 }
3784 SendUpdateFaviconURL(urls);
[email protected]5019ef12010-04-27 17:26:583785}
3786
[email protected]310ebd6302011-10-10 19:06:283787void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173788 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073789 DocumentState* document_state = DocumentState::FromDataSource(ds);
3790 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173791
[email protected]622474d2010-11-04 09:21:083792 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173793
[email protected]28685da92011-02-07 21:49:173794 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3795 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173796
3797 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273798 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173799}
3800
[email protected]310ebd6302011-10-10 19:06:283801void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083802 if (webview()->mainFrame() == frame) {
3803 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3804 page_id_));
3805 }
[email protected]3d9689372009-09-10 04:29:173806}
3807
[email protected]310ebd6302011-10-10 19:06:283808void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313809 WebDataSource* ds = frame->dataSource();
3810 DCHECK(ds);
3811
3812
[email protected]28685da92011-02-07 21:49:173813 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313814
3815 const WebURLRequest& failed_request = ds->request();
3816 string16 error_description;
[email protected]e9ff79c2012-10-19 21:31:263817 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533818 frame,
[email protected]1a55c5be2011-11-29 11:36:313819 failed_request,
3820 error,
3821 NULL,
3822 &error_description);
3823 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3824 frame->identifier(),
3825 failed_request.url(),
3826 !frame->parent(),
3827 error.reason,
3828 error_description));
[email protected]3d9689372009-09-10 04:29:173829}
3830
[email protected]310ebd6302011-10-10 19:06:283831void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173832 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073833 DocumentState* document_state = DocumentState::FromDataSource(ds);
3834 if (document_state->finish_load_time().is_null())
3835 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413836
[email protected]676126f72011-01-15 00:03:513837 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173838
[email protected]1a55c5be2011-11-29 11:36:313839 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3840 frame->identifier(),
3841 ds->request().url(),
3842 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173843}
3844
[email protected]310ebd6302011-10-10 19:06:283845void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173846 WebFrame* frame, bool is_new_navigation) {
3847 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073848 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173849 // update the ExtraData on the datasource so that others who read the
3850 // ExtraData will get the new NavigationState. Similarly, if we did not
3851 // initiate this navigation, then we need to take care to reset any pre-
3852 // existing navigation state to a content-initiated navigation state.
3853 // DidCreateDataSource conveniently takes care of this for us.
3854 didCreateDataSource(frame, frame->dataSource());
3855
[email protected]007733c2011-11-17 00:34:073856 DocumentState* document_state =
3857 DocumentState::FromDataSource(frame->dataSource());
3858 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093859 new_state->set_was_within_same_page(true);
3860
[email protected]3d9689372009-09-10 04:29:173861 didCommitProvisionalLoad(frame, is_new_navigation);
3862
[email protected]750fcf872011-08-03 23:10:473863 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3864 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173865}
3866
[email protected]310ebd6302011-10-10 19:06:283867void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313868 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593869}
3870
[email protected]310ebd6302011-10-10 19:06:283871void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173872 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3873 // Ignore
3874}
3875
[email protected]310ebd6302011-10-10 19:06:283876void RenderViewImpl::willSendRequest(WebFrame* frame,
3877 unsigned identifier,
3878 WebURLRequest& request,
3879 const WebURLResponse& redirect_response) {
[email protected]b4576a12013-01-22 10:41:433880 // The request my be empty during tests.
3881 if (request.url().isEmpty())
3882 return;
3883
[email protected]5e369672009-11-03 23:48:303884 WebFrame* top_frame = frame->top();
3885 if (!top_frame)
3886 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513887 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3888 WebDataSource* top_data_source = top_frame->dataSource();
3889 WebDataSource* data_source =
3890 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223891
[email protected]e9ff79c2012-10-19 21:31:263892 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073893 DocumentState* document_state = DocumentState::FromDataSource(data_source);
[email protected]def55e022012-07-26 01:15:293894 DCHECK(document_state);
[email protected]e20b88d2013-04-09 15:28:373895 InternalDocumentStateData* internal_data =
3896 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]007733c2011-11-17 00:34:073897 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e1ed5a12012-08-08 19:57:443898 transition_type = navigation_state->transition_type();
3899
3900 GURL request_url(request.url());
3901 GURL new_url;
[email protected]e9ff79c2012-10-19 21:31:263902 if (GetContentClient()->renderer()->WillSendRequest(
[email protected]53d96fb2012-11-27 15:36:273903 frame,
3904 transition_type,
3905 request_url,
3906 request.firstPartyForCookies(),
3907 &new_url)) {
[email protected]e1ed5a12012-08-08 19:57:443908 request.setURL(WebURL(new_url));
3909 }
3910
[email protected]e20b88d2013-04-09 15:28:373911 if (internal_data->is_cache_policy_override_set())
3912 request.setCachePolicy(internal_data->cache_policy_override());
[email protected]8a3125a712010-08-09 18:58:513913
[email protected]ca662822012-05-11 17:53:593914 WebKit::WebReferrerPolicy referrer_policy;
[email protected]e20b88d2013-04-09 15:28:373915 if (internal_data->is_referrer_policy_set()) {
3916 referrer_policy = internal_data->referrer_policy();
3917 internal_data->clear_referrer_policy();
[email protected]ca662822012-05-11 17:53:593918 } else {
3919 referrer_policy = frame->document().referrerPolicy();
3920 }
3921
[email protected]e372f3d2012-07-17 19:16:443922 // The request's extra data may indicate that we should set a custom user
3923 // agent. This needs to be done here, after WebKit is through with setting the
3924 // user agent on its own.
3925 WebString custom_user_agent;
3926 if (request.extraData()) {
3927 webkit_glue::WebURLRequestExtraDataImpl* old_extra_data =
3928 static_cast<webkit_glue::WebURLRequestExtraDataImpl*>(
3929 request.extraData());
3930 custom_user_agent = old_extra_data->custom_user_agent();
3931
3932 if (!custom_user_agent.isNull()) {
3933 if (custom_user_agent.isEmpty())
3934 request.clearHTTPHeaderField("User-Agent");
3935 else
3936 request.setHTTPHeaderField("User-Agent", custom_user_agent);
3937 }
3938 }
3939
[email protected]91043a8232011-11-04 16:41:193940 request.setExtraData(
[email protected]ca662822012-05-11 17:53:593941 new RequestExtraData(referrer_policy,
[email protected]e372f3d2012-07-17 19:16:443942 custom_user_agent,
[email protected]537fbe02011-11-24 00:58:063943 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193944 frame->identifier(),
3945 frame->parent() == top_frame,
3946 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]80744782012-05-04 01:47:003947 navigation_state->allow_download(),
[email protected]4ad5d77d2011-12-03 02:00:483948 transition_type,
3949 navigation_state->transferred_request_child_id(),
3950 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573951
[email protected]007733c2011-11-17 00:34:073952 DocumentState* top_document_state =
3953 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573954 // TODO(gavinp): separate out prefetching and prerender field trials
3955 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073956 if (top_document_state &&
[email protected]925dec1c2012-05-18 05:09:003957 request.targetType() == WebURLRequest::TargetIsPrefetch)
[email protected]007733c2011-11-17 00:34:073958 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513959
[email protected]3d9689372009-09-10 04:29:173960 request.setRequestorID(routing_id_);
[email protected]af15bf22013-03-08 01:18:173961 request.setHasUserGesture(WebUserGestureIndicator::isProcessingUserGesture());
[email protected]cd448092010-12-06 23:49:133962
[email protected]f050fde2013-03-21 00:40:453963 if (!navigation_state->extra_headers().empty()) {
3964 for (net::HttpUtil::HeadersIterator i(
3965 navigation_state->extra_headers().begin(),
3966 navigation_state->extra_headers().end(), "\n");
3967 i.GetNext(); ) {
3968 request.setHTTPHeaderField(WebString::fromUTF8(i.name()),
3969 WebString::fromUTF8(i.values()));
3970 }
3971 }
3972
[email protected]0a8db0d2011-04-13 15:15:403973 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133974 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173975}
3976
[email protected]310ebd6302011-10-10 19:06:283977void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173978 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493979
[email protected]3d9689372009-09-10 04:29:173980 // Only do this for responses that correspond to a provisional data source
3981 // of the top-most frame. If we have a provisional data source, then we
3982 // can't have any sub-resources yet, so we know that this response must
3983 // correspond to a frame load.
3984 if (!frame->provisionalDataSource() || frame->parent())
3985 return;
3986
3987 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083988 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173989 if (frame->isViewSourceModeEnabled())
3990 return;
3991
[email protected]007733c2011-11-17 00:34:073992 DocumentState* document_state =
3993 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083994 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533995
[email protected]972ebdff2010-06-10 22:59:073996 // Record page load flags.
[email protected]b9fd01ba2012-02-28 01:50:403997 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3998 if (extra_data) {
[email protected]e07ddafe2013-03-05 21:03:363999 document_state->set_was_fetched_via_spdy(
4000 extra_data->was_fetched_via_spdy());
4001 document_state->set_was_npn_negotiated(
4002 extra_data->was_npn_negotiated());
[email protected]b9fd01ba2012-02-28 01:50:404003 document_state->set_npn_negotiated_protocol(
4004 extra_data->npn_negotiated_protocol());
[email protected]e07ddafe2013-03-05 21:03:364005 document_state->set_was_alternate_protocol_available(
4006 extra_data->was_alternate_protocol_available());
4007 document_state->set_was_fetched_via_proxy(
4008 extra_data->was_fetched_via_proxy());
[email protected]b9fd01ba2012-02-28 01:50:404009 }
[email protected]e20b88d2013-04-09 15:28:374010 InternalDocumentStateData* internal_data =
4011 InternalDocumentStateData::FromDocumentState(document_state);
4012 internal_data->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:094013 // Whether or not the http status code actually corresponds to an error is
4014 // only checked when the page is done loading, if |use_error_page| is
4015 // still true.
[email protected]e20b88d2013-04-09 15:28:374016 internal_data->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:174017}
4018
[email protected]310ebd6302011-10-10 19:06:284019void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:174020 WebFrame* frame, unsigned identifier) {
[email protected]e20b88d2013-04-09 15:28:374021 InternalDocumentStateData* internal_data =
4022 InternalDocumentStateData::FromDataSource(frame->dataSource());
4023 if (!internal_data->use_error_page())
[email protected]3d9689372009-09-10 04:29:174024 return;
4025
[email protected]7bfc153f2011-09-23 22:00:204026 // Do not show error page when DevTools is attached.
4027 if (devtools_agent_->IsAttached())
4028 return;
4029
[email protected]06333afe2011-02-24 14:55:094030 // Display error page, if appropriate.
[email protected]e20b88d2013-04-09 15:28:374031 int http_status_code = internal_data->http_status_code();
[email protected]3f853a52010-09-13 19:15:084032 if (http_status_code == 404) {
4033 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:414034 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:174035
[email protected]b6cb3a842011-06-24 18:28:414036 const GURL& error_page_url =
4037 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:094038 if (error_page_url.is_valid()) {
4039 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:474040 original_error.domain = "http";
4041 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:414042 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:174043
[email protected]e20b88d2013-04-09 15:28:374044 internal_data->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:094045 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:424046 error_page_url, frame, frame->dataSource()->request(),
4047 original_error,
[email protected]6e806822011-11-19 01:51:084048 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4049 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:094050 return;
4051 }
4052 }
[email protected]3d9689372009-09-10 04:29:174053
[email protected]e6a2ce52011-10-08 01:40:134054 std::string error_domain;
[email protected]e9ff79c2012-10-19 21:31:264055 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:134056 http_status_code, &error_domain)) {
4057 WebURLError error;
4058 error.unreachableURL = frame->document().url();
4059 error.domain = WebString::fromUTF8(error_domain);
4060 error.reason = http_status_code;
4061
4062 LoadNavigationErrorPage(
4063 frame, frame->dataSource()->request(), error, std::string(), true);
4064 }
[email protected]3d9689372009-09-10 04:29:174065}
4066
[email protected]310ebd6302011-10-10 19:06:284067void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:174068 WebFrame* frame, unsigned identifier, const WebURLError& error) {
4069 // Ignore
4070}
4071
[email protected]310ebd6302011-10-10 19:06:284072void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:174073 WebFrame* frame, const WebURLRequest& request,
4074 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:004075 // The recipients of this message have no use for data: URLs: they don't
4076 // affect the page's insecure content list and are not in the disk cache. To
4077 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
4078 // filter them out here.
4079 GURL url(request.url());
4080 if (url.SchemeIs("data"))
4081 return;
4082
[email protected]3d9689372009-09-10 04:29:174083 // Let the browser know we loaded a resource from the memory cache. This
4084 // message is needed to display the correct SSL indicators.
4085 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
4086 routing_id_,
[email protected]84703292011-10-28 20:44:004087 url,
[email protected]70435962011-08-02 20:13:284088 response.securityInfo(),
4089 request.httpMethod().utf8(),
[email protected]6d6cfb3a2012-05-23 22:53:184090 response.mimeType().utf8(),
[email protected]70435962011-08-02 20:13:284091 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:174092}
4093
[email protected]310ebd6302011-10-10 19:06:284094void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:294095 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
4096}
4097
[email protected]310ebd6302011-10-10 19:06:284098void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:024099 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:294100 Send(new ViewHostMsg_DidRunInsecureContent(
4101 routing_id_,
[email protected]92771112011-01-20 00:13:024102 origin.toString().utf8(),
4103 target));
[email protected]e3d60e5d2009-09-25 21:08:294104}
4105
[email protected]310ebd6302011-10-10 19:06:284106void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:174107 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
4108}
4109
[email protected]310ebd6302011-10-10 19:06:284110void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
4111 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:584112 int extension_group,
[email protected]310ebd6302011-10-10 19:06:284113 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:264114 GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:584115 frame, context, extension_group, world_id);
4116}
4117
[email protected]310ebd6302011-10-10 19:06:284118void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
4119 v8::Handle<v8::Context> context,
4120 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:264121 GetContentClient()->renderer()->WillReleaseScriptContext(
[email protected]5bc10932011-09-21 21:03:304122 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:284123}
4124
[email protected]310ebd6302011-10-10 19:06:284125void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:074126 // We don't always want to send the change messages over IPC, only if we've
4127 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
4128 // message.
4129 if (!send_preferred_size_changes_ || !webview())
4130 return;
4131
[email protected]705243f2010-05-05 19:58:074132 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
4133 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:534134
4135 // In the presence of zoom, these sizes are still reported as if unzoomed,
4136 // so we need to adjust.
4137 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
4138 size.set_width(static_cast<int>(size.width() * zoom_factor));
4139 size.set_height(static_cast<int>(size.height() * zoom_factor));
4140
[email protected]705243f2010-05-05 19:58:074141 if (size == preferred_size_)
4142 return;
[email protected]c27324b2009-11-19 22:44:294143
[email protected]705243f2010-05-05 19:58:074144 preferred_size_ = size;
4145 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
4146 preferred_size_));
[email protected]3d9689372009-09-10 04:29:174147}
4148
[email protected]caaf2482013-05-01 20:33:324149BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
[email protected]fb325d122012-11-20 23:58:054150 if (!browser_plugin_manager_)
4151 browser_plugin_manager_ = BrowserPluginManager::Create(this);
4152 return browser_plugin_manager_;
4153}
4154
[email protected]273558fb2012-01-12 15:03:514155void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]7082fb942012-05-16 23:44:594156 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:404157 return;
4158
[email protected]d9da9582013-01-31 04:59:054159#if defined(OS_ANDROID)
[email protected]ce585bf2013-03-14 16:25:164160 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC))
[email protected]d9da9582013-01-31 04:59:054161 return;
4162#endif
4163
[email protected]4fb0f202012-05-30 22:44:534164#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:514165 if (!media_stream_dispatcher_)
4166 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
4167
[email protected]1bc65a42012-04-23 09:31:254168 if (!media_stream_impl_) {
[email protected]273558fb2012-01-12 15:03:514169 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:254170 this,
[email protected]273558fb2012-01-12 15:03:514171 media_stream_dispatcher_,
[email protected]6ee10bd2012-09-13 09:01:534172 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
[email protected]273558fb2012-01-12 15:03:514173 }
[email protected]5b87e782012-02-09 18:19:324174#endif
[email protected]273558fb2012-01-12 15:03:514175}
4176
[email protected]310ebd6302011-10-10 19:06:284177void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
4178 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:314179 if (webview()->mainFrame() != frame)
4180 return;
4181 WebView* frameView = frame->view();
4182 if (!frameView)
4183 return;
4184
4185 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
4186 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
4187
4188 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
4189 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
4190 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
4191 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
4192
4193 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
4194 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
4195 }
4196}
4197
[email protected]310ebd6302011-10-10 19:06:284198void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:314199 WebSize offset = frame->scrollOffset();
4200 WebSize minimum_offset = frame->minimumScrollOffset();
4201 WebSize maximum_offset = frame->maximumScrollOffset();
4202
4203 bool is_pinned_to_left = offset.width <= minimum_offset.width;
4204 bool is_pinned_to_right = offset.width >= maximum_offset.width;
4205
4206 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
4207 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
4208 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
4209 routing_id_, is_pinned_to_left, is_pinned_to_right));
4210
4211 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
4212 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
4213 }
[email protected]4e721742013-02-04 21:39:304214
4215 Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_));
[email protected]dd6afca2011-08-13 03:44:314216}
4217
[email protected]310ebd6302011-10-10 19:06:284218void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:494219 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:314220
4221 if (webview()->mainFrame() == frame)
4222 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:264223
4224 FOR_EACH_OBSERVER(
4225 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:314226}
4227
[email protected]a9344092d2013-02-27 00:56:454228void RenderViewImpl::willInsertBody(WebKit::WebFrame* frame) {
4229 if (!frame->parent()) {
4230 Send(new ViewHostMsg_WillInsertBody(routing_id()));
4231 }
4232}
4233
[email protected]4d0f8182012-10-19 23:14:474234void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) {
4235 if (frame != webview()->mainFrame())
4236 return;
4237
[email protected]92d457802013-04-01 19:18:494238 InternalDocumentStateData* data =
4239 InternalDocumentStateData::FromDataSource(frame->dataSource());
4240 data->set_did_first_visually_non_empty_layout(true);
4241
4242#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:474243 // Update body background color if necessary.
4244 SkColor bg_color = webwidget_->backgroundColor();
4245
4246 // If not initialized, default to white. Note that 0 is different from black
4247 // as black still has alpha 0xFF.
4248 if (!bg_color)
4249 bg_color = SK_ColorWHITE;
4250
4251 if (bg_color != body_background_color_) {
4252 body_background_color_ = bg_color;
4253 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id_, bg_color));
4254 }
[email protected]4d0f8182012-10-19 23:14:474255#endif
[email protected]92d457802013-04-01 19:18:494256}
[email protected]4d0f8182012-10-19 23:14:474257
[email protected]55750b32012-09-21 14:05:034258void RenderViewImpl::SendFindReply(int request_id,
4259 int match_count,
4260 int ordinal,
4261 const WebRect& selection_rect,
4262 bool final_status_update) {
[email protected]55750b32012-09-21 14:05:034263 Send(new ViewHostMsg_Find_Reply(routing_id_,
4264 request_id,
4265 match_count,
4266 selection_rect,
4267 ordinal,
4268 final_status_update));
4269}
4270
[email protected]432c9a72013-02-27 01:51:034271// static
4272bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams(
4273 const string16& selection_text,
4274 size_t selection_text_offset,
4275 const ui::Range& selection_range,
4276 const ContextMenuParams& params) {
4277 string16 trimmed_selection_text;
4278 if (!selection_text.empty() && !selection_range.is_empty()) {
4279 const int start = selection_range.GetMin() - selection_text_offset;
4280 const size_t length = selection_range.length();
4281 if (start >= 0 && start + length <= selection_text.length()) {
4282 TrimWhitespace(selection_text.substr(start, length), TRIM_ALL,
4283 &trimmed_selection_text);
4284 }
4285 }
4286 string16 trimmed_params_text;
4287 TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text);
4288 return trimmed_params_text != trimmed_selection_text;
4289}
4290
[email protected]55750b32012-09-21 14:05:034291void RenderViewImpl::reportFindInPageMatchCount(int request_id,
4292 int count,
[email protected]310ebd6302011-10-10 19:06:284293 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:114294 int active_match_ordinal = -1; // -1 = don't update active match ordinal
4295 if (!count)
4296 active_match_ordinal = 0;
4297
[email protected]55750b32012-09-21 14:05:034298 // Send the search result over to the browser process.
4299 SendFindReply(request_id,
4300 count,
4301 active_match_ordinal,
4302 gfx::Rect(),
4303 final_update);
[email protected]8922e1f2009-10-03 05:01:264304}
4305
[email protected]310ebd6302011-10-10 19:06:284306void RenderViewImpl::reportFindInPageSelection(int request_id,
4307 int active_match_ordinal,
4308 const WebRect& selection_rect) {
[email protected]55750b32012-09-21 14:05:034309 SendFindReply(request_id,
4310 -1,
4311 active_match_ordinal,
4312 selection_rect,
4313 false);
[email protected]8922e1f2009-10-03 05:01:264314}
4315
[email protected]310ebd6302011-10-10 19:06:284316void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:224317 WebFrame* frame,
[email protected]18cdb0e2013-03-19 16:37:534318 WebKit::WebFileSystemType type,
[email protected]2b06a992010-08-21 05:48:224319 long long size,
[email protected]d275d7a2010-11-03 01:34:494320 bool create,
[email protected]2b06a992010-08-21 05:48:224321 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:084322 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:224323
[email protected]b6cb3a842011-06-24 18:28:414324 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564325 if (origin.isUnique()) {
4326 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:084327 callbacks->didFail(WebKit::WebFileErrorAbort);
4328 return;
4329 }
[email protected]2b06a992010-08-21 05:48:224330
[email protected]c5a272d2010-09-27 18:37:084331 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
4332 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d2691962013-05-16 14:19:274333 size, create,
4334 base::Bind(&OpenFileSystemCallbackAdapter, callbacks),
4335 base::Bind(&FileStatusCallbackAdapter, callbacks));
[email protected]2b06a992010-08-21 05:48:224336}
4337
[email protected]d5e08552012-08-02 21:43:404338void RenderViewImpl::deleteFileSystem(
4339 WebFrame* frame,
[email protected]18cdb0e2013-03-19 16:37:534340 WebKit::WebFileSystemType type ,
[email protected]d5e08552012-08-02 21:43:404341 WebFileSystemCallbacks* callbacks) {
4342 DCHECK(callbacks);
4343
4344 WebSecurityOrigin origin = frame->document().securityOrigin();
4345 if (origin.isUnique()) {
4346 // Unique origins cannot store persistent state.
4347 callbacks->didSucceed();
4348 return;
4349 }
4350
4351 ChildThread::current()->file_system_dispatcher()->DeleteFileSystem(
4352 GURL(origin.toString()),
4353 static_cast<fileapi::FileSystemType>(type),
[email protected]d2691962013-05-16 14:19:274354 base::Bind(&FileStatusCallbackAdapter, callbacks));
[email protected]d5e08552012-08-02 21:43:404355}
4356
[email protected]310ebd6302011-10-10 19:06:284357void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:404358 WebFrame* frame,
4359 WebStorageQuotaType type,
4360 WebStorageQuotaCallbacks* callbacks) {
4361 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414362 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564363 if (origin.isUnique()) {
4364 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404365 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4366 return;
4367 }
4368 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:534369 GURL(origin.toString()),
4370 static_cast<quota::StorageType>(type),
4371 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404372}
4373
[email protected]310ebd6302011-10-10 19:06:284374void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404375 WebFrame* frame,
4376 WebStorageQuotaType type,
4377 unsigned long long requested_size,
4378 WebStorageQuotaCallbacks* callbacks) {
4379 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414380 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564381 if (origin.isUnique()) {
4382 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404383 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4384 return;
4385 }
4386 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:534387 routing_id(), GURL(origin.toString()),
4388 static_cast<quota::StorageType>(type), requested_size,
4389 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404390}
4391
[email protected]f546640b2012-05-15 00:03:494392bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]0720b532012-08-28 19:23:374393 WebKit::WebFrame* sourceFrame,
4394 WebKit::WebFrame* targetFrame,
[email protected]f546640b2012-05-15 00:03:494395 WebKit::WebSecurityOrigin target_origin,
4396 WebKit::WebDOMMessageEvent event) {
4397 if (!is_swapped_out_)
4398 return false;
4399
4400 ViewMsg_PostMessage_Params params;
4401 params.data = event.data().toString();
4402 params.source_origin = event.origin();
4403 if (!target_origin.isNull())
4404 params.target_origin = target_origin.toString();
4405
4406 // Include the routing ID for the source frame, which the browser process
4407 // will translate into the routing ID for the equivalent frame in the target
4408 // process.
[email protected]f546640b2012-05-15 00:03:494409 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]0720b532012-08-28 19:23:374410 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
[email protected]f546640b2012-05-15 00:03:494411 if (source_view)
4412 params.source_routing_id = source_view->routing_id();
4413
4414 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4415 return true;
4416}
4417
[email protected]5fa3a062012-03-21 15:39:344418void RenderViewImpl::willOpenSocketStream(
4419 WebSocketStreamHandle* handle) {
4420 SocketStreamHandleData::AddToHandle(handle, routing_id_);
4421}
4422
[email protected]ccee4862012-10-03 18:34:264423void RenderViewImpl::willStartUsingPeerConnectionHandler(
4424 WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) {
4425#if defined(ENABLE_WEBRTC)
4426 static_cast<RTCPeerConnectionHandler*>(handler)->associateWithFrame(frame);
4427#endif
4428}
4429
[email protected]bf70edce2012-06-20 22:32:224430WebKit::WebString RenderViewImpl::userAgentOverride(
4431 WebKit::WebFrame* frame,
4432 const WebKit::WebURL& url) {
4433 if (!webview() || !webview()->mainFrame() ||
4434 renderer_preferences_.user_agent_override.empty()) {
4435 return WebKit::WebString();
4436 }
4437
4438 // If we're in the middle of committing a load, the data source we need
4439 // will still be provisional.
4440 WebFrame* main_frame = webview()->mainFrame();
4441 WebDataSource* data_source = NULL;
4442 if (main_frame->provisionalDataSource())
4443 data_source = main_frame->provisionalDataSource();
4444 else
4445 data_source = main_frame->dataSource();
4446
[email protected]e20b88d2013-04-09 15:28:374447 InternalDocumentStateData* internal_data = data_source ?
4448 InternalDocumentStateData::FromDataSource(data_source) : NULL;
4449 if (internal_data && internal_data->is_overriding_user_agent())
[email protected]bf70edce2012-06-20 22:32:224450 return WebString::fromUTF8(renderer_preferences_.user_agent_override);
[email protected]e20b88d2013-04-09 15:28:374451 return WebKit::WebString();
[email protected]bf70edce2012-06-20 22:32:224452}
4453
[email protected]a3e217f2013-04-12 22:38:344454WebString RenderViewImpl::doNotTrackValue(WebFrame* frame) {
4455 if (renderer_preferences_.enable_do_not_track)
4456 return WebString::fromUTF8("1");
4457 return WebString();
4458}
4459
[email protected]818915cd2012-11-20 13:14:114460bool RenderViewImpl::allowWebGL(WebFrame* frame, bool default_value) {
4461 if (!default_value)
4462 return false;
4463
4464 bool blocked = true;
4465 Send(new ViewHostMsg_Are3DAPIsBlocked(
4466 routing_id_,
4467 GURL(frame->top()->document().securityOrigin().toString()),
4468 THREE_D_API_TYPE_WEBGL,
4469 &blocked));
4470 return !blocked;
4471}
4472
4473void RenderViewImpl::didLoseWebGLContext(
4474 WebKit::WebFrame* frame,
4475 int arb_robustness_status_code) {
4476 Send(new ViewHostMsg_DidLose3DContext(
4477 GURL(frame->top()->document().securityOrigin().toString()),
4478 THREE_D_API_TYPE_WEBGL,
4479 arb_robustness_status_code));
4480}
4481
[email protected]18d5be92011-07-25 18:00:194482// WebKit::WebPageSerializerClient implementation ------------------------------
4483
[email protected]310ebd6302011-10-10 19:06:284484void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194485 const WebURL& frame_url,
4486 const WebCString& data,
4487 WebPageSerializerClient::PageSerializationStatus status) {
4488 Send(new ViewHostMsg_SendSerializedHtmlData(
4489 routing_id(),
4490 frame_url,
4491 data.data(),
4492 static_cast<int32>(status)));
4493}
4494
[email protected]e9ff79c2012-10-19 21:31:264495// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:314496
[email protected]310ebd6302011-10-10 19:06:284497bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314498 return RenderWidget::Send(message);
4499}
4500
[email protected]82114f52012-03-20 22:53:414501int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314502 return routing_id_;
4503}
4504
[email protected]82114f52012-03-20 22:53:414505int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314506 return page_id_;
4507}
4508
[email protected]82114f52012-03-20 22:53:414509gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314510 return size();
4511}
4512
[email protected]82114f52012-03-20 22:53:414513WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314514 return webkit_preferences_;
4515}
4516
[email protected]324825d2012-11-30 12:37:154517void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
4518 OnUpdateWebPreferences(preferences);
4519}
4520
[email protected]82114f52012-03-20 22:53:414521WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314522 return webview();
4523}
4524
[email protected]82114f52012-03-20 22:53:414525WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314526 if (!webview())
4527 return WebNode();
4528 WebFrame* focused_frame = webview()->focusedFrame();
4529 if (focused_frame) {
4530 WebDocument doc = focused_frame->document();
4531 if (!doc.isNull())
4532 return doc.focusedNode();
4533 }
4534
4535 return WebNode();
4536}
4537
[email protected]82114f52012-03-20 22:53:414538WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314539 return context_menu_node_;
4540}
4541
[email protected]2a84f9d2012-06-05 21:50:434542bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4543 if (node.isNull())
4544 return false;
4545
4546 if (node.isContentEditable())
4547 return true;
4548
4549 if (node.isElementNode()) {
4550 const WebElement& element = node.toConst<WebElement>();
4551 if (element.isTextFormControlElement())
4552 return true;
4553
4554 // Also return true if it has an ARIA role of 'textbox'.
4555 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4556 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4557 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4558 return true;
4559 break;
4560 }
[email protected]a2ef54c2011-10-10 16:20:314561 }
4562 }
[email protected]2a84f9d2012-06-05 21:50:434563
4564 return false;
[email protected]a2ef54c2011-10-10 16:20:314565}
4566
[email protected]310ebd6302011-10-10 19:06:284567WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:314568 WebKit::WebFrame* frame,
4569 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:414570 const WebKit::WebPluginParams& params) {
[email protected]6d17f6392012-12-05 05:24:544571 WebKit::WebPlugin* pepper_webplugin =
4572 pepper_helper_->CreatePepperWebPlugin(info, params);
4573
4574 if (pepper_webplugin)
4575 return pepper_webplugin;
[email protected]a2ef54c2011-10-10 16:20:314576
[email protected]1b517202012-12-19 17:16:104577 if (!webkit::npapi::NPAPIPluginsSupported())
4578 return NULL;
4579
[email protected]a2ef54c2011-10-10 16:20:314580 return new webkit::npapi::WebPluginImpl(
4581 frame, params, info.path, AsWeakPtr());
4582}
4583
[email protected]310ebd6302011-10-10 19:06:284584void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4585 const string16& jscript,
4586 int id,
4587 bool notify_result) {
[email protected]3b2a3a82013-02-20 15:29:314588 v8::HandleScope handle_scope;
[email protected]a2ef54c2011-10-10 16:20:314589 v8::Handle<v8::Value> result;
4590 WebFrame* web_frame = GetChildFrame(frame_xpath);
4591 if (web_frame)
4592 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4593 if (notify_result) {
[email protected]0cd50aa2013-02-12 22:28:014594 base::ListValue list;
[email protected]a2ef54c2011-10-10 16:20:314595 if (!result.IsEmpty() && web_frame) {
[email protected]a2ef54c2011-10-10 16:20:314596 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4597 v8::Context::Scope context_scope(context);
4598 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514599 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244600 converter.SetRegExpAllowed(true);
4601 base::Value* result_value = converter.FromV8Value(result, context);
[email protected]0cd50aa2013-02-12 22:28:014602 list.Set(0, result_value ? result_value : base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314603 } else {
[email protected]0cd50aa2013-02-12 22:28:014604 list.Set(0, base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314605 }
4606 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4607 }
4608}
4609
[email protected]310ebd6302011-10-10 19:06:284610bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314611 return (!send_preferred_size_changes_ ||
4612 (disable_scrollbars_size_limit_.width() <= width ||
4613 disable_scrollbars_size_limit_.height() <= height));
4614}
4615
[email protected]82114f52012-03-20 22:53:414616int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314617 return enabled_bindings_;
4618}
4619
[email protected]82114f52012-03-20 22:53:414620bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314621 return send_content_state_immediately_;
4622}
4623
[email protected]82114f52012-03-20 22:53:414624float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314625 return filtered_time_per_frame();
4626}
4627
[email protected]e9ff79c2012-10-19 21:31:264628int RenderViewImpl::ShowContextMenu(ContextMenuClient* client,
4629 const ContextMenuParams& params) {
[email protected]860ee642012-10-13 03:46:254630 DCHECK(client); // A null client means "internal" when we issue callbacks.
[email protected]e9ff79c2012-10-19 21:31:264631 ContextMenuParams our_params(params);
[email protected]860ee642012-10-13 03:46:254632 our_params.custom_context.request_id = pending_context_menus_.Add(client);
4633 Send(new ViewHostMsg_ContextMenu(routing_id_, our_params));
4634 return our_params.custom_context.request_id;
[email protected]a2ef54c2011-10-10 16:20:314635}
4636
[email protected]e0fd0eb2012-10-17 21:11:464637void RenderViewImpl::CancelContextMenu(int request_id) {
4638 DCHECK(pending_context_menus_.Lookup(request_id));
4639 pending_context_menus_.Remove(request_id);
4640}
4641
[email protected]82114f52012-03-20 22:53:414642WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314643 return visibilityState();
4644}
4645
[email protected]310ebd6302011-10-10 19:06:284646void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
4647 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314648 return runModalAlertDialog(frame, message);
4649}
4650
[email protected]310ebd6302011-10-10 19:06:284651void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:314652 WebKit::WebFrame* frame,
4653 const WebKit::WebURLRequest& request,
4654 WebKit::WebNavigationPolicy policy) {
4655 loadURLExternally(frame, request, policy);
4656}
4657
4658// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:514659
[email protected]310ebd6302011-10-10 19:06:284660webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]c42de732013-02-16 06:26:314661 const base::FilePath& file_path,
[email protected]4e0616e2010-05-28 14:55:534662 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:204663 if (!PluginChannelHost::IsListening()) {
4664 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:594665 return NULL;
[email protected]94752ee2012-02-10 10:38:204666 }
[email protected]f103ab72009-09-02 17:10:594667
[email protected]00c39612010-03-06 02:53:284668 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:464669 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:324670#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]3b21be92012-11-02 06:00:024671 return webkit::npapi::WebPluginDelegateImpl::Create(file_path, mime_type);
[email protected]6876dff2010-01-15 19:38:094672#else
[email protected]7398dcc2011-09-06 21:40:324673 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:224674 NOTIMPLEMENTED();
4675 return NULL;
[email protected]7b6616f2010-01-14 18:07:554676#endif
[email protected]f103ab72009-09-02 17:10:594677 }
4678
[email protected]4e0616e2010-05-28 14:55:534679 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:594680}
4681
[email protected]6ac77cb2012-05-01 14:49:014682WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
[email protected]c42de732013-02-16 06:26:314683 const base::FilePath& file_path) {
[email protected]e9ff79c2012-10-19 21:31:264684 return GetContentClient()->renderer()->CreatePluginReplacement(
[email protected]6ac77cb2012-05-01 14:49:014685 this, file_path);
4686}
4687
[email protected]310ebd6302011-10-10 19:06:284688void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034689#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274690 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594691#endif
4692}
4693
[email protected]310ebd6302011-10-10 19:06:284694void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034695#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274696 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594697#endif
4698 CleanupWindowInPluginMoves(window);
4699}
4700
[email protected]310ebd6302011-10-10 19:06:284701void RenderViewImpl::DidMovePlugin(
4702 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594703 SchedulePluginMove(move);
4704}
4705
[email protected]310ebd6302011-10-10 19:06:284706void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594707 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524708 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594709}
4710
[email protected]310ebd6302011-10-10 19:06:284711void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594712 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524713 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594714}
4715
[email protected]310ebd6302011-10-10 19:06:284716WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:514717 return &cookie_jar_;
4718}
4719
[email protected]5d65fe92012-06-02 00:48:554720void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074721 Send(new ViewHostMsg_MediaNotification(routing_id_,
4722 reinterpret_cast<int64>(player),
4723 player->hasVideo(),
4724 player->hasAudio(),
4725 true));
4726}
4727
[email protected]5d65fe92012-06-02 00:48:554728void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074729 Send(new ViewHostMsg_MediaNotification(routing_id_,
4730 reinterpret_cast<int64>(player),
4731 player->hasVideo(),
4732 player->hasAudio(),
4733 false));
4734}
4735
[email protected]5d65fe92012-06-02 00:48:554736void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074737 DidPause(player);
4738}
4739
[email protected]310ebd6302011-10-10 19:06:284740void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294741 if (!webview())
4742 return;
4743
[email protected]26aa0482009-09-30 16:55:274744 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054745 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294746}
4747
[email protected]310ebd6302011-10-10 19:06:284748void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364749 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004750 if (!frame)
4751 return;
[email protected]b781ff282011-08-20 06:19:364752
[email protected]e99ef6f2011-10-16 01:13:004753 string16 text;
4754 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:524755 ui::Range range;
[email protected]6d17f6392012-12-05 05:24:544756 if (pepper_helper_->IsPluginFocused()) {
4757 pepper_helper_->GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414758 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524759 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:004760 } else {
[email protected]3c8c74c2012-03-15 07:34:524761 size_t location, length;
4762 if (!webview()->caretOrSelectionRange(&location, &length))
4763 return;
4764
4765 range = ui::Range(location, location + length);
4766
4767 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
4768 // If current focused element is editable, we will send 100 more chars
4769 // before and after selection. It is for input method surrounding text
4770 // feature.
4771 if (location > kExtraCharsBeforeAndAfterSelection)
4772 offset = location - kExtraCharsBeforeAndAfterSelection;
4773 else
4774 offset = 0;
4775 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4776 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4777 if (!webrange.isNull())
4778 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4779 } else {
4780 offset = location;
4781 text = frame->selectionAsText();
4782 // http://crbug.com/101435
4783 // In some case, frame->selectionAsText() returned text's length is not
4784 // equal to the length returned from webview()->caretOrSelectionRange().
4785 // So we have to set the range according to text.length().
4786 range.set_end(range.start() + text.length());
4787 }
[email protected]b781ff282011-08-20 06:19:364788 }
4789
[email protected]b781ff282011-08-20 06:19:364790 // Sometimes we get repeated didChangeSelection calls from webkit when
4791 // the selection hasn't actually changed. We don't want to report these
4792 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004793 if (selection_text_offset_ != offset ||
4794 selection_range_ != range ||
4795 selection_text_ != text) {
4796 selection_text_ = text;
4797 selection_text_offset_ = offset;
4798 selection_range_ = range;
4799 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4800 }
[email protected]47822262013-04-23 17:22:364801 UpdateSelectionBounds();
[email protected]b781ff282011-08-20 06:19:364802}
4803
[email protected]310ebd6302011-10-10 19:06:284804GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4805 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554806 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294807 // If the URL that failed was secure, then the embedding web page was not
4808 // expecting a network attacker to be able to manipulate its contents. As
4809 // we fetch alternate error pages over HTTP, we would be allowing a network
4810 // attacker to manipulate the contents of the response if we tried to use
4811 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154812 return GURL();
initial.commit09911bf2008-07-26 23:55:294813 }
4814
4815 // Grab the base URL from the browser process.
4816 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154817 return GURL();
initial.commit09911bf2008-07-26 23:55:294818
4819 // Strip query params from the failed URL.
4820 GURL::Replacements remove_params;
4821 remove_params.ClearUsername();
4822 remove_params.ClearPassword();
4823 remove_params.ClearQuery();
4824 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554825 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504826 std::string spec_to_send = url_to_send.spec();
4827 // Notify link doctor of the url truncation by sending of "?" at the end.
4828 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414829 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294830
4831 // Construct the query params to send to link doctor.
4832 std::string params(alternate_error_page_url_.query());
4833 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024834 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294835 params.append("&sourceid=chrome");
4836 params.append("&error=");
4837 switch (error_type) {
4838 case DNS_ERROR:
4839 params.append("dnserror");
4840 break;
4841
4842 case HTTP_404:
4843 params.append("http404");
4844 break;
4845
[email protected]5df266ac2008-10-15 19:50:134846 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334847 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134848 break;
4849
initial.commit09911bf2008-07-26 23:55:294850 default:
4851 NOTREACHED() << "unknown ErrorPageType";
4852 }
4853
4854 // OK, build the final url to return.
4855 GURL::Replacements link_doctor_params;
4856 link_doctor_params.SetQueryStr(params);
4857 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4858 return url;
4859}
4860
[email protected]69ddf852012-02-21 23:21:314861GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4862 WebDataSource* ds = frame->dataSource();
4863 if (ds->hasUnreachableURL())
4864 return ds->unreachableURL();
4865
4866 const WebURLRequest& request = ds->request();
4867 return request.url();
4868}
4869
[email protected]310ebd6302011-10-10 19:06:284870WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014871 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494872}
4873
[email protected]55750b32012-09-21 14:05:034874void RenderViewImpl::OnFind(int request_id,
4875 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284876 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274877 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494878
[email protected]872542532011-06-23 00:43:164879 // Check if the plugin still exists in the document.
4880 if (main_frame->document().isPluginDocument() &&
4881 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494882 if (options.findNext) {
4883 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014884 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494885 } else {
[email protected]55750b32012-09-21 14:05:034886 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234887 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114888 // Send "no results".
[email protected]55750b32012-09-21 14:05:034889 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494890 }
4891 }
4892 return;
4893 }
4894
[email protected]b4bb2502009-10-01 22:35:274895 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274896 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294897 WebFrame* search_frame = focused_frame; // start searching focused frame.
4898
4899 bool multi_frame = (frame_after_main != main_frame);
4900
4901 // If we have multiple frames, we don't want to wrap the search within the
4902 // frame, so we check here if we only have main_frame in the chain.
4903 bool wrap_within_frame = !multi_frame;
4904
[email protected]b3f2b912009-04-09 16:18:524905 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294906 bool result = false;
4907
[email protected]7830da3e2009-11-06 16:27:264908 // If something is selected when we start searching it means we cannot just
4909 // increment the current match ordinal; we need to re-generate it.
4910 WebRange current_selection = focused_frame->selectionRange();
4911
initial.commit09911bf2008-07-26 23:55:294912 do {
[email protected]dd7daa82009-08-10 05:46:454913 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594914 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294915
4916 if (!result) {
4917 // don't leave text selected as you move to the next frame.
[email protected]6dd17a8a2013-05-01 05:50:104918 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
4919 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:294920
4921 // Find the next frame, but skip the invisible ones.
4922 do {
4923 // What is the next frame to search? (we might be going backwards). Note
4924 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594925 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274926 search_frame->traverseNext(true) :
4927 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454928 } while (!search_frame->hasVisibleContent() &&
4929 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294930
[email protected]884db412008-11-24 23:46:504931 // Make sure selection doesn't affect the search operation in new frame.
[email protected]6dd17a8a2013-05-01 05:50:104932 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
4933 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:294934
4935 // If we have multiple frames and we have wrapped back around to the
4936 // focused frame, we need to search it once more allowing wrap within
4937 // the frame, otherwise it will report 'no match' if the focused frame has
4938 // reported matches, but no frames after the focused_frame contain a
4939 // match for the search word(s).
4940 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454941 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594942 request_id, search_text, options, true, // Force wrapping.
4943 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294944 }
4945 }
4946
[email protected]26aa0482009-09-30 16:55:274947 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294948 } while (!result && search_frame != focused_frame);
4949
[email protected]7830da3e2009-11-06 16:27:264950 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294951 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454952 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294953 } else {
4954 // If nothing is found, set result to "0 of 0", otherwise, set it to
4955 // "-1 of 1" to indicate that we found at least one item, but we don't know
4956 // yet what is active.
4957 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4958 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294959
[email protected]4f3dc372009-02-24 00:10:294960 // If we find no matches then this will be our last status update.
4961 // Otherwise the scoping effort will send more results.
4962 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294963
[email protected]55750b32012-09-21 14:05:034964 SendFindReply(request_id, match_count, ordinal, selection_rect,
4965 final_status_update);
initial.commit09911bf2008-07-26 23:55:294966
initial.commit09911bf2008-07-26 23:55:294967 // Scoping effort begins, starting with the mainframe.
4968 search_frame = main_frame;
4969
[email protected]dd7daa82009-08-10 05:46:454970 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294971
4972 do {
4973 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454974 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294975
4976 // We don't start another scoping effort unless at least one match has
4977 // been found.
4978 if (result) {
4979 // Start new scoping request. If the scoping function determines that it
4980 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454981 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594982 search_text,
4983 options,
initial.commit09911bf2008-07-26 23:55:294984 true); // reset the tickmarks
4985 }
4986
4987 // Iterate to the next frame. The frame will not necessarily scope, for
4988 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274989 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294990 } while (search_frame != main_frame);
4991 }
4992}
4993
[email protected]e9ff79c2012-10-19 21:31:264994void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494995 WebView* view = webview();
4996 if (!view)
4997 return;
4998
4999 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:165000 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:015001 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:495002 return;
5003 }
5004
[email protected]e9ff79c2012-10-19 21:31:265005 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]6dd17a8a2013-05-01 05:50:105006 if (clear_selection) {
5007 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
5008 GetFocusedNode());
5009 }
[email protected]24a7f3c2010-03-25 08:26:495010
5011 WebFrame* frame = view->mainFrame();
5012 while (frame) {
5013 frame->stopFinding(clear_selection);
5014 frame = frame->traverseNext(false);
5015 }
5016
[email protected]e9ff79c2012-10-19 21:31:265017 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:495018 WebFrame* focused_frame = view->focusedFrame();
5019 if (focused_frame) {
5020 WebDocument doc = focused_frame->document();
5021 if (!doc.isNull()) {
5022 WebNode node = doc.focusedNode();
5023 if (!node.isNull())
5024 node.simulateClick();
5025 }
5026 }
5027 }
5028}
5029
[email protected]59363fc92012-09-05 03:46:315030#if defined(OS_ANDROID)
5031void RenderViewImpl::OnActivateNearestFindResult(int request_id,
5032 float x, float y) {
5033 if (!webview())
5034 return;
5035
5036 WebFrame* main_frame = webview()->mainFrame();
5037 WebRect selection_rect;
5038 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
5039 &selection_rect);
5040 if (ordinal == -1) {
5041 // Something went wrong, so send a no-op reply (force the main_frame to
5042 // report the current match count) in case the host is waiting for a
5043 // response due to rate-limiting).
5044 main_frame->increaseMatchCount(0, request_id);
5045 return;
5046 }
5047
[email protected]55750b32012-09-21 14:05:035048 SendFindReply(request_id,
5049 -1 /* number_of_matches */,
5050 ordinal,
5051 selection_rect,
5052 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:315053}
5054
5055void RenderViewImpl::OnFindMatchRects(int current_version) {
5056 if (!webview())
5057 return;
5058
5059 WebFrame* main_frame = webview()->mainFrame();
5060 std::vector<gfx::RectF> match_rects;
5061
5062 int rects_version = main_frame->findMatchMarkersVersion();
5063 if (current_version != rects_version) {
5064 WebVector<WebFloatRect> web_match_rects;
5065 main_frame->findMatchRects(web_match_rects);
5066 match_rects.reserve(web_match_rects.size());
5067 for (size_t i = 0; i < web_match_rects.size(); ++i)
5068 match_rects.push_back(gfx::RectF(web_match_rects[i]));
5069 }
5070
5071 gfx::RectF active_rect = main_frame->activeFindMatchRect();
5072 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
5073 rects_version,
5074 match_rects,
5075 active_rect));
5076}
5077#endif
5078
[email protected]e9ff79c2012-10-19 21:31:265079void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:515080 if (!webview()) // Not sure if this can happen, but no harm in being safe.
5081 return;
5082
[email protected]258d31122010-05-09 10:59:415083 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:105084
[email protected]b75b8292010-10-01 07:28:255085 double old_zoom_level = webview()->zoomLevel();
5086 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:265087 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:255088 zoom_level = 0;
5089 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
5090 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:485091 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:255092 } else {
5093 // Either the user hit the zoom factor limit and thus the zoom level is now
5094 // not a whole number, or a plugin changed it to a custom value. We want
5095 // to go to the next whole number so that the user can always get back to
5096 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:485097 if ((old_zoom_level > 1 && zoom > 0) ||
5098 (old_zoom_level < 1 && zoom < 0)) {
5099 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:255100 } else {
5101 // We're going towards 100%, so first go to the next whole number.
5102 zoom_level = static_cast<int>(old_zoom_level);
5103 }
5104 }
[email protected]b75b8292010-10-01 07:28:255105 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:415106 zoomLevelChanged();
5107}
5108
[email protected]e9ff79c2012-10-19 21:31:265109void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x,
5110 int zoom_center_y) {
[email protected]47578fa02011-11-02 19:34:415111 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
5112 kScalingIncrementForGesture);
5113}
5114
[email protected]e9ff79c2012-10-19 21:31:265115void RenderViewImpl::ZoomFactorHelper(PageZoom zoom,
[email protected]47578fa02011-11-02 19:34:415116 int zoom_center_x,
5117 int zoom_center_y,
5118 float scaling_increment) {
5119 if (!webview()) // Not sure if this can happen, but no harm in being safe.
5120 return;
5121
[email protected]c514d6372011-08-16 22:54:445122 double old_page_scale_factor = webview()->pageScaleFactor();
5123 double page_scale_factor;
[email protected]e9ff79c2012-10-19 21:31:265124 if (zoom == PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:445125 page_scale_factor = 1.0;
5126 } else {
5127 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:415128 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:445129 }
[email protected]47578fa02011-11-02 19:34:415130 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:095131 webview()->setPageScaleFactor(page_scale_factor,
5132 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:415133 }
[email protected]40bd6582009-12-04 23:49:515134}
5135
[email protected]310ebd6302011-10-10 19:06:285136void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:175137 webview()->hidePopups();
5138 webview()->setZoomLevel(false, zoom_level);
5139 zoomLevelChanged();
5140}
5141
[email protected]310ebd6302011-10-10 19:06:285142void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
5143 double zoom_level) {
[email protected]cbe55d22013-02-14 17:04:335144#if !defined(OS_ANDROID)
5145 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
5146 // for legacy WebView text scaling emulation. Thus, the code that resets
5147 // the zoom level from this map will be effectively resetting text zoom level.
[email protected]9d797f32010-04-23 07:17:545148 host_zoom_levels_[url] = zoom_level;
[email protected]cbe55d22013-02-14 17:04:335149#endif
initial.commit09911bf2008-07-26 23:55:295150}
5151
[email protected]310ebd6302011-10-10 19:06:285152void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:275153 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:295154}
5155
[email protected]310ebd6302011-10-10 19:06:285156void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:275157 WebString no_encoding;
5158 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:185159}
5160
[email protected]310ebd6302011-10-10 19:06:285161WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:455162 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:275163 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:455164
5165 // xpath string can represent a frame deep down the tree (across multiple
5166 // frame DOMs).
5167 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
5168 // should break into 2 xpaths
5169 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:415170 std::vector<string16> xpaths;
5171 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:455172
[email protected]26aa0482009-09-30 16:55:275173 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:415174 for (std::vector<string16>::const_iterator i = xpaths.begin();
5175 frame && i != xpaths.end(); ++i) {
5176 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:295177 }
5178
[email protected]dd7daa82009-08-10 05:46:455179 return frame;
initial.commit09911bf2008-07-26 23:55:295180}
5181
[email protected]310ebd6302011-10-10 19:06:285182void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
5183 const string16& jscript,
5184 int id,
5185 bool notify_result) {
[email protected]c76faea2013-03-26 07:42:425186 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest",
5187 TRACE_EVENT_SCOPE_THREAD);
[email protected]882b7b22010-10-05 03:34:535188 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:295189}
5190
[email protected]f546640b2012-05-15 00:03:495191void RenderViewImpl::OnPostMessageEvent(
5192 const ViewMsg_PostMessage_Params& params) {
[email protected]bf4a2312013-04-23 00:32:115193 // TODO(nasko): Support sending to subframes.
[email protected]e12dbe6f2012-10-04 22:11:195194 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495195
5196 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:495197 WebFrame* source_frame = NULL;
5198 if (params.source_routing_id != MSG_ROUTING_NONE) {
5199 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
5200 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:195201 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495202 }
5203
5204 // Create an event with the message. The final parameter to initMessageEvent
5205 // is the last event ID, which is not used with postMessage.
5206 WebDOMEvent event = frame->document().createEvent("MessageEvent");
5207 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
5208 msg_event.initMessageEvent("message",
5209 // |canBubble| and |cancellable| are always false
5210 false, false,
5211 WebSerializedScriptValue::fromString(params.data),
5212 params.source_origin, source_frame, "");
5213
5214 // We must pass in the target_origin to do the security check on this side,
5215 // since it may have changed since the original postMessage call was made.
5216 WebSecurityOrigin target_origin;
5217 if (!params.target_origin.empty()) {
5218 target_origin =
5219 WebSecurityOrigin::createFromString(WebString(params.target_origin));
5220 }
5221 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
5222}
5223
[email protected]310ebd6302011-10-10 19:06:285224void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
5225 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:415226 WebFrame* frame = GetChildFrame(frame_xpath);
5227 if (!frame)
[email protected]216813952011-05-19 22:21:265228 return;
[email protected]ae461542009-06-19 19:03:415229
[email protected]01cf589c2011-07-28 18:04:035230 frame->document().insertUserStyleSheet(
5231 WebString::fromUTF8(css),
5232 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:485233}
5234
[email protected]310ebd6302011-10-10 19:06:285235void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]940ed1d2012-11-27 21:03:215236 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
5237 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
[email protected]dcc72db2013-01-02 00:44:185238 RenderThread::Get()->RegisterExtension(WebUIExtension::Get());
[email protected]940ed1d2012-11-27 21:03:215239 new WebUIExtensionData(this);
5240 }
5241
[email protected]81e63782009-02-27 19:35:095242 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:045243
5244 // Keep track of the total bindings accumulated in this process.
5245 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:295246}
5247
[email protected]310ebd6302011-10-10 19:06:285248void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
5249 const gfx::Point& client_point,
5250 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425251 WebDragOperationsMask ops,
5252 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555253 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]c10680312013-05-31 15:22:055254 WebDropDataToDragData(drop_data),
[email protected]59f4f2fa2011-03-23 01:00:555255 client_point,
5256 screen_point,
[email protected]1f2230b2012-05-17 23:43:425257 ops,
5258 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555259
5260 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5261}
5262
[email protected]310ebd6302011-10-10 19:06:285263void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
5264 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425265 WebDragOperationsMask ops,
5266 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555267 WebDragOperation operation = webview()->dragTargetDragOver(
5268 client_point,
5269 screen_point,
[email protected]1f2230b2012-05-17 23:43:425270 ops,
5271 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555272
5273 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5274}
5275
[email protected]310ebd6302011-10-10 19:06:285276void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555277 webview()->dragTargetDragLeave();
5278}
5279
[email protected]310ebd6302011-10-10 19:06:285280void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425281 const gfx::Point& screen_point,
5282 int key_modifiers) {
5283 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575284
5285 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555286}
5287
[email protected]310ebd6302011-10-10 19:06:285288void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5289 const gfx::Point& screen_point,
5290 bool ended,
5291 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035292 if (ended) {
[email protected]26aa0482009-09-30 16:55:275293 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205294 } else {
5295 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035296 }
initial.commit09911bf2008-07-26 23:55:295297}
5298
[email protected]310ebd6302011-10-10 19:06:285299void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275300 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295301}
5302
[email protected]310ebd6302011-10-10 19:06:285303void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595304 webkit_preferences_ = prefs;
[email protected]3184f90b2013-05-01 18:17:535305 webkit_glue::ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:295306}
5307
[email protected]38761452012-10-18 16:31:595308void RenderViewImpl::OnUpdateTimezone() {
5309 if (webview())
5310 NotifyTimezoneChange(webview()->mainFrame());
5311}
5312
[email protected]310ebd6302011-10-10 19:06:285313void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295314 alternate_error_page_url_ = url;
5315}
5316
[email protected]310ebd6302011-10-10 19:06:285317void RenderViewImpl::OnCustomContextMenuAction(
[email protected]e9ff79c2012-10-19 21:31:265318 const CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085319 unsigned action) {
[email protected]860ee642012-10-13 03:46:255320 if (custom_context.request_id) {
5321 // External context menu request, look in our map.
[email protected]e9ff79c2012-10-19 21:31:265322 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:255323 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:465324 if (client)
5325 client->OnMenuAction(custom_context.request_id, action);
[email protected]860ee642012-10-13 03:46:255326 } else {
5327 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:085328 webview()->performCustomContextMenuAction(action);
[email protected]860ee642012-10-13 03:46:255329 }
[email protected]a0c7153e2009-12-09 14:36:335330}
5331
[email protected]310ebd6302011-10-10 19:06:285332void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515333 int id,
[email protected]c42de732013-02-16 06:26:315334 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:515335 if (!enumeration_completions_[id])
5336 return;
5337
5338 WebVector<WebString> ws_file_names(paths.size());
5339 for (size_t i = 0; i < paths.size(); ++i)
[email protected]bb0e79472012-10-23 04:36:345340 ws_file_names[i] = webkit_base::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:515341
5342 enumeration_completions_[id]->didChooseFile(ws_file_names);
5343 enumeration_completions_.erase(id);
5344}
5345
[email protected]fb11b6a42012-03-14 07:25:125346void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395347 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365348 // This could happen if we navigated to a different page before the user
5349 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475350 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365351 return;
5352
[email protected]b5188522012-03-15 00:18:045353 // Convert Chrome's SelectedFileInfo list to WebKit's.
5354 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5355 files.size());
5356 for (size_t i = 0; i < files.size(); ++i) {
5357 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]bb0e79472012-10-23 04:36:345358 selected_file.path = webkit_base::FilePathToWebString(files[i].local_path);
5359 selected_file.displayName = webkit_base::FilePathStringToWebString(
[email protected]b5188522012-03-15 00:18:045360 files[i].display_name);
5361 selected_files[i] = selected_file;
5362 }
[email protected]a1128322009-10-06 18:38:465363
[email protected]cdaf8d02010-03-30 19:52:475364 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045365 file_chooser_completions_.front()->completion->didChooseFile(
5366 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475367 file_chooser_completions_.pop_front();
5368
5369 // If there are more pending file chooser requests, schedule one now.
5370 if (!file_chooser_completions_.empty()) {
5371 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5372 file_chooser_completions_.front()->params));
5373 }
initial.commit09911bf2008-07-26 23:55:295374}
5375
[email protected]244ac1892011-12-02 17:04:475376void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5377 const gfx::Size& max_size) {
5378 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5379 if (!webview())
5380 return;
[email protected]97e1bf72013-03-06 14:06:055381 auto_resize_mode_ = true;
[email protected]61e2b3cc2012-03-02 16:13:345382 webview()->enableAutoResizeMode(min_size, max_size);
5383}
5384
5385void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5386 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5387 if (!webview())
5388 return;
[email protected]97e1bf72013-03-06 14:06:055389 auto_resize_mode_ = false;
[email protected]61e2b3cc2012-03-02 16:13:345390 webview()->disableAutoResizeMode();
5391
[email protected]eac2b362013-05-22 07:01:455392 if (!new_size.IsEmpty()) {
5393 Resize(new_size,
5394 physical_backing_size_,
5395 overdraw_bottom_height_,
5396 resizer_rect_,
5397 is_fullscreen_,
5398 NO_RESIZE_ACK);
5399 }
[email protected]244ac1892011-12-02 17:04:475400}
5401
[email protected]2bf834f2011-11-17 20:02:215402void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245403 if (send_preferred_size_changes_)
5404 return;
[email protected]9fb325e2010-05-06 18:23:245405 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395406
[email protected]d812fd12011-05-27 23:05:075407 // Start off with an initial preferred size notification (in case
5408 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595409 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085410}
5411
[email protected]310ebd6302011-10-10 19:06:285412void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105413 const gfx::Size& disable_scrollbar_size_limit) {
5414 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5415}
5416
[email protected]310ebd6302011-10-10 19:06:285417void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:265418 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505419 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515420 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375421 UpdateFontRenderingFromRendererPrefs();
[email protected]38a85712013-01-02 22:45:025422
5423#if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015424 if (renderer_prefs.use_custom_colors) {
5425 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
5426 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
5427 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:025428#if defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015429 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]93623c5d2009-12-10 21:40:325430 renderer_prefs.thumb_inactive_color,
5431 renderer_prefs.thumb_active_color,
5432 renderer_prefs.track_color);
[email protected]38a85712013-01-02 22:45:025433#endif // defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015434
5435 if (webview()) {
5436#if defined(TOOLKIT_GTK)
5437 webview()->setScrollbarColors(
5438 renderer_prefs.thumb_inactive_color,
5439 renderer_prefs.thumb_active_color,
5440 renderer_prefs.track_color);
5441#endif // defined(TOOLKIT_GTK)
5442 webview()->setSelectionColors(
5443 renderer_prefs.active_selection_bg_color,
5444 renderer_prefs.active_selection_fg_color,
5445 renderer_prefs.inactive_selection_bg_color,
5446 renderer_prefs.inactive_selection_fg_color);
5447 webview()->themeChanged();
5448 }
[email protected]644d77e2010-01-27 01:03:105449 }
[email protected]38a85712013-01-02 22:45:025450#endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]d299d972012-03-23 02:26:555451
[email protected]107c0532013-02-06 02:34:095452 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
5453 RenderThreadImpl::current()->SetFlingCurveParameters(
5454 renderer_prefs.touchpad_fling_profile,
5455 renderer_prefs.touchscreen_fling_profile);
5456
[email protected]d051d9a2011-12-10 02:02:505457 // If the zoom level for this page matches the old zoom default, and this
5458 // is not a plugin, update the zoom level to match the new default.
5459 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]cbe55d22013-02-14 17:04:335460 !ZoomValuesEqual(old_zoom_level,
5461 renderer_preferences_.default_zoom_level) &&
[email protected]e9ff79c2012-10-19 21:31:265462 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]d051d9a2011-12-10 02:02:505463 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
5464 zoomLevelChanged();
5465 }
[email protected]80d96fa2009-06-10 22:34:515466}
5467
[email protected]310ebd6302011-10-10 19:06:285468void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5469 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285470 if (webview())
5471 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565472}
5473
[email protected]77829642012-05-15 14:47:175474void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
5475 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5476}
5477
[email protected]81375e872012-01-11 21:40:365478void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5479 const WebPluginAction& action) {
5480 if (webview())
5481 webview()->performPluginAction(action, location);
5482}
5483
[email protected]310ebd6302011-10-10 19:06:285484void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195485 const GURL& page_url) {
5486 // Prepare list to storage all savable resource links.
5487 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465488 std::vector<GURL> referrer_urls_list;
5489 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195490 std::vector<GURL> frames_list;
[email protected]12a936d2013-05-15 04:55:495491 SavableResourcesResult result(&resources_list,
5492 &referrer_urls_list,
5493 &referrer_policies_list,
5494 &frames_list);
[email protected]18d5be92011-07-25 18:00:195495
[email protected]e9ff79c2012-10-19 21:31:265496 // webkit/ doesn't know about Referrer.
[email protected]12a936d2013-05-15 04:55:495497 if (!GetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195498 webview(),
5499 page_url,
5500 &result,
[email protected]e9ff79c2012-10-19 21:31:265501 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195502 // If something is wrong when collecting all savable resource links,
5503 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465504 referrer_urls_list.clear();
5505 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195506 resources_list.clear();
5507 frames_list.clear();
5508 }
5509
[email protected]e9ff79c2012-10-19 21:31:265510 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:465511 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5512 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5513 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:265514 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:465515 }
5516
[email protected]18d5be92011-07-25 18:00:195517 // Send result of all savable resource links to embedder.
5518 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5519 resources_list,
5520 referrers_list,
5521 frames_list));
5522}
5523
[email protected]310ebd6302011-10-10 19:06:285524void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195525 const std::vector<GURL>& links,
[email protected]c42de732013-02-16 06:26:315526 const std::vector<base::FilePath>& local_paths,
5527 const base::FilePath& local_directory_name) {
[email protected]18d5be92011-07-25 18:00:195528
5529 // Convert std::vector of GURLs to WebVector<WebURL>
5530 WebVector<WebURL> weburl_links(links);
5531
5532 // Convert std::vector of std::strings to WebVector<WebString>
5533 WebVector<WebString> webstring_paths(local_paths.size());
5534 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]bb0e79472012-10-23 04:36:345535 webstring_paths[i] = webkit_base::FilePathToWebString(local_paths[i]);
[email protected]18d5be92011-07-25 18:00:195536
5537 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5538 webstring_paths,
[email protected]bb0e79472012-10-23 04:36:345539 webkit_base::FilePathToWebString(
[email protected]18d5be92011-07-25 18:00:195540 local_directory_name));
5541}
5542
[email protected]310ebd6302011-10-10 19:06:285543void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125544 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275545 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125546 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5547 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5548 before_unload_start_time,
5549 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295550}
5551
[email protected]310ebd6302011-10-10 19:06:285552void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]73eb2602012-02-09 19:50:555553 // Only run unload if we're not swapped out yet, but send the ack either way.
5554 if (!is_swapped_out_) {
5555 // Swap this RenderView out so the tab can navigate to a page rendered by a
5556 // different process. This involves running the unload handler and clearing
5557 // the page. Once WasSwappedOut is called, we also allow this process to
5558 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155559
[email protected]73eb2602012-02-09 19:50:555560 // Send an UpdateState message before we get swapped out.
5561 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155562
[email protected]73eb2602012-02-09 19:50:555563 // Synchronously run the unload handler before sending the ACK.
5564 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155565
[email protected]73eb2602012-02-09 19:50:555566 // Swap out and stop sending any IPC messages that are not ACKs.
5567 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155568
[email protected]6169a5772013-05-29 17:41:145569 // Now that we're swapped out and filtering IPC messages, stop loading to
5570 // ensure that no other in-progress navigation continues. We do this here
5571 // to avoid sending a DidStopLoading message to the browser process.
5572 OnStop();
5573
[email protected]285f4bb82012-04-17 15:57:285574 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555575 // run a second time, thanks to a check in FrameLoader::stopLoading.
5576 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285577 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375578 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285579
5580 // Let WebKit know that this view is hidden so it can drop resources and
5581 // stop compositing.
5582 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555583 }
[email protected]992db4c2011-05-12 15:37:155584
5585 // Just echo back the params in the ACK.
5586 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
5587}
5588
[email protected]0720b532012-08-28 19:23:375589void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445590 // We use loadRequest instead of loadHTMLString because the former commits
5591 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:265592 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:445593 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]890b06ca2012-12-13 21:07:365594 CHECK(is_swapped_out_);
[email protected]e9ff79c2012-10-19 21:31:265595 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:445596 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375597 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445598}
5599
[email protected]310ebd6302011-10-10 19:06:285600void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375601 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295602 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5603 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5604 // in the onunload handler from appearing. For now, we're bypassing that and
5605 // calling the FrameLoader's CloseURL method directly. This should be
5606 // revisited to avoid having two ways to close a page. Having a single way
5607 // to close that can run onunload is also useful for fixing
5608 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275609 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295610
[email protected]992db4c2011-05-12 15:37:155611 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295612}
5613
[email protected]310ebd6302011-10-10 19:06:285614void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025615#if defined(USE_AURA)
5616 // Aura doesn't care if we switch themes.
5617#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525618 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465619 if (webview())
5620 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575621#else // defined(OS_WIN)
5622 // TODO(port): we don't support theming on non-Windows platforms yet
5623 NOTIMPLEMENTED();
5624#endif
initial.commit09911bf2008-07-26 23:55:295625}
5626
[email protected]310ebd6302011-10-10 19:06:285627void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:085628 if (decrement_shared_popup_at_destruction_)
5629 shared_popup_counter_->data--;
5630 shared_popup_counter_ = new SharedRenderViewCounter(0);
5631 decrement_shared_popup_at_destruction_ = false;
5632}
5633
[email protected]310ebd6302011-10-10 19:06:285634bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5635 const WebURLError& error,
5636 bool replace) {
[email protected]15d79e12009-08-02 19:23:455637 // We only show alternate error pages in the main frame. They are
5638 // intended to assist the user when navigating, so there is not much
5639 // value in showing them for failed subframes. Ideally, we would be
5640 // able to use the TYPED transition type for this, but that flag is
5641 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455642 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455643 return false;
5644
5645 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375646 // connection failure.
[email protected]15d79e12009-08-02 19:23:455647 int ec = error.reason;
5648 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5649 ec != net::ERR_CONNECTION_FAILED &&
5650 ec != net::ERR_CONNECTION_REFUSED &&
5651 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415652 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455653 return false;
[email protected]82114f52012-03-20 22:53:415654 }
[email protected]15d79e12009-08-02 19:23:455655
5656 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555657 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455658 if (!error_page_url.is_valid())
5659 return false;
5660
[email protected]11a65772013-04-27 00:36:425661 WebDataSource* ds = frame->provisionalDataSource();
5662 const WebURLRequest& failed_request = ds->request();
5663
[email protected]15d79e12009-08-02 19:23:455664 // Load an empty page first so there is an immediate response to the error,
5665 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455666 frame->loadHTMLString(std::string(),
[email protected]e9ff79c2012-10-19 21:31:265667 GURL(kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455668 error.unreachableURL,
5669 replace);
5670
5671 // Now, create a fetcher for the error page and associate it with the data
5672 // source we just created via the LoadHTMLString call. That way if another
5673 // navigation occurs, the fetcher will get destroyed.
[email protected]e20b88d2013-04-09 15:28:375674 InternalDocumentStateData* internal_data =
5675 InternalDocumentStateData::FromDataSource(frame->provisionalDataSource());
5676 internal_data->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455677 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:425678 error_page_url, frame, failed_request, error,
[email protected]6e806822011-11-19 01:51:085679 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5680 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455681 return true;
5682}
5683
[email protected]310ebd6302011-10-10 19:06:285684void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
[email protected]11a65772013-04-27 00:36:425685 const WebURLRequest& original_request,
[email protected]310ebd6302011-10-10 19:06:285686 const WebURLError& original_error,
5687 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455688 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095689 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555690 // will simply display a default error page.
[email protected]11a65772013-04-27 00:36:425691 LoadNavigationErrorPage(frame, original_request, original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455692}
5693
[email protected]310ebd6302011-10-10 19:06:285694void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005695 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475696 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005697}
5698
[email protected]0fdd5012013-05-29 08:05:565699void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]cda45c02010-02-25 19:28:105700 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475701 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105702 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205703 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]0fdd5012013-05-29 08:05:565704 ShouldDisplayScrollbars(params.new_size.width(),
5705 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:105706 }
[email protected]dd6afca2011-08-13 03:44:315707 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105708 }
5709
[email protected]0fdd5012013-05-29 08:05:565710 RenderWidget::OnResize(params);
[email protected]30f75e62009-02-25 22:01:005711}
[email protected]0aa477bd2009-03-23 22:21:435712
[email protected]29ed96a2012-02-04 18:12:165713void RenderViewImpl::WillInitiatePaint() {
5714 // Notify the pepper plugins that we're about to paint.
[email protected]6d17f6392012-12-05 05:24:545715 pepper_helper_->ViewWillInitiatePaint();
[email protected]29ed96a2012-02-04 18:12:165716}
5717
[email protected]310ebd6302011-10-10 19:06:285718void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:165719 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]6d17f6392012-12-05 05:24:545720 pepper_helper_->ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:285721}
5722
[email protected]310ebd6302011-10-10 19:06:285723void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:285724 // Notify any pepper plugins that we painted. This will call into the plugin,
5725 // and we it may ask to close itself as a result. This will, in turn, modify
5726 // our set, possibly invalidating the iterator. So we iterate on a copy that
5727 // won't change out from under us.
[email protected]6d17f6392012-12-05 05:24:545728 pepper_helper_->ViewFlushedPaint();
[email protected]53900d52010-06-16 04:25:015729
[email protected]5b1dec8c2012-02-07 04:35:385730 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5731 // See crbug.com/112921.
5732 if (!webview())
5733 return;
5734
[email protected]00c39612010-03-06 02:53:285735 WebFrame* main_frame = webview()->mainFrame();
5736
5737 // If we have a provisional frame we are between the start and commit stages
5738 // of loading and we don't want to save stats.
5739 if (!main_frame->provisionalDataSource()) {
5740 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075741 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]92d457802013-04-01 19:18:495742 InternalDocumentStateData* data =
[email protected]e20b88d2013-04-09 15:28:375743 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]92d457802013-04-01 19:18:495744 if (data->did_first_visually_non_empty_layout() &&
5745 !data->did_first_visually_non_empty_paint()) {
5746 data->set_did_first_visually_non_empty_paint(true);
5747 Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_,
5748 page_id_));
5749 }
5750
[email protected]05c8e502010-08-15 15:13:525751 // TODO(jar): The following code should all be inside a method, probably in
5752 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285753 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075754 if (document_state->first_paint_time().is_null()) {
5755 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285756 }
[email protected]007733c2011-11-17 00:34:075757 if (document_state->first_paint_after_load_time().is_null() &&
5758 !document_state->finish_load_time().is_null()) {
5759 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285760 }
5761 }
5762}
5763
[email protected]310ebd6302011-10-10 19:06:285764webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155765 const gfx::Rect& paint_bounds,
5766 TransportDIB** dib,
5767 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:205768 gfx::Rect* clip,
5769 float* scale_factor) {
[email protected]6d17f6392012-12-05 05:24:545770 return pepper_helper_->GetBitmapForOptimizedPluginPaint(
[email protected]0f3a2d12012-09-01 03:37:205771 paint_bounds, dib, location, clip, scale_factor);
[email protected]ca4847f2010-09-24 05:39:155772}
5773
[email protected]ceb36f7d2012-10-31 18:33:245774gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075775 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:245776 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525777}
5778
[email protected]310ebd6302011-10-10 19:06:285779void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165780 if (webview())
[email protected]26aa0482009-09-30 16:55:275781 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165782}
5783
[email protected]310ebd6302011-10-10 19:06:285784void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145785 if (webview())
[email protected]b4bb2502009-10-01 22:35:275786 webview()->setIsTransparent(!background.empty());
[email protected]ba91a792013-02-06 09:48:285787 if (compositor_)
5788 compositor_->setHasTransparentBackground(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145789
5790 SetBackground(background);
5791}
5792
[email protected]2a84f9d2012-06-05 21:50:435793void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5794 if (accessibility_mode_ == new_mode)
5795 return;
5796 accessibility_mode_ = new_mode;
5797 if (renderer_accessibility_) {
5798 delete renderer_accessibility_;
5799 renderer_accessibility_ = NULL;
5800 }
5801 if (accessibility_mode_ == AccessibilityModeComplete)
5802 renderer_accessibility_ = new RendererAccessibilityComplete(this);
5803 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5804 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
5805}
5806
[email protected]310ebd6302011-10-10 19:06:285807void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345808 if (webview())
[email protected]b4bb2502009-10-01 22:35:275809 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265810
5811#if defined(OS_MACOSX)
5812 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5813 for (plugin_it = plugin_delegates_.begin();
5814 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5815 (*plugin_it)->SetWindowFocus(active);
5816 }
5817#endif
[email protected]8c66c5a2009-07-22 17:26:345818}
5819
[email protected]6ce7abc52010-02-02 18:40:145820#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285821void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:145822 // Inform plugins that their container has changed visibility.
5823 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5824 for (plugin_it = plugin_delegates_.begin();
5825 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5826 (*plugin_it)->SetContainerVisibility(visible);
5827 }
5828}
[email protected]1e6e3c992010-02-08 15:52:135829
[email protected]310ebd6302011-10-10 19:06:285830void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5831 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135832 // Inform plugins that their window's frame has changed.
5833 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5834 for (plugin_it = plugin_delegates_.begin();
5835 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5836 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5837 }
5838}
[email protected]935d63d2010-10-15 23:31:555839
[email protected]310ebd6302011-10-10 19:06:285840void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5841 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135842 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555843 // applies to it or not, so inform all the delegates.
5844 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5845 for (plugin_it = plugin_delegates_.begin();
5846 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135847 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555848 }
5849}
[email protected]6ce7abc52010-02-02 18:40:145850#endif // OS_MACOSX
5851
[email protected]310ebd6302011-10-10 19:06:285852void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595853 // We need to grab a pointer to the doomed WebView before we destroy it.
5854 WebView* doomed = webview();
5855 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495856 g_view_map.Get().erase(doomed);
[email protected]058561b2012-12-03 06:48:225857 g_routing_id_view_map.Get().erase(routing_id_);
[email protected]60c42a8c72009-10-09 04:08:595858}
5859
[email protected]310ebd6302011-10-10 19:06:285860void RenderViewImpl::DidHandleKeyEvent() {
[email protected]b2324b092012-11-01 10:34:115861 ClearEditCommands();
[email protected]446705872009-09-10 07:22:485862}
5863
[email protected]310ebd6302011-10-10 19:06:285864bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]41d86852012-11-07 12:23:245865 possible_drag_event_info_.event_source =
5866 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
5867 possible_drag_event_info_.event_location =
5868 gfx::Point(event.globalX, event.globalY);
[email protected]6d17f6392012-12-05 05:24:545869 pepper_helper_->WillHandleMouseEvent();
[email protected]217690d2012-01-27 07:33:115870
5871 // If the mouse is locked, only the current owner of the mouse lock can
5872 // process mouse events.
5873 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375874}
5875
[email protected]41d86852012-11-07 12:23:245876bool RenderViewImpl::WillHandleGestureEvent(
5877 const WebKit::WebGestureEvent& event) {
5878 possible_drag_event_info_.event_source =
5879 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
5880 possible_drag_event_info_.event_location =
5881 gfx::Point(event.globalX, event.globalY);
5882 return false;
5883}
5884
[email protected]2b942c332012-04-25 16:26:265885void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515886 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065887}
5888
[email protected]310ebd6302011-10-10 19:06:285889void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245890 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5891}
5892
[email protected]3d5c243b2012-11-30 00:26:015893bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const {
5894 if (!webview())
5895 return false;
5896 return webview()->hasTouchEventHandlersAt(point);
5897}
5898
[email protected]310ebd6302011-10-10 19:06:285899void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435900 RenderWidget::OnWasHidden();
5901
[email protected]2d7b82c2012-06-01 05:57:505902#if defined(OS_ANDROID)
5903 // Inform WebMediaPlayerManagerAndroid to release all media player resources.
[email protected]5c469b42012-11-26 22:25:305904 // unless some audio is playing.
[email protected]263135d2012-11-15 13:01:565905 // If something is in progress the resource will not be freed, it will
5906 // only be freed once the tab is destroyed or if the user navigates away
5907 // via WebMediaPlayerAndroid::Destroy
[email protected]5c469b42012-11-26 22:25:305908 media_player_manager_->ReleaseMediaResources();
[email protected]6392d982013-04-16 16:59:225909
5910#if defined(ENABLE_WEBRTC)
5911 RenderThreadImpl::current()->video_capture_impl_manager()->
5912 SuspendDevices(true);
5913#endif
[email protected]2d7b82c2012-06-01 05:57:505914#endif
5915
[email protected]8869d392013-05-07 15:34:265916 if (webview())
[email protected]f59203a2011-06-07 10:01:445917 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075918
[email protected]204f1df2012-01-04 20:21:135919 // Inform PPAPI plugins that their page is no longer visible.
[email protected]6d17f6392012-12-05 05:24:545920 pepper_helper_->PageVisibilityChanged(false);
[email protected]204f1df2012-01-04 20:21:135921
[email protected]a6939ca42011-02-18 17:58:075922#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135923 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435924 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5925 for (plugin_it = plugin_delegates_.begin();
5926 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5927 (*plugin_it)->SetContainerVisibility(false);
5928 }
[email protected]a6939ca42011-02-18 17:58:075929#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435930}
5931
[email protected]9e2e4632012-07-27 16:38:415932void RenderViewImpl::OnWasShown(bool needs_repainting) {
5933 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435934
[email protected]6392d982013-04-16 16:59:225935#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
5936 RenderThreadImpl::current()->video_capture_impl_manager()->
5937 SuspendDevices(false);
5938#endif
5939
[email protected]8869d392013-05-07 15:34:265940 if (webview())
[email protected]f59203a2011-06-07 10:01:445941 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075942
[email protected]204f1df2012-01-04 20:21:135943 // Inform PPAPI plugins that their page is visible.
[email protected]6d17f6392012-12-05 05:24:545944 pepper_helper_->PageVisibilityChanged(true);
[email protected]204f1df2012-01-04 20:21:135945
[email protected]a6939ca42011-02-18 17:58:075946#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135947 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435948 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5949 for (plugin_it = plugin_delegates_.begin();
5950 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5951 (*plugin_it)->SetContainerVisibility(true);
5952 }
[email protected]784ea1ab2010-09-18 00:02:345953#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075954}
[email protected]1e6e3c992010-02-08 15:52:135955
[email protected]ed7defa2013-03-12 21:29:595956GURL RenderViewImpl::GetURLForGraphicsContext3D() {
5957 DCHECK(webview());
5958 if (webview()->mainFrame())
5959 return GURL(webview()->mainFrame()->document().url());
5960 else
5961 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:245962}
5963
[email protected]479b0172012-10-29 19:27:095964bool RenderViewImpl::ForceCompositingModeEnabled() {
5965 return webkit_preferences_.force_compositing_mode;
5966}
5967
[email protected]310ebd6302011-10-10 19:06:285968void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135969 RenderWidget::OnSetFocus(enable);
5970
[email protected]7d3c02c2010-05-05 23:10:315971 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075972 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135973 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5974 for (plugin_it = plugin_delegates_.begin();
5975 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345976#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315977 // RenderWidget's call to setFocus can cause the underlying webview's
5978 // activation state to change just like a call to setIsActive.
5979 if (enable)
5980 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345981#endif
[email protected]7d3c02c2010-05-05 23:10:315982 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135983 }
5984 }
[email protected]a01da5682012-06-30 00:37:315985 // Notify all Pepper plugins.
[email protected]6d17f6392012-12-05 05:24:545986 pepper_helper_->OnSetFocus(enable);
[email protected]321032992012-11-08 01:01:275987 // Notify all BrowserPlugins of the RenderView's focus state.
[email protected]fb325d122012-11-20 23:58:055988 if (browser_plugin_manager_)
[email protected]caaf2482013-05-01 20:33:325989 browser_plugin_manager_->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:135990}
[email protected]941e4552010-02-01 21:23:435991
[email protected]310ebd6302011-10-10 19:06:285992void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]3306f262012-09-21 19:20:425993 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]3f783362011-10-21 22:40:505994 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575995}
5996
[email protected]73bf95812011-10-12 11:38:325997void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]3306f262012-09-21 19:20:425998 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]8fe8f742012-06-14 00:36:085999 if (renderer_accessibility_)
6000 renderer_accessibility_->FocusedNodeChanged(WebNode());
[email protected]73bf95812011-10-12 11:38:326001}
6002
[email protected]3f783362011-10-21 22:40:506003void RenderViewImpl::PpapiPluginCaretPositionChanged() {
6004 UpdateSelectionBounds();
6005}
6006
[email protected]b25b3ee2012-01-13 05:19:546007bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
[email protected]6d17f6392012-12-05 05:24:546008 if (!pepper_helper_->IsPluginFocused())
[email protected]b25b3ee2012-01-13 05:19:546009 return false;
[email protected]6d17f6392012-12-05 05:24:546010 *rect = pepper_helper_->GetCaretBounds();
[email protected]b25b3ee2012-01-13 05:19:546011 return true;
6012}
6013
[email protected]397c23962012-05-21 07:09:326014void RenderViewImpl::SimulateImeSetComposition(
6015 const string16& text,
6016 const std::vector<WebKit::WebCompositionUnderline>& underlines,
6017 int selection_start,
6018 int selection_end) {
6019 OnImeSetComposition(text, underlines, selection_start, selection_end);
6020}
6021
6022void RenderViewImpl::SimulateImeConfirmComposition(
6023 const string16& text,
6024 const ui::Range& replacement_range) {
6025 OnImeConfirmComposition(text, replacement_range);
6026}
6027
[email protected]73bf95812011-10-12 11:38:326028void RenderViewImpl::PpapiPluginCancelComposition() {
6029 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]58b48a0d2012-06-13 07:01:356030 const ui::Range range(ui::Range::InvalidRange());
6031 const std::vector<gfx::Rect> empty_bounds;
6032 UpdateCompositionInfo(range, empty_bounds);
[email protected]73bf95812011-10-12 11:38:326033}
6034
[email protected]3c8c74c2012-03-15 07:34:526035void RenderViewImpl::PpapiPluginSelectionChanged() {
6036 SyncSelectionIfRequired();
6037}
6038
[email protected]e9ff79c2012-10-19 21:31:266039void RenderViewImpl::PpapiPluginCreated(RendererPpapiHost* host) {
[email protected]236bf852012-07-27 22:49:366040 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
6041 DidCreatePepperPlugin(host));
6042}
6043
[email protected]310ebd6302011-10-10 19:06:286044void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:576045 const string16& text,
6046 const std::vector<WebKit::WebCompositionUnderline>& underlines,
6047 int selection_start,
6048 int selection_end) {
[email protected]6d17f6392012-12-05 05:24:546049 if (pepper_helper_->IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:326050 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]6d17f6392012-12-05 05:24:546051 pepper_helper_->OnImeSetComposition(text,
6052 underlines,
6053 selection_start,
6054 selection_end);
[email protected]73bf95812011-10-12 11:38:326055 } else {
[email protected]e6ae0f6c2011-10-04 10:39:236056#if defined(OS_WIN)
6057 // When a plug-in has focus, we create platform-specific IME data used by
6058 // our IME emulator and send it directly to the focused plug-in, i.e. we
6059 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
6060 // instance ID is the same one as the specified ID.)
6061 if (focused_plugin_id_ >= 0) {
6062 std::vector<int> clauses;
6063 std::vector<int> target;
6064 for (size_t i = 0; i < underlines.size(); ++i) {
6065 clauses.push_back(underlines[i].startOffset);
6066 clauses.push_back(underlines[i].endOffset);
6067 if (underlines[i].thick) {
6068 target.clear();
6069 target.push_back(underlines[i].startOffset);
6070 target.push_back(underlines[i].endOffset);
6071 }
6072 }
6073 std::set<WebPluginDelegateProxy*>::iterator it;
6074 for (it = plugin_delegates_.begin();
6075 it != plugin_delegates_.end(); ++it) {
6076 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
6077 focused_plugin_id_);
6078 }
6079 return;
6080 }
6081#endif
[email protected]56ea1a62011-05-30 07:05:576082 RenderWidget::OnImeSetComposition(text,
6083 underlines,
6084 selection_start,
6085 selection_end);
6086 }
6087}
6088
[email protected]4de6d1692011-10-12 08:45:446089void RenderViewImpl::OnImeConfirmComposition(
6090 const string16& text, const ui::Range& replacement_range) {
[email protected]6d17f6392012-12-05 05:24:546091 if (pepper_helper_->IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:326092 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]6d17f6392012-12-05 05:24:546093 pepper_helper_->OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:576094 } else {
[email protected]e6ae0f6c2011-10-04 10:39:236095#if defined(OS_WIN)
6096 // Same as OnImeSetComposition(), we send the text from IMEs directly to
6097 // plug-ins. When we send IME text directly to plug-ins, we should not send
6098 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:446099 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:236100 if (focused_plugin_id_ >= 0) {
6101 std::set<WebPluginDelegateProxy*>::iterator it;
6102 for (it = plugin_delegates_.begin();
6103 it != plugin_delegates_.end(); ++it) {
6104 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
6105 }
6106 return;
6107 }
6108#endif
[email protected]ebd28ac2011-10-13 18:49:056109 if (replacement_range.IsValid() && webview()) {
6110 // Select the text in |replacement_range|, it will then be replaced by
6111 // text added by the call to RenderWidget::OnImeConfirmComposition().
6112 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:166113 WebRange webrange = WebRange::fromDocumentRange(
6114 frame, replacement_range.start(), replacement_range.length());
6115 if (!webrange.isNull())
[email protected]884f9002012-08-21 19:33:586116 frame->selectRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:056117 }
6118 }
[email protected]4de6d1692011-10-12 08:45:446119 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:576120 }
6121}
6122
[email protected]468ac582012-11-20 00:53:196123void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) {
6124 RenderWidget::SetDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:046125 if (webview()) {
[email protected]dea5e7682012-06-14 05:21:246126 webview()->setDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:046127 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
6128 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:436129 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
6130 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:046131 }
[email protected]3a1c8a8032013-03-18 22:35:326132 if (auto_resize_mode_)
6133 AutoResizeCompositor();
[email protected]caaf2482013-05-01 20:33:326134
6135 if (browser_plugin_manager_)
6136 browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_);
[email protected]dea5e7682012-06-14 05:21:246137}
6138
[email protected]310ebd6302011-10-10 19:06:286139ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]6d17f6392012-12-05 05:24:546140 return pepper_helper_->IsPluginFocused() ?
6141 pepper_helper_->GetTextInputType() : RenderWidget::GetTextInputType();
[email protected]73bf95812011-10-12 11:38:326142}
6143
[email protected]3f783362011-10-21 22:40:506144void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
[email protected]6d17f6392012-12-05 05:24:546145 if (pepper_helper_->IsPluginFocused()) {
[email protected]3f783362011-10-21 22:40:506146 // TODO(kinaba) http://crbug.com/101101
6147 // Current Pepper IME API does not handle selection bounds. So we simply
6148 // use the caret position as an empty range for now. It will be updated
6149 // after Pepper API equips features related to surrounding text retrieval.
[email protected]6d17f6392012-12-05 05:24:546150 gfx::Rect caret = pepper_helper_->GetCaretBounds();
[email protected]3f783362011-10-21 22:40:506151 *start = caret;
6152 *end = caret;
6153 return;
6154 }
6155 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:456156}
6157
[email protected]58b48a0d2012-06-13 07:01:356158void RenderViewImpl::GetCompositionCharacterBounds(
6159 std::vector<gfx::Rect>* bounds) {
6160 DCHECK(bounds);
6161 bounds->clear();
6162
6163 if (!webview())
6164 return;
6165 size_t start_offset = 0;
6166 size_t character_count = 0;
6167 if (!webview()->compositionRange(&start_offset, &character_count))
6168 return;
6169 if (character_count == 0)
6170 return;
6171
6172 WebKit::WebFrame* frame = webview()->focusedFrame();
6173 if (!frame)
6174 return;
6175
6176 bounds->reserve(character_count);
6177 WebKit::WebRect webrect;
6178 for (size_t i = 0; i < character_count; ++i) {
6179 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
6180 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
6181 bounds->clear();
6182 return;
6183 }
6184 bounds->push_back(webrect);
6185 }
6186}
6187
[email protected]310ebd6302011-10-10 19:06:286188bool RenderViewImpl::CanComposeInline() {
[email protected]6d17f6392012-12-05 05:24:546189 return pepper_helper_->IsPluginFocused() ?
6190 pepper_helper_->CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:576191}
6192
[email protected]35134e12013-02-22 20:07:406193void RenderViewImpl::InstrumentWillBeginFrame() {
6194 if (!webview())
6195 return;
6196 if (!webview()->devToolsAgent())
6197 return;
6198 webview()->devToolsAgent()->didBeginFrame();
6199}
6200
6201void RenderViewImpl::InstrumentDidBeginFrame() {
6202 if (!webview())
6203 return;
6204 if (!webview()->devToolsAgent())
6205 return;
6206 // TODO(jamesr/caseq): Decide if this needs to be renamed.
6207 webview()->devToolsAgent()->didComposite();
6208}
6209
6210void RenderViewImpl::InstrumentDidCancelFrame() {
6211 if (!webview())
6212 return;
6213 if (!webview()->devToolsAgent())
6214 return;
6215 webview()->devToolsAgent()->didCancelFrame();
6216}
6217
6218void RenderViewImpl::InstrumentWillComposite() {
6219 if (!webview())
6220 return;
6221 if (!webview()->devToolsAgent())
6222 return;
6223 webview()->devToolsAgent()->willComposite();
6224}
6225
[email protected]34bb3ac2013-03-08 02:41:286226bool RenderViewImpl::AllowPartialSwap() const {
6227 return allow_partial_swap_;
6228}
6229
[email protected]e6ae0f6c2011-10-04 10:39:236230#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:286231void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:236232 if (focused)
6233 focused_plugin_id_ = plugin_id;
6234 else
6235 focused_plugin_id_ = -1;
6236}
6237#endif
6238
[email protected]43f28f832010-02-03 02:28:486239#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286240void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:416241 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:136242}
6243
[email protected]310ebd6302011-10-10 19:06:286244void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:136245 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:556246 // This message can be sent during event-handling, and needs to be delivered
6247 // within that context.
6248 msg->set_unblock(true);
6249 Send(msg);
6250}
[email protected]82114f52012-03-20 22:53:416251#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:286252
[email protected]310ebd6302011-10-10 19:06:286253bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:266254 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476255 WebFileChooserCompletion* completion) {
6256 static const size_t kMaximumPendingFileChooseRequests = 4;
6257 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6258 // This sanity check prevents too many file choose requests from getting
6259 // queued which could DoS the user. Getting these is most likely a
6260 // programming error (there are many ways to DoS the user so it's not
6261 // considered a "real" security check), either in JS requesting many file
6262 // choosers to pop up, or in a plugin.
6263 //
6264 // TODO(brettw) we might possibly want to require a user gesture to open
6265 // a file picker, which will address this issue in a better way.
6266 return false;
6267 }
6268
6269 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6270 new PendingFileChooser(params, completion)));
6271 if (file_chooser_completions_.size() == 1) {
6272 // Actually show the browse dialog when this is the first request.
6273 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6274 }
6275 return true;
6276}
6277
[email protected]310ebd6302011-10-10 19:06:286278WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516279 if (!geolocation_dispatcher_)
6280 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6281 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256282}
[email protected]61c9f032010-03-31 23:04:196283
[email protected]310ebd6302011-10-10 19:06:286284WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:116285 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226286#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026287 if (!input_tag_speech_dispatcher_)
6288 input_tag_speech_dispatcher_ =
6289 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226290#endif
[email protected]c52b2892012-03-07 11:01:026291 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116292}
6293
[email protected]64d09222012-05-25 10:10:346294WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
[email protected]64d09222012-05-25 10:10:346295 if (!speech_recognition_dispatcher_)
6296 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:346297 return speech_recognition_dispatcher_;
6298}
6299
[email protected]310ebd6302011-10-10 19:06:286300WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:516301 if (!device_orientation_dispatcher_)
6302 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
6303 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:536304}
6305
[email protected]310ebd6302011-10-10 19:06:286306void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6307 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256308 // For now, don't remember plugin zoom values. We don't want to mix them with
6309 // normal web content (i.e. a fixed layout plugin would usually want them
6310 // different).
6311 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6312
[email protected]b75b8292010-10-01 07:28:256313 int minimum_percent = static_cast<int>(
6314 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
6315 int maximum_percent = static_cast<int>(
6316 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256317
6318 Send(new ViewHostMsg_UpdateZoomLimits(
6319 routing_id_, minimum_percent, maximum_percent, remember));
6320}
6321
[email protected]310ebd6302011-10-10 19:06:286322void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256323 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086324 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266325
6326 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6327
[email protected]b75b8292010-10-01 07:28:256328 // Tell the browser which url got zoomed so it can update the menu and the
6329 // saved values if necessary
6330 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086331 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416332 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256333}
6334
[email protected]310ebd6302011-10-10 19:06:286335void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6336 const WebString& base_url,
6337 const WebString& url,
6338 const WebString& title) {
[email protected]af15bf22013-03-08 01:18:176339 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]a6d36cc2011-02-23 00:39:486340 GURL base(base_url);
6341 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6342 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6343 return;
6344 }
[email protected]f1a29a02011-10-06 23:08:446345 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6346 UTF16ToUTF8(scheme),
6347 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366348 title,
6349 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486350}
6351
[email protected]310ebd6302011-10-10 19:06:286352WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:446353 WebKit::WebPageVisibilityState current_state = is_hidden() ?
6354 WebKit::WebPageVisibilityStateHidden :
6355 WebKit::WebPageVisibilityStateVisible;
6356 WebKit::WebPageVisibilityState override_state = current_state;
[email protected]e9ff79c2012-10-19 21:31:266357 if (GetContentClient()->renderer()->
[email protected]f59203a2011-06-07 10:01:446358 ShouldOverridePageVisibilityState(this,
6359 &override_state))
6360 return override_state;
6361 return current_state;
[email protected]94dec932011-05-26 20:04:216362}
6363
[email protected]273558fb2012-01-12 15:03:516364WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:516365 EnsureMediaStreamImpl();
6366 return media_stream_impl_;
6367}
6368
[email protected]a0629af92012-08-08 00:39:376369void RenderViewImpl::draggableRegionsChanged() {
6370 FOR_EACH_OBSERVER(
6371 RenderViewObserver,
6372 observers_,
6373 DraggableRegionsChanged(webview()->mainFrame()));
6374}
6375
[email protected]20657a82012-08-21 20:23:036376#if defined(OS_ANDROID)
6377WebContentDetectionResult RenderViewImpl::detectContentAround(
6378 const WebHitTestResult& touch_hit) {
6379 DCHECK(!touch_hit.isNull());
6380 DCHECK(!touch_hit.node().isNull());
6381 DCHECK(touch_hit.node().isTextNode());
6382
6383 // Process the position with all the registered content detectors until
6384 // a match is found. Priority is provided by their relative order.
6385 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6386 it != content_detectors_.end(); ++it) {
6387 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6388 if (content.valid) {
6389 return WebContentDetectionResult(content.content_boundaries,
6390 UTF8ToUTF16(content.text), content.intent_url);
6391 }
6392 }
6393 return WebContentDetectionResult();
6394}
6395
6396void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6397 // Introduce a short delay so that the user can notice the content.
[email protected]dd32b1272013-05-04 14:17:116398 base::MessageLoop::current()->PostDelayedTask(
[email protected]20657a82012-08-21 20:23:036399 FROM_HERE,
[email protected]dd32b1272013-05-04 14:17:116400 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent,
6401 AsWeakPtr(),
6402 intent,
6403 expected_content_intent_id_),
[email protected]20657a82012-08-21 20:23:036404 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6405}
6406
6407void RenderViewImpl::cancelScheduledContentIntents() {
6408 ++expected_content_intent_id_;
6409}
6410
6411void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6412 size_t request_id) {
6413 if (request_id != expected_content_intent_id_)
6414 return;
6415
6416 // Remove the content highlighting if any.
6417 scheduleComposite();
6418
6419 if (!intent.is_empty())
6420 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6421}
[email protected]b18583c2012-12-18 06:55:276422
6423bool RenderViewImpl::openDateTimeChooser(
6424 const WebKit::WebDateTimeChooserParams& params,
6425 WebKit::WebDateTimeChooserCompletion* completion) {
6426 date_time_picker_client_.reset(
6427 new RendererDateTimePicker(this, params, completion));
6428 return date_time_picker_client_->Open();
6429}
6430
[email protected]6d17f6392012-12-05 05:24:546431#endif // defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:036432
[email protected]310ebd6302011-10-10 19:06:286433void RenderViewImpl::OnAsyncFileOpened(
6434 base::PlatformFileError error_code,
6435 IPC::PlatformFileForTransit file_for_transit,
6436 int message_id) {
[email protected]6d17f6392012-12-05 05:24:546437 pepper_helper_->OnAsyncFileOpened(
[email protected]27a9ef32010-09-10 04:06:246438 error_code,
6439 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
6440 message_id);
6441}
[email protected]caf706f2010-10-26 17:54:086442
[email protected]310ebd6302011-10-10 19:06:286443void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:476444 int request_id,
[email protected]108fd342013-01-04 20:46:546445 base::ProcessId broker_pid,
[email protected]d54305072011-06-22 20:58:436446 const IPC::ChannelHandle& handle) {
[email protected]108fd342013-01-04 20:46:546447 pepper_helper_->OnPpapiBrokerChannelCreated(request_id, broker_pid, handle);
[email protected]eb415bf0e2011-04-14 02:45:426448}
6449
[email protected]d8415ad92012-08-23 14:40:506450void RenderViewImpl::OnPpapiBrokerPermissionResult(
6451 int request_id,
6452 bool result) {
[email protected]6d17f6392012-12-05 05:24:546453 pepper_helper_->OnPpapiBrokerPermissionResult(request_id, result);
[email protected]d8415ad92012-08-23 14:40:506454}
6455
[email protected]caf706f2010-10-26 17:54:086456#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286457void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156458 if (external_popup_menu_ == NULL) {
6459 // Crash reports from the field indicate that we can be notified with a
6460 // NULL external popup menu (we probably get notified twice).
6461 // If you hit this please file a bug against jcivelli and include the page
6462 // and steps to repro.
6463 NOTREACHED();
6464 return;
6465 }
[email protected]caf706f2010-10-26 17:54:086466 external_popup_menu_->DidSelectItem(selected_index);
6467 external_popup_menu_.reset();
6468}
6469#endif
[email protected]bb461532010-11-26 21:50:236470
[email protected]24d2b172012-05-26 00:54:126471#if defined(OS_ANDROID)
6472void RenderViewImpl::OnSelectPopupMenuItems(
6473 bool canceled,
6474 const std::vector<int>& selected_indices) {
6475 // It is possible to receive more than one of these calls if the user presses
6476 // a select faster than it takes for the show-select-popup IPC message to make
6477 // it to the browser UI thread. Ignore the extra-messages.
6478 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
[email protected]59383c782013-04-17 16:43:276479 if (!external_popup_menu_)
[email protected]24d2b172012-05-26 00:54:126480 return;
6481
6482 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6483 external_popup_menu_.reset();
6484}
6485#endif
6486
[email protected]310ebd6302011-10-10 19:06:286487void RenderViewImpl::OnContextMenuClosed(
[email protected]e9ff79c2012-10-19 21:31:266488 const CustomContextMenuContext& custom_context) {
[email protected]860ee642012-10-13 03:46:256489 if (custom_context.request_id) {
6490 // External request, should be in our map.
[email protected]e9ff79c2012-10-19 21:31:266491 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:256492 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:466493 if (client) {
6494 client->OnMenuClosed(custom_context.request_id);
6495 pending_context_menus_.Remove(custom_context.request_id);
6496 }
[email protected]860ee642012-10-13 03:46:256497 } else {
6498 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:086499 context_menu_node_.reset();
[email protected]860ee642012-10-13 03:46:256500 }
[email protected]521b2482011-01-15 00:10:106501}
[email protected]5a7b15a2011-08-22 22:48:186502
[email protected]47822262013-04-23 17:22:366503void RenderViewImpl::OnShowContextMenu() {
6504 if (webview())
6505 webview()->showContextMenu();
6506}
6507
[email protected]310ebd6302011-10-10 19:06:286508void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186509 if (!webview())
6510 return;
6511 WebFrame* main_frame = webview()->mainFrame();
6512 if (!main_frame)
6513 return;
6514 main_frame->enableViewSourceMode(true);
6515}
[email protected]67bfb83f2011-09-22 03:36:376516
[email protected]da816272013-05-15 21:31:176517#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:206518void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:316519 DCHECK(!java_bridge_dispatcher_);
[email protected]7e9c5bb02012-05-14 13:58:316520 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]7f3c7af2011-10-20 22:52:516521}
[email protected]da816272013-05-15 21:31:176522#endif
[email protected]0720b532012-08-28 19:23:376523
[email protected]7cc78902012-12-06 02:32:266524void RenderViewImpl::OnDisownOpener() {
6525 if (!webview())
6526 return;
6527
6528 WebFrame* main_frame = webview()->mainFrame();
6529 if (main_frame && main_frame->opener())
6530 main_frame->setOpener(NULL);
6531}
6532
[email protected]efd7e47f2012-10-19 20:37:516533#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:036534bool RenderViewImpl::didTapMultipleTargets(
6535 const WebKit::WebGestureEvent& event,
6536 const WebVector<WebRect>& target_rects) {
[email protected]f9526d12012-10-18 01:55:036537 gfx::Rect finger_rect(
6538 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
6539 event.data.tap.width, event.data.tap.height);
6540 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:076541 float new_total_scale =
6542 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
6543 finger_rect, target_rects, GetSize(),
6544 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
6545 device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect);
6546 if (!new_total_scale)
[email protected]f9526d12012-10-18 01:55:036547 return false;
6548
[email protected]70221f02013-01-31 22:17:076549 gfx::Size canvas_size = gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(),
6550 new_total_scale));
[email protected]f9526d12012-10-18 01:55:036551 TransportDIB* transport_dib = NULL;
6552 {
6553 scoped_ptr<skia::PlatformCanvas> canvas(
6554 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
6555 gfx::Rect(canvas_size)));
[email protected]59383c782013-04-17 16:43:276556 if (!canvas)
[email protected]f9526d12012-10-18 01:55:036557 return false;
6558
[email protected]70221f02013-01-31 22:17:076559 // TODO(trchen): Cleanup the device scale factor mess.
6560 // device scale will be applied in WebKit
6561 // --> zoom_rect doesn't include device scale,
6562 // but WebKit will still draw on zoom_rect * device_scale_factor_
6563 canvas->scale(new_total_scale / device_scale_factor_,
6564 new_total_scale / device_scale_factor_);
6565 canvas->translate(-zoom_rect.x() * device_scale_factor_,
6566 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:036567
[email protected]f9526d12012-10-18 01:55:036568 webwidget_->paint(webkit_glue::ToWebCanvas(canvas.get()), zoom_rect,
6569 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
6570 }
[email protected]70221f02013-01-31 22:17:076571
6572 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
6573 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect)));
[email protected]f9526d12012-10-18 01:55:036574 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
[email protected]70221f02013-01-31 22:17:076575 physical_window_zoom_rect,
[email protected]f9526d12012-10-18 01:55:036576 canvas_size,
6577 transport_dib->id()));
6578
6579 return true;
6580}
[email protected]6fceb912013-02-15 06:24:156581
6582skia::RefPtr<SkPicture> RenderViewImpl::CapturePicture() {
[email protected]635353c2013-03-06 09:11:206583 return compositor_ ? compositor_->CapturePicture() :
[email protected]6fceb912013-02-15 06:24:156584 skia::RefPtr<SkPicture>();
6585}
[email protected]efd7e47f2012-10-19 20:37:516586#endif
[email protected]f9526d12012-10-18 01:55:036587
[email protected]b283d292013-02-21 08:40:346588unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
6589 return history_list_length_;
6590}
6591
[email protected]cc290f902013-03-04 20:06:026592void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
6593 if (enable) {
6594 if (has_focus())
6595 return;
6596 OnSetActive(true);
6597 OnSetFocus(true);
6598 } else {
6599 if (!has_focus())
6600 return;
6601 OnSetFocus(false);
6602 OnSetActive(false);
6603 }
6604}
6605
[email protected]3a1c8a8032013-03-18 22:35:326606void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
6607 SetDeviceScaleFactor(factor);
6608 if (!auto_resize_mode_)
6609 AutoResizeCompositor();
6610}
6611
[email protected]eac2b362013-05-22 07:01:456612void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
6613 const gfx::Size& max_size) {
6614 OnEnableAutoResize(min_size, max_size);
6615}
6616
6617void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
6618 OnDisableAutoResize(new_size);
6619}
6620
[email protected]f9526d12012-10-18 01:55:036621void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6622 TransportDIB::Handle dib_handle) {
6623 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6624 RenderProcess::current()->ReleaseTransportDIB(dib);
6625}
[email protected]e9ff79c2012-10-19 21:31:266626
[email protected]6fceb912013-02-15 06:24:156627void RenderViewImpl::DidCommitCompositorFrame() {
6628 RenderWidget::DidCommitCompositorFrame();
6629 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
6630}
6631
[email protected]41225fe2013-03-29 05:32:026632void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
6633 if (!urls.empty())
6634 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls));
6635}
6636
6637void RenderViewImpl::DidStopLoadingIcons() {
6638 int icon_types = WebIconURL::TypeFavicon;
6639 if (TouchEnabled())
6640 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
6641
6642 WebVector<WebIconURL> icon_urls =
6643 webview()->mainFrame()->iconURLs(icon_types);
6644
6645 std::vector<FaviconURL> urls;
6646 for (size_t i = 0; i < icon_urls.size(); i++) {
6647 WebURL url = icon_urls[i].iconURL();
6648 if (!url.isEmpty())
6649 urls.push_back(FaviconURL(url,
6650 ToFaviconType(icon_urls[i].iconType())));
6651 }
6652 SendUpdateFaviconURL(urls);
6653}
6654
6655
[email protected]e9ff79c2012-10-19 21:31:266656} // namespace content