[email protected] | b553edd5 | 2012-01-10 12:15:23 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5 | #include "content/renderer/render_view_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
| 7 | #include <algorithm> |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 8 | #include <cmath> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 10 | #include "base/auto_reset.h" |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/bind_helpers.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 14 | #include "base/compiler_specific.h" |
[email protected] | 2132d6b | 2013-06-05 00:15:43 | [diff] [blame] | 15 | #include "base/debug/alias.h" |
[email protected] | e7ca289 | 2012-09-01 00:52:15 | [diff] [blame] | 16 | #include "base/debug/trace_event.h" |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 17 | #include "base/files/file_path.h" |
[email protected] | b1cf337 | 2011-04-20 21:28:10 | [diff] [blame] | 18 | #include "base/json/json_writer.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 19 | #include "base/lazy_instance.h" |
[email protected] | cffd752 | 2012-10-23 19:10:58 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | 7ccb707 | 2013-06-10 20:56:28 | [diff] [blame] | 21 | #include "base/message_loop/message_loop_proxy.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 22 | #include "base/metrics/histogram.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 23 | #include "base/path_service.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 24 | #include "base/process_util.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 25 | #include "base/strings/string_number_conversions.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 26 | #include "base/strings/string_piece.h" |
[email protected] | 27c0573 | 2013-02-15 21:55:49 | [diff] [blame] | 27 | #include "base/strings/string_split.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 28 | #include "base/strings/string_util.h" |
[email protected] | 40d11e0 | 2013-03-28 17:43:14 | [diff] [blame] | 29 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 30 | #include "base/strings/utf_string_conversions.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 31 | #include "base/time/time.h" |
[email protected] | 8e4f4495 | 2013-06-17 23:58:27 | [diff] [blame] | 32 | #include "content/child/appcache_dispatcher.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 33 | #include "content/child/child_thread.h" |
| 34 | #include "content/child/fileapi/file_system_dispatcher.h" |
[email protected] | c7199a6e | 2013-06-04 12:56:01 | [diff] [blame] | 35 | #include "content/child/fileapi/webfilesystem_callback_adapters.h" |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 36 | #include "content/child/npapi/webplugin_delegate_impl.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 37 | #include "content/child/quota_dispatcher.h" |
[email protected] | 541b7b0 | 2013-06-07 00:59:34 | [diff] [blame] | 38 | #include "content/child/request_extra_data.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 39 | #include "content/child/webmessageportchannel_impl.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 40 | #include "content/common/clipboard_messages.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 41 | #include "content/common/database_messages.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 42 | #include "content/common/drag_messages.h" |
[email protected] | c26ad88 | 2012-02-07 06:41:20 | [diff] [blame] | 43 | #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 44 | #include "content/common/input_messages.h" |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 45 | #include "content/common/java_bridge_messages.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 46 | #include "content/common/pepper_messages.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 47 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 48 | #include "content/common/socket_stream_handle_data.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 49 | #include "content/common/ssl_status_serialization.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 50 | #include "content/common/view_messages.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 51 | #include "content/public/common/bindings_policy.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 52 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 53 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 54 | #include "content/public/common/content_switches.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 55 | #include "content/public/common/context_menu_params.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 56 | #include "content/public/common/drop_data.h" |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 57 | #include "content/public/common/favicon_url.h" |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 58 | #include "content/public/common/file_chooser_params.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 59 | #include "content/public/common/ssl_status.h" |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 60 | #include "content/public/common/three_d_api_types.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 61 | #include "content/public/common/url_constants.h" |
[email protected] | 3b366ae | 2013-05-17 21:16:58 | [diff] [blame] | 62 | #include "content/public/common/url_utils.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 63 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 97f5813 | 2012-11-15 20:41:32 | [diff] [blame] | 64 | #include "content/public/renderer/context_menu_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 65 | #include "content/public/renderer/document_state.h" |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 66 | #include "content/public/renderer/history_item_serialization.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 67 | #include "content/public/renderer/navigation_state.h" |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 68 | #include "content/public/renderer/password_form_conversion_utils.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 69 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 70 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 4e4646a5 | 2013-02-08 07:23:41 | [diff] [blame] | 71 | #include "content/renderer/accessibility/renderer_accessibility.h" |
| 72 | #include "content/renderer/accessibility/renderer_accessibility_complete.h" |
| 73 | #include "content/renderer/accessibility/renderer_accessibility_focus_only.h" |
[email protected] | e6e5675 | 2012-08-10 00:46:06 | [diff] [blame] | 74 | #include "content/renderer/browser_plugin/browser_plugin.h" |
| 75 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 76 | #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" |
[email protected] | 3175fea | 2013-05-16 10:57:48 | [diff] [blame] | 77 | #include "content/renderer/context_menu_params_builder.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 78 | #include "content/renderer/device_orientation_dispatcher.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 79 | #include "content/renderer/devtools/devtools_agent.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 80 | #include "content/renderer/disambiguation_popup_helper.h" |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 81 | #include "content/renderer/dom_automation_controller.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 82 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 83 | #include "content/renderer/drop_data_builder.h" |
[email protected] | 5572215 | 2011-03-22 01:33:53 | [diff] [blame] | 84 | #include "content/renderer/external_popup_menu.h" |
[email protected] | f8c700ba | 2013-05-14 08:25:49 | [diff] [blame] | 85 | #include "content/renderer/fetchers/alt_error_page_resource_fetcher.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 86 | #include "content/renderer/geolocation_dispatcher.h" |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 87 | #include "content/renderer/gpu/input_handler_manager.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 88 | #include "content/renderer/gpu/render_widget_compositor.h" |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 89 | #include "content/renderer/idle_user_detector.h" |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 90 | #include "content/renderer/image_loading_helper.h" |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 91 | #include "content/renderer/ime_event_guard.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 92 | #include "content/renderer/input_tag_speech_dispatcher.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 93 | #include "content/renderer/internal_document_state_data.h" |
[email protected] | 0716190 | 2011-11-11 09:57:42 | [diff] [blame] | 94 | #include "content/renderer/java/java_bridge_dispatcher.h" |
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 95 | #include "content/renderer/load_progress_tracker.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 96 | #include "content/renderer/media/audio_device_factory.h" |
| 97 | #include "content/renderer/media/audio_renderer_mixer_manager.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 98 | #include "content/renderer/media/media_stream_dependency_factory.h" |
| 99 | #include "content/renderer/media/media_stream_dispatcher.h" |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 100 | #include "content/renderer/media/media_stream_impl.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 101 | #include "content/renderer/media/render_media_log.h" |
[email protected] | ccee486 | 2012-10-03 18:34:26 | [diff] [blame] | 102 | #include "content/renderer/media/rtc_peer_connection_handler.h" |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 103 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 104 | #include "content/renderer/media/webmediaplayer_impl.h" |
| 105 | #include "content/renderer/media/webmediaplayer_ms.h" |
| 106 | #include "content/renderer/media/webmediaplayer_params.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 107 | #include "content/renderer/mhtml_generator.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 108 | #include "content/renderer/notification_provider.h" |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 109 | #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 110 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 111 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 112 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 113 | #include "content/renderer/render_view_impl_params.h" |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 114 | #include "content/renderer/render_view_mouse_lock_dispatcher.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 115 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 116 | #include "content/renderer/renderer_date_time_picker.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 117 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 118 | #include "content/renderer/renderer_webcolorchooser_impl.h" |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 119 | #include "content/renderer/savable_resources.h" |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 120 | #include "content/renderer/speech_recognition_dispatcher.h" |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 121 | #include "content/renderer/stats_collection_controller.h" |
| 122 | #include "content/renderer/stats_collection_observer.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 123 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 124 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 125 | #include "content/renderer/web_ui_extension.h" |
| 126 | #include "content/renderer/web_ui_extension_data.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 127 | #include "content/renderer/webplugin_delegate_proxy.h" |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 128 | #include "content/renderer/webplugin_impl.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 129 | #include "content/renderer/websharedworker_proxy.h" |
[email protected] | f596114 | 2013-04-17 23:09:42 | [diff] [blame] | 130 | #include "media/audio/audio_output_device.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 131 | #include "media/base/audio_renderer_mixer_input.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 132 | #include "media/base/filter_collection.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 133 | #include "media/base/media_switches.h" |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 134 | #include "media/filters/audio_renderer_impl.h" |
[email protected] | b9a407e | 2013-07-24 07:30:02 | [diff] [blame] | 135 | #include "media/filters/gpu_video_decoder_factories.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 136 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 137 | #include "net/base/escape.h" |
| 138 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 139 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 140 | #include "net/http/http_util.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 141 | #include "third_party/WebKit/public/platform/WebCString.h" |
| 142 | #include "third_party/WebKit/public/platform/WebDragData.h" |
| 143 | #include "third_party/WebKit/public/platform/WebFileSystemType.h" |
| 144 | #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 145 | #include "third_party/WebKit/public/platform/WebImage.h" |
| 146 | #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 147 | #include "third_party/WebKit/public/platform/WebPoint.h" |
| 148 | #include "third_party/WebKit/public/platform/WebRect.h" |
| 149 | #include "third_party/WebKit/public/platform/WebSize.h" |
| 150 | #include "third_party/WebKit/public/platform/WebSocketStreamHandle.h" |
| 151 | #include "third_party/WebKit/public/platform/WebString.h" |
| 152 | #include "third_party/WebKit/public/platform/WebURL.h" |
| 153 | #include "third_party/WebKit/public/platform/WebURLError.h" |
| 154 | #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 155 | #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 156 | #include "third_party/WebKit/public/platform/WebVector.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 157 | #include "third_party/WebKit/public/web/WebAccessibilityObject.h" |
| 158 | #include "third_party/WebKit/public/web/WebColorName.h" |
| 159 | #include "third_party/WebKit/public/web/WebDOMEvent.h" |
| 160 | #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" |
| 161 | #include "third_party/WebKit/public/web/WebDataSource.h" |
| 162 | #include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h" |
| 163 | #include "third_party/WebKit/public/web/WebDateTimeChooserParams.h" |
| 164 | #include "third_party/WebKit/public/web/WebDevToolsAgent.h" |
| 165 | #include "third_party/WebKit/public/web/WebDocument.h" |
| 166 | #include "third_party/WebKit/public/web/WebElement.h" |
| 167 | #include "third_party/WebKit/public/web/WebFileChooserParams.h" |
| 168 | #include "third_party/WebKit/public/web/WebFileSystemCallbacks.h" |
| 169 | #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 170 | #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 171 | #include "third_party/WebKit/public/web/WebFormElement.h" |
| 172 | #include "third_party/WebKit/public/web/WebFrame.h" |
| 173 | #include "third_party/WebKit/public/web/WebHelperPlugin.h" |
| 174 | #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 175 | #include "third_party/WebKit/public/web/WebInputElement.h" |
| 176 | #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 177 | #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" |
| 178 | #include "third_party/WebKit/public/web/WebNavigationPolicy.h" |
| 179 | #include "third_party/WebKit/public/web/WebNodeList.h" |
| 180 | #include "third_party/WebKit/public/web/WebPageSerializer.h" |
| 181 | #include "third_party/WebKit/public/web/WebPlugin.h" |
| 182 | #include "third_party/WebKit/public/web/WebPluginAction.h" |
| 183 | #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 184 | #include "third_party/WebKit/public/web/WebPluginDocument.h" |
| 185 | #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 186 | #include "third_party/WebKit/public/web/WebRange.h" |
| 187 | #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 188 | #include "third_party/WebKit/public/web/WebSearchableFormData.h" |
| 189 | #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 190 | #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 191 | #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
| 192 | #include "third_party/WebKit/public/web/WebSettings.h" |
| 193 | #include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h" |
| 194 | #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 195 | #include "third_party/WebKit/public/web/WebUserMediaClient.h" |
| 196 | #include "third_party/WebKit/public/web/WebView.h" |
| 197 | #include "third_party/WebKit/public/web/WebWindowFeatures.h" |
| 198 | #include "third_party/WebKit/public/web/default/WebRenderTheme.h" |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 199 | #include "ui/base/ui_base_switches_util.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 200 | #include "ui/gfx/native_widget_types.h" |
| 201 | #include "ui/gfx/point.h" |
| 202 | #include "ui/gfx/rect.h" |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 203 | #include "ui/gfx/rect_conversions.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 204 | #include "ui/gfx/size_conversions.h" |
[email protected] | 4344a3c | 2013-01-17 23:49:20 | [diff] [blame] | 205 | #include "ui/shell_dialogs/selected_file_info.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 206 | #include "v8/include/v8.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 207 | #include "webkit/child/weburlresponse_extradata_impl.h" |
[email protected] | 3caf2cb6 | 2013-06-04 00:31:33 | [diff] [blame] | 208 | #include "webkit/common/dom_storage/dom_storage_types.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 209 | #include "webkit/glue/webkit_glue.h" |
[email protected] | d5b2fdf | 2013-06-05 09:36:55 | [diff] [blame] | 210 | #include "webkit/renderer/appcache/web_application_cache_host_impl.h" |
[email protected] | fab55e7 | 2013-05-31 07:06:18 | [diff] [blame] | 211 | #include "webkit/renderer/webpreferences_renderer.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 212 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 213 | #if defined(OS_ANDROID) |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 214 | #include <cpu-features.h> |
| 215 | |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 216 | #include "content/common/android/device_telephony_info.h" |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 217 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 218 | #include "content/renderer/android/address_detector.h" |
| 219 | #include "content/renderer/android/content_detector.h" |
| 220 | #include "content/renderer/android/email_detector.h" |
| 221 | #include "content/renderer/android/phone_number_detector.h" |
[email protected] | bc42744 | 2013-07-13 02:53:08 | [diff] [blame] | 222 | #include "content/renderer/media/android/renderer_media_player_manager.h" |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 223 | #include "content/renderer/media/android/stream_texture_factory_android.h" |
| 224 | #include "content/renderer/media/android/webmediaplayer_android.h" |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 225 | #include "content/renderer/media/android/webmediaplayer_proxy_android.h" |
[email protected] | c277d3c | 2013-07-15 21:49:37 | [diff] [blame] | 226 | #include "skia/ext/platform_canvas.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 227 | #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 228 | #include "third_party/WebKit/public/platform/WebFloatRect.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 229 | #include "third_party/WebKit/public/web/WebHitTestResult.h" |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 230 | #include "ui/gfx/rect_f.h" |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 231 | |
| 232 | #if defined(GOOGLE_TV) |
| 233 | #include "content/renderer/media/rtc_video_decoder_bridge_tv.h" |
| 234 | #include "content/renderer/media/rtc_video_decoder_factory_tv.h" |
| 235 | #endif |
| 236 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 237 | #elif defined(OS_WIN) |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 238 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 239 | // * theming |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 240 | #include "ui/native_theme/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 241 | #elif defined(USE_X11) |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 242 | #include "ui/native_theme/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 243 | #elif defined(OS_MACOSX) |
| 244 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 245 | #endif |
| 246 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 247 | using WebKit::WebAccessibilityNotification; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 248 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 249 | using WebKit::WebApplicationCacheHost; |
| 250 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 251 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 252 | using WebKit::WebColor; |
| 253 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 254 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 255 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 256 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 257 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 258 | using WebKit::WebDataSource; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 259 | using WebKit::WebDocument; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 260 | using WebKit::WebDOMEvent; |
| 261 | using WebKit::WebDOMMessageEvent; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 262 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 263 | using WebKit::WebDragOperation; |
| 264 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 265 | using WebKit::WebEditingAction; |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 266 | using WebKit::WebElement; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 267 | using WebKit::WebExternalPopupMenu; |
| 268 | using WebKit::WebExternalPopupMenuClient; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 269 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 270 | using WebKit::WebFileSystem; |
| 271 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 272 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 273 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 274 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 275 | using WebKit::WebFrame; |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 276 | using WebKit::WebGestureEvent; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 277 | using WebKit::WebHistoryItem; |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 278 | using WebKit::WebHTTPBody; |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 279 | using WebKit::WebIconURL; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 280 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 281 | using WebKit::WebInputElement; |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 282 | using WebKit::WebInputEvent; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 283 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 284 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 285 | using WebKit::WebMediaPlayerClient; |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 286 | using WebKit::WebMouseEvent; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 287 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 288 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 289 | using WebKit::WebNode; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 290 | using WebKit::WebPageSerializer; |
| 291 | using WebKit::WebPageSerializerClient; |
[email protected] | 50da23d0 | 2012-04-13 17:47:48 | [diff] [blame] | 292 | using WebKit::WebPeerConnection00Handler; |
| 293 | using WebKit::WebPeerConnection00HandlerClient; |
| 294 | using WebKit::WebPeerConnectionHandler; |
| 295 | using WebKit::WebPeerConnectionHandlerClient; |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 296 | using WebKit::WebPluginAction; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 297 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 298 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 299 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 300 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 301 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 302 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 303 | using WebKit::WebRect; |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 304 | using WebKit::WebReferrerPolicy; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 305 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 306 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 307 | using WebKit::WebSecurityOrigin; |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 308 | using WebKit::WebSecurityPolicy; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 309 | using WebKit::WebSerializedScriptValue; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 310 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 311 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 312 | using WebKit::WebSize; |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 313 | using WebKit::WebSocketStreamHandle; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 314 | using WebKit::WebStorageNamespace; |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 315 | using WebKit::WebStorageQuotaCallbacks; |
| 316 | using WebKit::WebStorageQuotaError; |
| 317 | using WebKit::WebStorageQuotaType; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 318 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 319 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 320 | using WebKit::WebTextDirection; |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 321 | using WebKit::WebTouchEvent; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 322 | using WebKit::WebURL; |
| 323 | using WebKit::WebURLError; |
| 324 | using WebKit::WebURLRequest; |
| 325 | using WebKit::WebURLResponse; |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 326 | using WebKit::WebUserGestureIndicator; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 327 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 328 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 329 | using WebKit::WebWidget; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 330 | using WebKit::WebWindowFeatures; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 331 | using appcache::WebApplicationCacheHostImpl; |
| 332 | using base::Time; |
| 333 | using base::TimeDelta; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 334 | |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 335 | using webkit_glue::WebURLResponseExtraDataImpl; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 336 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 337 | #if defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 338 | using WebKit::WebContentDetectionResult; |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 339 | using WebKit::WebFloatPoint; |
| 340 | using WebKit::WebFloatRect; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 341 | using WebKit::WebHitTestResult; |
| 342 | #endif |
| 343 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 344 | namespace content { |
| 345 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 346 | //----------------------------------------------------------------------------- |
| 347 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 348 | typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 349 | static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 350 | typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap; |
| 351 | static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map = |
| 352 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 353 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 354 | // Time, in seconds, we delay before sending content state changes (such as form |
| 355 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 356 | // spamming the browser. |
| 357 | // To avoid having tab/session restore require sending a message to get the |
| 358 | // current content state during tab closing we use a shorter timeout for the |
| 359 | // foreground renderer. This means there is a small window of time from which |
| 360 | // content state is modified and not sent to session restore, but this is |
| 361 | // better than having to wake up all renderers during shutdown. |
| 362 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 363 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 364 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 365 | static const size_t kExtraCharsBeforeAndAfterSelection = 100; |
| 366 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 367 | // The maximum number of popups that can be spawned from one page. |
| 368 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 369 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 370 | static const float kScalingIncrement = 0.1f; |
| 371 | |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 372 | static const float kScalingIncrementForGesture = 0.01f; |
| 373 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 374 | #if defined(OS_ANDROID) |
| 375 | // Delay between tapping in content and launching the associated android intent. |
| 376 | // Used to allow users see what has been recognized as content. |
| 377 | static const size_t kContentIntentDelayMilliseconds = 700; |
| 378 | #endif |
| 379 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 380 | static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = |
| 381 | NULL; |
| 382 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 383 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 384 | // Replace any occurrences of swappedout:// with about:blank. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 385 | const WebURL& blank_url = GURL(kAboutBlankURL); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 386 | WebVector<WebURL> urls; |
| 387 | ds->redirectChain(urls); |
| 388 | result->reserve(urls.size()); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 389 | for (size_t i = 0; i < urls.size(); ++i) { |
| 390 | if (urls[i] != GURL(kSwappedOutURL)) |
| 391 | result->push_back(urls[i]); |
| 392 | else |
| 393 | result->push_back(blank_url); |
| 394 | } |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 395 | } |
| 396 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 397 | // If |data_source| is non-null and has an InternalDocumentStateData associated |
| 398 | // with it, the AltErrorPageResourceFetcher is reset. |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 399 | static void StopAltErrorPageFetcher(WebDataSource* data_source) { |
| 400 | if (data_source) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 401 | InternalDocumentStateData* internal_data = |
| 402 | InternalDocumentStateData::FromDataSource(data_source); |
| 403 | if (internal_data) |
| 404 | internal_data->set_alt_error_page_fetcher(NULL); |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 408 | static bool IsReload(const ViewMsg_Navigate_Params& params) { |
| 409 | return |
| 410 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 411 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE || |
| 412 | params.navigation_type == |
| 413 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 414 | } |
| 415 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 416 | // static |
| 417 | WebReferrerPolicy RenderViewImpl::GetReferrerPolicyFromRequest( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 418 | WebFrame* frame, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 419 | const WebURLRequest& request) { |
| 420 | return request.extraData() ? |
| 421 | static_cast<RequestExtraData*>(request.extraData())->referrer_policy() : |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 422 | frame->document().referrerPolicy(); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 423 | } |
| 424 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 425 | // static |
| 426 | Referrer RenderViewImpl::GetReferrerFromRequest( |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 427 | WebFrame* frame, |
| 428 | const WebURLRequest& request) { |
| 429 | return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 430 | GetReferrerPolicyFromRequest(frame, request)); |
| 431 | } |
| 432 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 433 | // static |
| 434 | WebURLResponseExtraDataImpl* RenderViewImpl::GetExtraDataFromResponse( |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 435 | const WebURLResponse& response) { |
| 436 | return static_cast<WebURLResponseExtraDataImpl*>( |
| 437 | response.extraData()); |
| 438 | } |
| 439 | |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 440 | NOINLINE static void CrashIntentionally() { |
| 441 | // NOTE(shess): Crash directly rather than using NOTREACHED() so |
| 442 | // that the signature is easier to triage in crash reports. |
| 443 | volatile int* zero = NULL; |
| 444 | *zero = 0; |
| 445 | } |
| 446 | |
[email protected] | 2132d6b | 2013-06-05 00:15:43 | [diff] [blame] | 447 | #if defined(ADDRESS_SANITIZER) |
| 448 | NOINLINE static void MaybeTriggerAsanError(const GURL& url) { |
| 449 | // NOTE(rogerm): We intentionally perform an invalid heap access here in |
| 450 | // order to trigger an Address Sanitizer (ASAN) error report. |
| 451 | static const char kCrashDomain[] = "crash"; |
| 452 | static const char kHeapOverflow[] = "/heap-overflow"; |
| 453 | static const char kHeapUnderflow[] = "/heap-underflow"; |
| 454 | static const char kUseAfterFree[] = "/use-after-free"; |
| 455 | static const int kArraySize = 5; |
| 456 | |
| 457 | if (!url.DomainIs(kCrashDomain, sizeof(kCrashDomain) - 1)) |
| 458 | return; |
| 459 | |
| 460 | if (!url.has_path()) |
| 461 | return; |
| 462 | |
| 463 | scoped_ptr<int[]> array(new int[kArraySize]); |
| 464 | std::string crash_type(url.path()); |
| 465 | int dummy = 0; |
| 466 | if (crash_type == kHeapOverflow) { |
| 467 | dummy = array[kArraySize]; |
| 468 | } else if (crash_type == kHeapUnderflow ) { |
| 469 | dummy = array[-1]; |
| 470 | } else if (crash_type == kUseAfterFree) { |
| 471 | int* dangling = array.get(); |
| 472 | array.reset(); |
| 473 | dummy = dangling[kArraySize / 2]; |
| 474 | } |
| 475 | |
| 476 | // Make sure the assignments to the dummy value aren't optimized away. |
| 477 | base::debug::Alias(&dummy); |
| 478 | } |
| 479 | #endif // ADDRESS_SANITIZER |
| 480 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 481 | static void MaybeHandleDebugURL(const GURL& url) { |
| 482 | if (!url.SchemeIs(chrome::kChromeUIScheme)) |
| 483 | return; |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 484 | if (url == GURL(kChromeUICrashURL)) { |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 485 | CrashIntentionally(); |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 486 | } else if (url == GURL(kChromeUIKillURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 487 | base::KillProcess(base::GetCurrentProcessHandle(), 1, false); |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 488 | } else if (url == GURL(kChromeUIHangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 489 | for (;;) { |
| 490 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 491 | } |
[email protected] | 50f86bc | 2012-11-01 19:59:13 | [diff] [blame] | 492 | } else if (url == GURL(kChromeUIShorthangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 493 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 494 | } |
[email protected] | 2132d6b | 2013-06-05 00:15:43 | [diff] [blame] | 495 | |
| 496 | #if defined(ADDRESS_SANITIZER) |
| 497 | MaybeTriggerAsanError(url); |
| 498 | #endif // ADDRESS_SANITIZER |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 499 | } |
| 500 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 501 | // Returns false unless this is a top-level navigation. |
| 502 | static bool IsTopLevelNavigation(WebFrame* frame) { |
| 503 | return frame->parent() == NULL; |
| 504 | } |
| 505 | |
| 506 | // Returns false unless this is a top-level navigation that crosses origins. |
| 507 | static bool IsNonLocalTopLevelNavigation(const GURL& url, |
| 508 | WebFrame* frame, |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 509 | WebNavigationType type, |
| 510 | bool is_form_post) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 511 | if (!IsTopLevelNavigation(frame)) |
| 512 | return false; |
| 513 | |
| 514 | // Navigations initiated within Webkit are not sent out to the external host |
| 515 | // in the following cases. |
| 516 | // 1. The url scheme is not http/https |
| 517 | // 2. The origin of the url and the opener is the same in which case the |
| 518 | // opener relationship is maintained. |
| 519 | // 3. Reloads/form submits/back forward navigations |
| 520 | if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) |
| 521 | return false; |
| 522 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 523 | if (type != WebKit::WebNavigationTypeReload && |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 524 | type != WebKit::WebNavigationTypeBackForward && !is_form_post) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 525 | // The opener relationship between the new window and the parent allows the |
| 526 | // new window to script the parent and vice versa. This is not allowed if |
| 527 | // the origins of the two domains are different. This can be treated as a |
| 528 | // top level navigation and routed back to the host. |
| 529 | WebKit::WebFrame* opener = frame->opener(); |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 530 | if (!opener) |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 531 | return true; |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 532 | |
| 533 | if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
| 534 | return true; |
| 535 | } |
| 536 | return false; |
| 537 | } |
| 538 | |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 539 | static void NotifyTimezoneChange(WebKit::WebFrame* frame) { |
| 540 | v8::HandleScope handle_scope; |
| 541 | v8::Context::Scope context_scope(frame->mainWorldScriptContext()); |
| 542 | v8::Date::DateTimeConfigurationChangeNotification(); |
| 543 | WebKit::WebFrame* child = frame->firstChild(); |
| 544 | for (; child; child = child->nextSibling()) |
| 545 | NotifyTimezoneChange(child); |
| 546 | } |
| 547 | |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 548 | static WindowOpenDisposition NavigationPolicyToDisposition( |
| 549 | WebNavigationPolicy policy) { |
| 550 | switch (policy) { |
| 551 | case WebKit::WebNavigationPolicyIgnore: |
| 552 | return IGNORE_ACTION; |
| 553 | case WebKit::WebNavigationPolicyDownload: |
| 554 | return SAVE_TO_DISK; |
| 555 | case WebKit::WebNavigationPolicyCurrentTab: |
| 556 | return CURRENT_TAB; |
| 557 | case WebKit::WebNavigationPolicyNewBackgroundTab: |
| 558 | return NEW_BACKGROUND_TAB; |
| 559 | case WebKit::WebNavigationPolicyNewForegroundTab: |
| 560 | return NEW_FOREGROUND_TAB; |
| 561 | case WebKit::WebNavigationPolicyNewWindow: |
| 562 | return NEW_WINDOW; |
| 563 | case WebKit::WebNavigationPolicyNewPopup: |
| 564 | return NEW_POPUP; |
| 565 | default: |
| 566 | NOTREACHED() << "Unexpected WebNavigationPolicy"; |
| 567 | return IGNORE_ACTION; |
| 568 | } |
| 569 | } |
| 570 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 571 | // Returns true if the device scale is high enough that losing subpixel |
| 572 | // antialiasing won't have a noticeable effect on text quality. |
| 573 | static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) { |
| 574 | #if defined(OS_ANDROID) |
| 575 | // On Android, we never have subpixel antialiasing. |
| 576 | return true; |
| 577 | #else |
| 578 | return device_scale_factor > 1.5f; |
| 579 | #endif |
| 580 | |
| 581 | } |
| 582 | |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 583 | static bool ShouldUseFixedPositionCompositing(float device_scale_factor) { |
| 584 | // Compositing for fixed-position elements is dependent on |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 585 | // device_scale_factor if no flag is set. http://crbug.com/172738 |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 586 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 587 | |
| 588 | if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition)) |
| 589 | return false; |
| 590 | |
| 591 | if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition)) |
| 592 | return true; |
| 593 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 594 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 595 | } |
| 596 | |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 597 | static bool ShouldUseAcceleratedCompositingForOverflowScroll( |
| 598 | float device_scale_factor) { |
| 599 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 600 | |
| 601 | if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll)) |
| 602 | return true; |
| 603 | |
| 604 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 605 | } |
| 606 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 607 | static bool ShouldUseTransitionCompositing(float device_scale_factor) { |
| 608 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 609 | |
| 610 | if (command_line.HasSwitch(switches::kDisableCompositingForTransition)) |
| 611 | return false; |
| 612 | |
| 613 | if (command_line.HasSwitch(switches::kEnableCompositingForTransition)) |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 614 | return true; |
| 615 | |
[email protected] | 9a7f6e1 | 2013-06-11 07:05:13 | [diff] [blame] | 616 | // TODO(ajuma): Re-enable this by default for high-DPI once the problem |
| 617 | // of excessive layer promotion caused by overlap has been addressed. |
| 618 | // http://crbug.com/178119. |
| 619 | return false; |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 620 | } |
| 621 | |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 622 | static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) { |
| 623 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 624 | |
| 625 | if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground)) |
| 626 | return false; |
| 627 | |
| 628 | if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground)) |
| 629 | return true; |
| 630 | |
| 631 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 632 | } |
| 633 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 634 | static FaviconURL::IconType ToFaviconType(WebKit::WebIconURL::Type type) { |
| 635 | switch (type) { |
| 636 | case WebKit::WebIconURL::TypeFavicon: |
| 637 | return FaviconURL::FAVICON; |
| 638 | case WebKit::WebIconURL::TypeTouch: |
| 639 | return FaviconURL::TOUCH_ICON; |
| 640 | case WebKit::WebIconURL::TypeTouchPrecomposed: |
| 641 | return FaviconURL::TOUCH_PRECOMPOSED_ICON; |
| 642 | case WebKit::WebIconURL::TypeInvalid: |
| 643 | return FaviconURL::INVALID_ICON; |
| 644 | } |
| 645 | return FaviconURL::INVALID_ICON; |
| 646 | } |
| 647 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 648 | /////////////////////////////////////////////////////////////////////////////// |
| 649 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 650 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 651 | PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c) |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 652 | : params(p), |
| 653 | completion(c) { |
| 654 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 655 | FileChooserParams params; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 656 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 657 | }; |
| 658 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 659 | namespace { |
| 660 | |
| 661 | class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { |
| 662 | public: |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 663 | explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget) |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 664 | : webwidget_(webwidget) {} |
| 665 | |
| 666 | virtual void OnLockMouseACK(bool succeeded) OVERRIDE { |
| 667 | if (succeeded) |
| 668 | webwidget_->didAcquirePointerLock(); |
| 669 | else |
| 670 | webwidget_->didNotAcquirePointerLock(); |
| 671 | } |
| 672 | |
| 673 | virtual void OnMouseLockLost() OVERRIDE { |
| 674 | webwidget_->didLosePointerLock(); |
| 675 | } |
| 676 | |
| 677 | virtual bool HandleMouseLockedInputEvent( |
| 678 | const WebKit::WebMouseEvent &event) OVERRIDE { |
| 679 | // The WebWidget handles mouse lock in WebKit's handleInputEvent(). |
| 680 | return false; |
| 681 | } |
| 682 | |
| 683 | private: |
| 684 | WebKit::WebWidget* webwidget_; |
| 685 | }; |
| 686 | |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 687 | int64 ExtractPostId(const WebHistoryItem& item) { |
| 688 | if (item.isNull()) |
| 689 | return -1; |
| 690 | |
| 691 | if (item.httpBody().isNull()) |
| 692 | return -1; |
| 693 | |
| 694 | return item.httpBody().identifier(); |
| 695 | } |
| 696 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 697 | bool TouchEnabled() { |
| 698 | // Based on the definition of chrome::kEnableTouchIcon. |
| 699 | #if defined(OS_ANDROID) |
| 700 | return true; |
| 701 | #else |
| 702 | return false; |
| 703 | #endif |
| 704 | } |
| 705 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 706 | WebDragData DropDataToWebDragData(const DropData& drop_data) { |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 707 | std::vector<WebDragData::Item> item_list; |
| 708 | |
| 709 | // These fields are currently unused when dragging into WebKit. |
| 710 | DCHECK(drop_data.download_metadata.empty()); |
| 711 | DCHECK(drop_data.file_contents.empty()); |
| 712 | DCHECK(drop_data.file_description_filename.empty()); |
| 713 | |
| 714 | if (!drop_data.text.is_null()) { |
| 715 | WebDragData::Item item; |
| 716 | item.storageType = WebDragData::Item::StorageTypeString; |
| 717 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| 718 | item.stringData = drop_data.text.string(); |
| 719 | item_list.push_back(item); |
| 720 | } |
| 721 | |
| 722 | // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it |
| 723 | // meaningful to write an empty URL to the clipboard? |
| 724 | if (!drop_data.url.is_empty()) { |
| 725 | WebDragData::Item item; |
| 726 | item.storageType = WebDragData::Item::StorageTypeString; |
| 727 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 728 | item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
| 729 | item.title = drop_data.url_title; |
| 730 | item_list.push_back(item); |
| 731 | } |
| 732 | |
| 733 | if (!drop_data.html.is_null()) { |
| 734 | WebDragData::Item item; |
| 735 | item.storageType = WebDragData::Item::StorageTypeString; |
| 736 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 737 | item.stringData = drop_data.html.string(); |
| 738 | item.baseURL = drop_data.html_base_url; |
| 739 | item_list.push_back(item); |
| 740 | } |
| 741 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 742 | for (std::vector<DropData::FileInfo>::const_iterator it = |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 743 | drop_data.filenames.begin(); |
| 744 | it != drop_data.filenames.end(); |
| 745 | ++it) { |
| 746 | WebDragData::Item item; |
| 747 | item.storageType = WebDragData::Item::StorageTypeFilename; |
| 748 | item.filenameData = it->path; |
| 749 | item.displayNameData = it->display_name; |
| 750 | item_list.push_back(item); |
| 751 | } |
| 752 | |
| 753 | for (std::map<base::string16, base::string16>::const_iterator it = |
| 754 | drop_data.custom_data.begin(); |
| 755 | it != drop_data.custom_data.end(); |
| 756 | ++it) { |
| 757 | WebDragData::Item item; |
| 758 | item.storageType = WebDragData::Item::StorageTypeString; |
| 759 | item.stringType = it->first; |
| 760 | item.stringData = it->second; |
| 761 | item_list.push_back(item); |
| 762 | } |
| 763 | |
| 764 | WebDragData result; |
| 765 | result.initialize(); |
| 766 | result.setItems(item_list); |
| 767 | result.setFilesystemId(drop_data.filesystem_id); |
| 768 | return result; |
| 769 | } |
| 770 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 771 | } // namespace |
| 772 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 773 | RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) |
| 774 | : RenderWidget(WebKit::WebPopupTypeNone, |
| 775 | params->screen_info, |
| 776 | params->swapped_out), |
| 777 | webkit_preferences_(params->webkit_prefs), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 778 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 779 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 780 | send_preferred_size_changes_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 781 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 782 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 783 | opened_by_user_gesture_(true), |
| 784 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 785 | page_id_(-1), |
| 786 | last_page_id_sent_to_browser_(-1), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 787 | next_page_id_(params->next_page_id), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 788 | history_list_offset_(-1), |
| 789 | history_list_length_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 790 | target_url_status_(TARGET_NONE), |
[email protected] | bbef1d3 | 2011-10-25 14:36:55 | [diff] [blame] | 791 | selection_text_offset_(0), |
[email protected] | e017c9c | 2013-02-20 13:44:52 | [diff] [blame] | 792 | selection_range_(ui::Range::InvalidRange()), |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 793 | #if defined(OS_ANDROID) |
| 794 | top_controls_constraints_(cc::BOTH), |
| 795 | #endif |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 796 | cached_is_main_frame_pinned_to_left_(false), |
| 797 | cached_is_main_frame_pinned_to_right_(false), |
| 798 | cached_has_main_frame_horizontal_scrollbar_(false), |
| 799 | cached_has_main_frame_vertical_scrollbar_(false), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 800 | cookie_jar_(this), |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 801 | notification_provider_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 802 | geolocation_dispatcher_(NULL), |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 803 | input_tag_speech_dispatcher_(NULL), |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 804 | speech_recognition_dispatcher_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 805 | device_orientation_dispatcher_(NULL), |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 806 | media_stream_dispatcher_(NULL), |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 807 | browser_plugin_manager_(NULL), |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 808 | media_stream_client_(NULL), |
| 809 | web_user_media_client_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 810 | devtools_agent_(NULL), |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 811 | accessibility_mode_(AccessibilityModeOff), |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 812 | renderer_accessibility_(NULL), |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 813 | java_bridge_dispatcher_(NULL), |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 814 | mouse_lock_dispatcher_(NULL), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 815 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 816 | body_background_color_(SK_ColorWHITE), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 817 | expected_content_intent_id_(0), |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 818 | media_player_proxy_(NULL), |
[email protected] | a756427 | 2013-04-19 14:24:46 | [diff] [blame] | 819 | #endif |
| 820 | #if defined(OS_WIN) |
| 821 | focused_plugin_id_(-1), |
| 822 | #endif |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 823 | enumeration_completion_id_(0), |
[email protected] | a756427 | 2013-04-19 14:24:46 | [diff] [blame] | 824 | #if defined(OS_ANDROID) |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 825 | load_progress_tracker_(new LoadProgressTracker(this)), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 826 | #endif |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 827 | session_storage_namespace_id_(params->session_storage_namespace_id), |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 828 | decrement_shared_popup_at_destruction_(false), |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 829 | handling_select_range_(false), |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 830 | next_snapshot_id_(0), |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 831 | allow_partial_swap_(params->allow_partial_swap), |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 832 | context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | void RenderViewImpl::Initialize(RenderViewImplParams* params) { |
[email protected] | 2f61bdd | 2013-07-02 18:38:47 | [diff] [blame] | 836 | RenderFrameImpl* main_frame = RenderFrameImpl::Create( |
| 837 | this, params->main_frame_routing_id); |
| 838 | main_render_frame_.reset(main_frame); |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 839 | |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 840 | #if defined(ENABLE_PLUGINS) |
| 841 | pepper_helper_.reset(new PepperPluginDelegateImpl(this)); |
| 842 | #else |
| 843 | pepper_helper_.reset(new RenderViewPepperHelper()); |
| 844 | #endif |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 845 | routing_id_ = params->routing_id; |
| 846 | surface_id_ = params->surface_id; |
| 847 | if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created) |
| 848 | opener_id_ = params->opener_id; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 849 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 850 | // Ensure we start with a valid next_page_id_ from the browser. |
| 851 | DCHECK_GE(next_page_id_, 0); |
| 852 | |
[email protected] | 21b3a6ae | 2011-11-30 00:45:29 | [diff] [blame] | 853 | #if defined(ENABLE_NOTIFICATIONS) |
| 854 | notification_provider_ = new NotificationProvider(this); |
| 855 | #else |
| 856 | notification_provider_ = NULL; |
| 857 | #endif |
| 858 | |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 859 | webwidget_ = WebView::create(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 860 | webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 861 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 862 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 863 | |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 864 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 865 | stats_collection_observer_.reset(new StatsCollectionObserver(this)); |
| 866 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 867 | #if defined(OS_ANDROID) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 868 | content::DeviceTelephonyInfo device_info; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 869 | |
| 870 | const std::string region_code = |
| 871 | command_line.HasSwitch(switches::kNetworkCountryIso) |
| 872 | ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 873 | : device_info.GetNetworkCountryIso(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 874 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 875 | new AddressDetector())); |
| 876 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 877 | new PhoneNumberDetector(region_code))); |
| 878 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 879 | new EmailDetector())); |
| 880 | #endif |
| 881 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 882 | if (params->counter) { |
| 883 | shared_popup_counter_ = params->counter; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 884 | // Only count this if it isn't swapped out upon creation. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 885 | if (!params->swapped_out) |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 886 | shared_popup_counter_->data++; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 887 | decrement_shared_popup_at_destruction_ = true; |
| 888 | } else { |
| 889 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 890 | decrement_shared_popup_at_destruction_ = false; |
| 891 | } |
| 892 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 893 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 894 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 895 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 896 | AddRef(); |
| 897 | |
| 898 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 899 | // completing initialization. Otherwise, we can finish it now. |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 900 | if (opener_id_ == MSG_ROUTING_NONE) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 901 | did_show_ = true; |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 902 | CompleteInit(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 903 | } |
| 904 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 905 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 906 | g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this)); |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 907 | webview()->setDeviceScaleFactor(device_scale_factor_); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 908 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 909 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 910 | webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled( |
| 911 | ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_)); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 912 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 913 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 914 | webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled( |
| 915 | ShouldUseAcceleratedFixedRootBackground(device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 916 | |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 917 | webkit_glue::ApplyWebPreferences(webkit_preferences_, webview()); |
[email protected] | 2f61bdd | 2013-07-02 18:38:47 | [diff] [blame] | 918 | webview()->initializeMainFrame(main_render_frame_.get()); |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 919 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 920 | if (switches::IsTouchDragDropEnabled()) |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 921 | webview()->settings()->setTouchDragDropEnabled(true); |
| 922 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 923 | if (switches::IsTouchEditingEnabled()) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 924 | webview()->settings()->setTouchEditingEnabled(true); |
| 925 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 926 | if (!params->frame_name.empty()) |
| 927 | webview()->mainFrame()->setName(params->frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 928 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 929 | OnSetRendererPrefs(params->renderer_prefs); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 930 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 931 | #if defined(ENABLE_WEBRTC) |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 932 | if (!media_stream_dispatcher_) |
| 933 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 934 | #endif |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 935 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 936 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 937 | #if defined(OS_MACOSX) |
| 938 | new TextInputClientObserver(this); |
| 939 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 940 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 941 | #if defined(OS_ANDROID) |
[email protected] | bc42744 | 2013-07-13 02:53:08 | [diff] [blame] | 942 | media_player_manager_.reset(new RendererMediaPlayerManager()); |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 943 | #endif |
| 944 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 945 | // The next group of objects all implement RenderViewObserver, so are deleted |
| 946 | // along with the RenderView automatically. |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 947 | devtools_agent_ = new DevToolsAgent(this); |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 948 | if (RenderWidgetCompositor* rwc = compositor()) { |
| 949 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 950 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 951 | mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 952 | new ImageLoadingHelper(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 953 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 954 | // Create renderer_accessibility_ if needed. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 955 | OnSetAccessibilityMode(params->accessibility_mode); |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 956 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 957 | new IdleUserDetector(this); |
| 958 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 959 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 960 | enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION; |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 961 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 962 | enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION; |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 963 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 964 | ProcessViewLayoutFlags(command_line); |
[email protected] | 7ddea980 | 2012-02-22 23:08:05 | [diff] [blame] | 965 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 966 | GetContentClient()->renderer()->RenderViewCreated(this); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 967 | |
| 968 | // If we have an opener_id but we weren't created by a renderer, then |
| 969 | // it's the browser asking us to set our opener to another RenderView. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 970 | if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) { |
| 971 | RenderViewImpl* opener_view = FromRoutingID(params->opener_id); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 972 | if (opener_view) |
| 973 | webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | // If we are initially swapped out, navigate to kSwappedOutURL. |
| 977 | // This ensures we are in a unique origin that others cannot script. |
| 978 | if (is_swapped_out_) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 979 | NavigateToSwappedOutURL(webview()->mainFrame()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 980 | } |
| 981 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 982 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 983 | history_page_ids_.clear(); |
| 984 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 985 | if (decrement_shared_popup_at_destruction_) |
| 986 | shared_popup_counter_->data--; |
| 987 | |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 988 | base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_); |
| 989 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 990 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 991 | while (!file_chooser_completions_.empty()) { |
| 992 | if (file_chooser_completions_.front()->completion) { |
| 993 | file_chooser_completions_.front()->completion->didChooseFile( |
| 994 | WebVector<WebString>()); |
| 995 | } |
| 996 | file_chooser_completions_.pop_front(); |
| 997 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 998 | |
[email protected] | 8ed1d3f | 2013-02-20 11:45:55 | [diff] [blame] | 999 | #if defined(OS_ANDROID) |
| 1000 | // The date/time picker client is both a scoped_ptr member of this class and |
| 1001 | // a RenderViewObserver. Reset it to prevent double deletion. |
| 1002 | date_time_picker_client_.reset(); |
| 1003 | #endif |
| 1004 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1005 | #ifndef NDEBUG |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 1006 | // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 1007 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1008 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 1009 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 1010 | RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 1011 | for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 1012 | it != routing_id_views->end(); ++it) |
| 1013 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1014 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1015 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1016 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1017 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1021 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1022 | ViewMap* views = g_view_map.Pointer(); |
| 1023 | ViewMap::iterator it = views->find(webview); |
| 1024 | return it == views->end() ? NULL : it->second; |
| 1025 | } |
| 1026 | |
| 1027 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1028 | RenderView* RenderView::FromWebView(WebKit::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1029 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /*static*/ |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 1033 | RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) { |
| 1034 | RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
| 1035 | RoutingIDViewMap::iterator it = views->find(routing_id); |
| 1036 | return it == views->end() ? NULL : it->second; |
| 1037 | } |
| 1038 | |
| 1039 | /*static*/ |
| 1040 | RenderView* RenderView::FromRoutingID(int routing_id) { |
| 1041 | return RenderViewImpl::FromRoutingID(routing_id); |
| 1042 | } |
| 1043 | |
| 1044 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1045 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 1046 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1047 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 1048 | if (!visitor->Visit(it->second)) |
| 1049 | return; |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1054 | RenderViewImpl* RenderViewImpl::Create( |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1055 | int32 opener_id, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1056 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1057 | const WebPreferences& webkit_prefs, |
| 1058 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1059 | int32 routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1060 | int32 main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1061 | int32 surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1062 | int64 session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1063 | const string16& frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1064 | bool is_renderer_created, |
| 1065 | bool swapped_out, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1066 | int32 next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1067 | const WebKit::WebScreenInfo& screen_info, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 1068 | AccessibilityMode accessibility_mode, |
| 1069 | bool allow_partial_swap) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1070 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1071 | RenderViewImplParams params( |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1072 | opener_id, |
| 1073 | renderer_prefs, |
| 1074 | webkit_prefs, |
| 1075 | counter, |
| 1076 | routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1077 | main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1078 | surface_id, |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1079 | session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1080 | frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1081 | is_renderer_created, |
| 1082 | swapped_out, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1083 | next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1084 | screen_info, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 1085 | accessibility_mode, |
| 1086 | allow_partial_swap); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1087 | RenderViewImpl* render_view = NULL; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1088 | if (g_create_render_view_impl) |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1089 | render_view = g_create_render_view_impl(¶ms); |
| 1090 | else |
| 1091 | render_view = new RenderViewImpl(¶ms); |
| 1092 | render_view->Initialize(¶ms); |
| 1093 | return render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | // static |
| 1097 | void RenderViewImpl::InstallCreateHook( |
| 1098 | RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) { |
| 1099 | CHECK(!g_create_render_view_impl); |
| 1100 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1101 | } |
| 1102 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1103 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1104 | observers_.AddObserver(observer); |
| 1105 | } |
| 1106 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1107 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 1108 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1109 | observers_.RemoveObserver(observer); |
| 1110 | } |
| 1111 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1112 | WebKit::WebView* RenderViewImpl::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 1113 | return static_cast<WebKit::WebView*>(webwidget()); |
| 1114 | } |
| 1115 | |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 1116 | void RenderViewImpl::PluginCrashed(const base::FilePath& plugin_path, |
[email protected] | cf4d6e74 | 2013-01-10 14:06:42 | [diff] [blame] | 1117 | base::ProcessId plugin_pid) { |
| 1118 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path, plugin_pid)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1119 | } |
| 1120 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1121 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1122 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1123 | // If the renderer is visible, set initial visibility and focus state. |
| 1124 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1125 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1126 | delegate->SetContainerVisibility(true); |
| 1127 | if (webview() && webview()->isActive()) |
| 1128 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1129 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1130 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1131 | // Plugins start assuming the content has focus (so that they work in |
| 1132 | // environments where RenderView isn't hosting them), so we always have to |
| 1133 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 1134 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1135 | } |
| 1136 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1137 | void RenderViewImpl::UnregisterPluginDelegate( |
| 1138 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1139 | plugin_delegates_.erase(delegate); |
| 1140 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1141 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1142 | bool RenderViewImpl::GetPluginInfo(const GURL& url, |
| 1143 | const GURL& page_url, |
| 1144 | const std::string& mime_type, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 1145 | WebPluginInfo* plugin_info, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1146 | std::string* actual_mime_type) { |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 1147 | bool found = false; |
| 1148 | Send(new ViewHostMsg_GetPluginInfo( |
| 1149 | routing_id_, url, page_url, mime_type, &found, plugin_info, |
| 1150 | actual_mime_type)); |
| 1151 | return found; |
| 1152 | } |
| 1153 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 1154 | void RenderViewImpl::TransferActiveWheelFlingAnimation( |
| 1155 | const WebKit::WebActiveWheelFlingParameters& params) { |
| 1156 | if (webview()) |
| 1157 | webview()->transferActiveWheelFlingAnimation(params); |
| 1158 | } |
| 1159 | |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 1160 | bool RenderViewImpl::HasIMETextFocus() { |
| 1161 | return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
| 1162 | } |
| 1163 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1164 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1165 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 1166 | if (main_frame) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1167 | GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1168 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1169 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 1170 | RenderViewObserver* observer; |
| 1171 | while ((observer = it.GetNext()) != NULL) |
| 1172 | if (observer->OnMessageReceived(message)) |
| 1173 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1174 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1175 | bool handled = true; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1176 | bool msg_is_ok = true; |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1177 | IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1178 | IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) |
| 1179 | IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) |
| 1180 | IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete) |
| 1181 | IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand) |
| 1182 | IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret) |
| 1183 | IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) |
| 1184 | IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
| 1185 | IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) |
| 1186 | IPC_MESSAGE_HANDLER(InputMsg_Replace, OnReplace) |
| 1187 | IPC_MESSAGE_HANDLER(InputMsg_ReplaceMisspelling, OnReplaceMisspelling) |
| 1188 | IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect, |
| 1189 | OnScrollFocusedEditableNodeIntoRect) |
| 1190 | IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll) |
| 1191 | IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange) |
| 1192 | IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent, |
| 1193 | OnSetEditCommandsForNextKeyEvent) |
| 1194 | IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) |
| 1195 | IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1196 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 1197 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1198 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1199 | IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1200 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets, |
| 1201 | OnSetEditableSelectionOffsets) |
| 1202 | IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText, |
| 1203 | OnSetCompositionFromExistingText) |
| 1204 | IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete, |
| 1205 | OnExtendSelectionAndDelete) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1206 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
| 1207 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 1208 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 1209 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1210 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 1211 | IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1212 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 1213 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1214 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1215 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 1216 | OnResetPageEncodingToDefault) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1217 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 1218 | IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 1219 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1220 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 1221 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 1222 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 1223 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| 1224 | IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) |
| 1225 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 1226 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 1227 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1228 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1229 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 1230 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 1231 | IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1232 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1233 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 1234 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1235 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 1236 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1237 | IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1238 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 1239 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1240 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 1241 | OnDisassociateFromPopupCount) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1242 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 1243 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1244 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 1245 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 1246 | OnEnablePreferredSizeChangedMode) |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1247 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1248 | IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 1249 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 1250 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1251 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 1252 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 1253 | IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent, |
| 1254 | OnOrientationChangeEvent) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1255 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 1256 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 1257 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 1258 | OnCustomContextMenuAction) |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 1259 | IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 1260 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, |
| 1261 | OnPpapiBrokerChannelCreated) |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 1262 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult, |
| 1263 | OnPpapiBrokerPermissionResult) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 1264 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 1265 | OnGetAllSavableResourceLinksForCurrentPage) |
| 1266 | IPC_MESSAGE_HANDLER( |
| 1267 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 1268 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 1269 | IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 1270 | IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 1271 | // TODO(viettrungluu): Move to a separate message filter. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1272 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 1273 | OnSetHistoryLengthAndPrune) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 1274 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | c7654a23 | 2013-06-12 21:04:44 | [diff] [blame] | 1275 | #if defined(OS_ANDROID) |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 1276 | IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
[email protected] | da81627 | 2013-05-15 21:31:17 | [diff] [blame] | 1277 | #endif |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1278 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 1279 | IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1280 | #if defined(OS_ANDROID) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1281 | IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult, |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1282 | OnActivateNearestFindResult) |
| 1283 | IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects) |
| 1284 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1285 | IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView, |
| 1286 | OnUndoScrollFocusedEditableNodeIntoRect) |
[email protected] | 452b4a9 | 2013-03-28 21:24:38 | [diff] [blame] | 1287 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState, |
| 1288 | OnUpdateTopControlsState) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1289 | #elif defined(OS_MACOSX) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1290 | IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1291 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 1292 | OnPluginImeCompositionCompleted) |
| 1293 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 1294 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1295 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| 1296 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| 1297 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 1298 | IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB, |
| 1299 | OnReleaseDisambiguationPopupDIB) |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 1300 | IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, |
| 1301 | OnWindowSnapshotCompleted) |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1302 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1303 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1304 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1305 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1306 | |
| 1307 | if (!msg_is_ok) { |
| 1308 | // The message had a handler, but its deserialization failed. |
| 1309 | // Kill the renderer to avoid potential spoofing attacks. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1310 | CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1311 | } |
| 1312 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1313 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1314 | } |
| 1315 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1316 | void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 1317 | MaybeHandleDebugURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1318 | if (!webview()) |
| 1319 | return; |
| 1320 | |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 1321 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
| 1322 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1323 | bool is_reload = IsReload(params); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1324 | |
| 1325 | // If this is a stale back/forward (due to a recent navigation the browser |
| 1326 | // didn't know about), ignore it. |
| 1327 | if (IsBackForwardToStaleEntry(params, is_reload)) |
| 1328 | return; |
| 1329 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1330 | // Swap this renderer back in if necessary. |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1331 | if (is_swapped_out_) { |
| 1332 | // We marked the view as hidden when swapping the view out, so be sure to |
| 1333 | // reset the visibility state before navigating to the new URL. |
| 1334 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | 890b06ca | 2012-12-13 21:07:36 | [diff] [blame] | 1335 | |
| 1336 | // If this is an attempt to reload while we are swapped out, we should not |
| 1337 | // reload swappedout://, but the previous page, which is stored in |
| 1338 | // params.state. Setting is_reload to false will treat this like a back |
| 1339 | // navigation to accomplish that. |
| 1340 | is_reload = false; |
| 1341 | |
[email protected] | 0b05902 | 2013-07-03 22:50:09 | [diff] [blame] | 1342 | // We refresh timezone when a view is swapped in since timezone |
| 1343 | // can get out of sync when the system timezone is updated while |
| 1344 | // the view is swapped out. |
| 1345 | NotifyTimezoneChange(webview()->mainFrame()); |
| 1346 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1347 | SetSwappedOut(false); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1348 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1349 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1350 | if (params.should_clear_history_list) { |
| 1351 | CHECK_EQ(params.pending_history_list_offset, -1); |
| 1352 | CHECK_EQ(params.current_history_list_offset, -1); |
| 1353 | CHECK_EQ(params.current_history_list_length, 0); |
| 1354 | } |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1355 | history_list_offset_ = params.current_history_list_offset; |
| 1356 | history_list_length_ = params.current_history_list_length; |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1357 | if (history_list_length_ >= 0) |
| 1358 | history_page_ids_.resize(history_list_length_, -1); |
| 1359 | if (params.pending_history_list_offset >= 0 && |
| 1360 | params.pending_history_list_offset < history_list_length_) |
| 1361 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1362 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1363 | GetContentClient()->SetActiveURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1364 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1365 | WebFrame* frame = webview()->mainFrame(); |
| 1366 | if (!params.frame_to_navigate.empty()) { |
| 1367 | frame = webview()->findFrameByName( |
| 1368 | WebString::fromUTF8(params.frame_to_navigate)); |
| 1369 | CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; |
| 1370 | } |
| 1371 | |
| 1372 | if (is_reload && frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1373 | // We cannot reload if we do not have any history state. This happens, for |
| 1374 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1375 | // a hack since it means that reload after a crashed tab does not cause an |
| 1376 | // end-to-end cache validation. |
| 1377 | is_reload = false; |
| 1378 | } |
| 1379 | |
[email protected] | 3d2fd59 | 2012-11-30 02:05:50 | [diff] [blame] | 1380 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params)); |
[email protected] | 48a5c77 | 2011-04-18 23:50:50 | [diff] [blame] | 1381 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1382 | // If we are reloading, then WebKit will use the history state of the current |
| 1383 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1384 | // have history state, then we need to navigate to it, which corresponds to a |
| 1385 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1386 | if (is_reload) { |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1387 | bool reload_original_url = |
| 1388 | (params.navigation_type == |
| 1389 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1390 | bool ignore_cache = (params.navigation_type == |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 1391 | ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1392 | |
| 1393 | if (reload_original_url) |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1394 | frame->reloadWithOverrideURL(params.url, true); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1395 | else |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1396 | frame->reload(ignore_cache); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1397 | } else if (params.page_state.IsValid()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1398 | // We must know the page ID of the page we are navigating back to. |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1399 | DCHECK_NE(params.page_id, -1); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1400 | WebHistoryItem item = PageStateToHistoryItem(params.page_state); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1401 | if (!item.isNull()) { |
| 1402 | // Ensure we didn't save the swapped out URL in UpdateState, since the |
| 1403 | // browser should never be telling us to navigate to swappedout://. |
| 1404 | CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL)); |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1405 | frame->loadHistoryItem(item); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1406 | } |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1407 | } else if (!params.base_url_for_data_url.is_empty()) { |
| 1408 | // A loadData request with a specified base URL. |
| 1409 | std::string mime_type, charset, data; |
| 1410 | if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1411 | frame->loadData( |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1412 | WebData(data.c_str(), data.length()), |
| 1413 | WebString::fromUTF8(mime_type), |
| 1414 | WebString::fromUTF8(charset), |
| 1415 | params.base_url_for_data_url, |
| 1416 | params.history_url_for_data_url, |
| 1417 | false); |
| 1418 | } else { |
| 1419 | CHECK(false) << |
| 1420 | "Invalid URL passed: " << params.url.possibly_invalid_spec(); |
| 1421 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1422 | } else { |
| 1423 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1424 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1425 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1426 | // A session history navigation should have been accompanied by state. |
[email protected] | cbc0cb7 | 2011-12-06 18:58:23 | [diff] [blame] | 1427 | CHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1428 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1429 | if (frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1430 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1431 | |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1432 | if (params.referrer.url.is_valid()) { |
| 1433 | WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
| 1434 | params.referrer.policy, |
| 1435 | params.url, |
| 1436 | WebString::fromUTF8(params.referrer.url.spec())); |
| 1437 | if (!referrer.isEmpty()) |
| 1438 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1439 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1440 | |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 1441 | if (!params.extra_headers.empty()) { |
| 1442 | for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), |
| 1443 | params.extra_headers.end(), "\n"); |
| 1444 | i.GetNext(); ) { |
| 1445 | request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 1446 | WebString::fromUTF8(i.values())); |
| 1447 | } |
| 1448 | } |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1449 | |
| 1450 | if (params.is_post) { |
| 1451 | request.setHTTPMethod(WebString::fromUTF8("POST")); |
| 1452 | |
| 1453 | // Set post data. |
| 1454 | WebHTTPBody http_body; |
| 1455 | http_body.initialize(); |
| 1456 | http_body.appendData(WebData( |
| 1457 | reinterpret_cast<const char*>( |
| 1458 | ¶ms.browser_initiated_post_data.front()), |
| 1459 | params.browser_initiated_post_data.size())); |
| 1460 | request.setHTTPBody(http_body); |
| 1461 | } |
| 1462 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1463 | frame->loadRequest(request); |
[email protected] | 198a95d6 | 2013-04-11 00:44:21 | [diff] [blame] | 1464 | |
| 1465 | // If this is a cross-process navigation, the browser process will send |
| 1466 | // along the proper navigation start value. |
| 1467 | if (!params.browser_navigation_start.is_null() && |
| 1468 | frame->provisionalDataSource()) { |
| 1469 | // browser_navigation_start is likely before this process existed, so we |
| 1470 | // can't use InterProcessTimeTicksConverter. Instead, the best we can do |
| 1471 | // is just ensure we don't report a bogus value in the future. |
| 1472 | base::TimeTicks navigation_start = std::min( |
| 1473 | base::TimeTicks::Now(), params.browser_navigation_start); |
| 1474 | double navigation_start_seconds = |
| 1475 | (navigation_start - base::TimeTicks()).InSecondsF(); |
| 1476 | frame->provisionalDataSource()->setNavigationStartTime( |
| 1477 | navigation_start_seconds); |
| 1478 | } |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1479 | } |
| 1480 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1481 | // In case LoadRequest failed before DidCreateDataSource was called. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1482 | pending_navigation_params_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1483 | } |
| 1484 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1485 | bool RenderViewImpl::IsBackForwardToStaleEntry( |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1486 | const ViewMsg_Navigate_Params& params, |
| 1487 | bool is_reload) { |
| 1488 | // Make sure this isn't a back/forward to an entry we have already cropped |
| 1489 | // or replaced from our history, before the browser knew about it. If so, |
| 1490 | // a new navigation has committed in the mean time, and we can ignore this. |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1491 | bool is_back_forward = !is_reload && params.page_state.IsValid(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1492 | |
| 1493 | // Note: if the history_list_length_ is 0 for a back/forward, we must be |
| 1494 | // restoring from a previous session. We'll update our state in OnNavigate. |
| 1495 | if (!is_back_forward || history_list_length_ <= 0) |
| 1496 | return false; |
| 1497 | |
| 1498 | DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_); |
| 1499 | |
| 1500 | // Check for whether the forward history has been cropped due to a recent |
| 1501 | // navigation the browser didn't know about. |
| 1502 | if (params.pending_history_list_offset >= history_list_length_) |
| 1503 | return true; |
| 1504 | |
| 1505 | // Check for whether this entry has been replaced with a new one. |
| 1506 | int expected_page_id = |
| 1507 | history_page_ids_[params.pending_history_list_offset]; |
[email protected] | 9978b8f0 | 2011-08-13 16:17:44 | [diff] [blame] | 1508 | if (expected_page_id > 0 && params.page_id != expected_page_id) { |
| 1509 | if (params.page_id < expected_page_id) |
| 1510 | return true; |
| 1511 | |
| 1512 | // Otherwise we've removed an earlier entry and should have shifted all |
| 1513 | // entries left. For now, it's ok to lazily update the list. |
| 1514 | // TODO(creis): Notify all live renderers when we remove entries from |
| 1515 | // the front of the list, so that we don't hit this case. |
| 1516 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
| 1517 | } |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1518 | |
| 1519 | return false; |
| 1520 | } |
| 1521 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1522 | // Stop loading the current page |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1523 | void RenderViewImpl::OnStop() { |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 1524 | if (webview()) { |
| 1525 | WebFrame* main_frame = webview()->mainFrame(); |
| 1526 | // Stop the alt error page fetcher. If we let it continue it may complete |
| 1527 | // and cause RenderViewHostManager to swap to this RenderView, even though |
| 1528 | // it may no longer be active. |
| 1529 | StopAltErrorPageFetcher(main_frame->provisionalDataSource()); |
| 1530 | StopAltErrorPageFetcher(main_frame->dataSource()); |
| 1531 | main_frame->stopLoading(); |
| 1532 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1533 | } |
| 1534 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1535 | // Reload current focused frame. |
| 1536 | // E.g. called by right-clicking on the frame and picking "reload this frame". |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1537 | void RenderViewImpl::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1538 | if (webview() && webview()->focusedFrame()) { |
| 1539 | // We always obey the cache (ignore_cache=false) here. |
| 1540 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1541 | // a cache-ignoring reload of the frame. |
| 1542 | webview()->focusedFrame()->reload(false); |
| 1543 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1544 | } |
| 1545 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1546 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1547 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1548 | } |
| 1549 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1550 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1551 | // Check if there is a targeturl waiting to be sent. |
| 1552 | if (target_url_status_ == TARGET_PENDING) { |
| 1553 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1554 | pending_target_url_)); |
| 1555 | } |
| 1556 | |
| 1557 | target_url_status_ = TARGET_NONE; |
| 1558 | } |
| 1559 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1560 | void RenderViewImpl::OnCopy() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1561 | if (!webview()) |
| 1562 | return; |
| 1563 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1564 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1565 | WebNode current_node = context_menu_node_.isNull() ? |
| 1566 | GetFocusedNode() : context_menu_node_; |
[email protected] | f6b1856b | 2011-06-29 22:02:53 | [diff] [blame] | 1567 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"), |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1568 | current_node); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1569 | } |
| 1570 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1571 | void RenderViewImpl::OnCut() { |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1572 | if (!webview()) |
| 1573 | return; |
| 1574 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1575 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1576 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"), |
| 1577 | GetFocusedNode()); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1578 | } |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1579 | |
| 1580 | void RenderViewImpl::OnDelete() { |
| 1581 | if (!webview()) |
| 1582 | return; |
| 1583 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1584 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"), |
| 1585 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
| 1589 | const std::string& value) { |
| 1590 | if (!webview() || !webview()->focusedFrame()) |
| 1591 | return; |
| 1592 | |
| 1593 | webview()->focusedFrame()->executeCommand( |
| 1594 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
| 1595 | } |
| 1596 | |
| 1597 | void RenderViewImpl::OnMoveCaret(const gfx::Point& point) { |
| 1598 | if (!webview()) |
| 1599 | return; |
| 1600 | |
| 1601 | Send(new ViewHostMsg_MoveCaret_ACK(routing_id_)); |
| 1602 | |
| 1603 | webview()->focusedFrame()->moveCaretSelectionTowardsWindowPoint(point); |
| 1604 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1605 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1606 | void RenderViewImpl::OnPaste() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1607 | if (!webview()) |
| 1608 | return; |
| 1609 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1610 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1611 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"), |
| 1612 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1613 | } |
| 1614 | |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1615 | void RenderViewImpl::OnPasteAndMatchStyle() { |
| 1616 | if (!webview()) |
| 1617 | return; |
| 1618 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1619 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1620 | webview()->focusedFrame()->executeCommand( |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1621 | WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode()); |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1622 | } |
| 1623 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1624 | void RenderViewImpl::OnRedo() { |
| 1625 | if (!webview()) |
| 1626 | return; |
| 1627 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1628 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"), |
| 1629 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1630 | } |
| 1631 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1632 | void RenderViewImpl::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1633 | if (!webview()) |
| 1634 | return; |
| 1635 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1636 | WebFrame* frame = webview()->focusedFrame(); |
| 1637 | if (!frame->hasSelection()) |
| 1638 | frame->selectWordAroundCaret(); |
[email protected] | 2365c64 | 2013-02-12 19:16:47 | [diff] [blame] | 1639 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1640 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1641 | } |
| 1642 | |
[email protected] | 2365c64 | 2013-02-12 19:16:47 | [diff] [blame] | 1643 | void RenderViewImpl::OnReplaceMisspelling(const string16& text) { |
| 1644 | if (!webview()) |
| 1645 | return; |
| 1646 | |
| 1647 | WebFrame* frame = webview()->focusedFrame(); |
| 1648 | if (!frame->hasSelection()) |
| 1649 | return; |
| 1650 | |
| 1651 | frame->replaceMisspelledRange(text); |
| 1652 | } |
| 1653 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1654 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1655 | const gfx::Rect& rect) { |
| 1656 | WebKit::WebNode node = GetFocusedNode(); |
| 1657 | if (!node.isNull()) { |
| 1658 | if (IsEditableNode(node)) { |
| 1659 | webview()->saveScrollAndScaleState(); |
| 1660 | webview()->scrollFocusedNodeIntoRect(rect); |
| 1661 | } |
| 1662 | } |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1663 | } |
| 1664 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1665 | void RenderViewImpl::OnSelectAll() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1666 | if (!webview()) |
| 1667 | return; |
| 1668 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1669 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1670 | webview()->focusedFrame()->executeCommand( |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1671 | WebString::fromUTF8("SelectAll"), GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1672 | } |
| 1673 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1674 | void RenderViewImpl::OnSelectRange(const gfx::Point& start, |
| 1675 | const gfx::Point& end) { |
| 1676 | if (!webview()) |
| 1677 | return; |
| 1678 | |
| 1679 | Send(new ViewHostMsg_SelectRange_ACK(routing_id_)); |
| 1680 | |
| 1681 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1682 | webview()->focusedFrame()->selectRange(start, end); |
| 1683 | } |
| 1684 | |
| 1685 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
| 1686 | const EditCommands& edit_commands) { |
| 1687 | edit_commands_ = edit_commands; |
| 1688 | } |
| 1689 | |
| 1690 | void RenderViewImpl::OnUndo() { |
| 1691 | if (!webview()) |
| 1692 | return; |
| 1693 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1694 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"), |
| 1695 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1696 | } |
| 1697 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1698 | void RenderViewImpl::OnUnselect() { |
| 1699 | if (!webview()) |
| 1700 | return; |
| 1701 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1702 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1703 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
| 1704 | GetFocusedNode()); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1705 | } |
| 1706 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1707 | #if defined(OS_MACOSX) |
| 1708 | void RenderViewImpl::OnCopyToFindPboard() { |
| 1709 | if (!webview()) |
| 1710 | return; |
| 1711 | |
| 1712 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1713 | // than the |OnCopy()| case. |
| 1714 | WebFrame* frame = webview()->focusedFrame(); |
| 1715 | if (frame->hasSelection()) { |
| 1716 | string16 selection = frame->selectionAsText(); |
| 1717 | RenderThread::Get()->Send( |
| 1718 | new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); |
| 1719 | } |
| 1720 | } |
| 1721 | #endif |
| 1722 | |
| 1723 | void RenderViewImpl::OnSetName(const std::string& name) { |
| 1724 | if (!webview()) |
| 1725 | return; |
| 1726 | |
| 1727 | webview()->mainFrame()->setName(WebString::fromUTF8(name)); |
| 1728 | } |
| 1729 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1730 | void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) { |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1731 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1732 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1733 | webview()->setEditableSelectionOffsets(start, end); |
| 1734 | } |
| 1735 | |
| 1736 | void RenderViewImpl::OnSetCompositionFromExistingText( |
| 1737 | int start, int end, |
| 1738 | const std::vector<WebKit::WebCompositionUnderline>& underlines) { |
| 1739 | if (!webview()) |
| 1740 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1741 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1742 | webview()->setCompositionFromExistingText(start, end, underlines); |
| 1743 | } |
| 1744 | |
| 1745 | void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) { |
| 1746 | if (!webview()) |
| 1747 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1748 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1749 | webview()->extendSelectionAndDelete(before, after); |
| 1750 | } |
| 1751 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1752 | void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length, |
| 1753 | int32 minimum_page_id) { |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1754 | DCHECK_GE(history_length, 0); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1755 | DCHECK(history_list_offset_ == history_list_length_ - 1); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1756 | DCHECK_GE(minimum_page_id, -1); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1757 | |
| 1758 | // Generate the new list. |
| 1759 | std::vector<int32> new_history_page_ids(history_length, -1); |
| 1760 | for (size_t i = 0; i < history_page_ids_.size(); ++i) { |
| 1761 | if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id) |
| 1762 | continue; |
| 1763 | new_history_page_ids.push_back(history_page_ids_[i]); |
| 1764 | } |
| 1765 | new_history_page_ids.swap(history_page_ids_); |
| 1766 | |
| 1767 | // Update indexes. |
| 1768 | history_list_length_ = history_page_ids_.size(); |
| 1769 | history_list_offset_ = history_list_length_ - 1; |
| 1770 | } |
| 1771 | |
| 1772 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1773 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1774 | if (!webview()) |
| 1775 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1776 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1777 | } |
| 1778 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1779 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1780 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1781 | if (!webview()) |
| 1782 | return; |
| 1783 | if (in_live_resize) |
| 1784 | webview()->willStartLiveResize(); |
| 1785 | else |
| 1786 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1787 | } |
| 1788 | #endif |
| 1789 | |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1790 | #if defined(OS_ANDROID) |
| 1791 | void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() { |
| 1792 | const WebNode node = GetFocusedNode(); |
| 1793 | if (!node.isNull() && IsEditableNode(node)) |
| 1794 | webview()->restoreScrollAndScaleState(); |
| 1795 | } |
| 1796 | #endif |
| 1797 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1798 | /////////////////////////////////////////////////////////////////////////////// |
| 1799 | |
| 1800 | // Tell the embedding application that the URL of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1801 | void RenderViewImpl::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1802 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1803 | DCHECK(ds); |
| 1804 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1805 | const WebURLRequest& request = ds->request(); |
| 1806 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1807 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1808 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1809 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 1810 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1811 | InternalDocumentStateData* internal_data = |
| 1812 | InternalDocumentStateData::FromDocumentState(document_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1813 | |
| 1814 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1815 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1816 | params.is_post = false; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1817 | params.post_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1818 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1819 | params.frame_id = frame->identifier(); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 1820 | params.socket_address.set_host(response.remoteIPAddress().utf8()); |
| 1821 | params.socket_address.set_port(response.remotePort()); |
[email protected] | e07ddafe | 2013-03-05 21:03:36 | [diff] [blame] | 1822 | WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response); |
| 1823 | if (extra_data) { |
| 1824 | params.was_fetched_via_proxy = extra_data->was_fetched_via_proxy(); |
| 1825 | } |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1826 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1827 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1828 | |
| 1829 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 1830 | params.url = GetLoadingUrl(frame); |
[email protected] | 809be03 | 2013-03-19 01:56:56 | [diff] [blame] | 1831 | DCHECK(!is_swapped_out_ || params.url == GURL(kSwappedOutURL)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1832 | |
[email protected] | 5f9b871 | 2011-11-23 08:55:57 | [diff] [blame] | 1833 | if (frame->document().baseURL() != params.url) |
| 1834 | params.base_url = frame->document().baseURL(); |
| 1835 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1836 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1837 | params.should_update_history = !ds->hasUnreachableURL() && |
[email protected] | b7df1b7 | 2011-02-10 00:08:04 | [diff] [blame] | 1838 | !response.isMultipartPayload() && (response.httpStatusCode() != 404); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1839 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1840 | params.searchable_form_url = internal_data->searchable_form_url(); |
| 1841 | params.searchable_form_encoding = internal_data->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1842 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1843 | const PasswordForm* password_form_data = document_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1844 | if (password_form_data) |
| 1845 | params.password_form = *password_form_data; |
| 1846 | |
| 1847 | params.gesture = navigation_gesture_; |
| 1848 | navigation_gesture_ = NavigationGestureUnknown; |
| 1849 | |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1850 | // Make navigation state a part of the FrameNavigate message so that commited |
| 1851 | // entry had it at all times. |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1852 | WebHistoryItem item = frame->currentHistoryItem(); |
| 1853 | if (item.isNull()) { |
| 1854 | item.initialize(); |
| 1855 | item.setURLString(request.url().spec().utf16()); |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1856 | } |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1857 | params.page_state = HistoryItemToPageState(item); |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1858 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1859 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1860 | // Top-level navigation. |
| 1861 | |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 1862 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1863 | // will also call us back which will cause us to send a message to |
| 1864 | // update WebContentsImpl. |
| 1865 | webview()->zoomLimitsChanged( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1866 | WebView::zoomFactorToZoomLevel(kMinimumZoomFactor), |
| 1867 | WebView::zoomFactorToZoomLevel(kMaximumZoomFactor)); |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 1868 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1869 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1870 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1871 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1872 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1873 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1874 | // Reset the zoom levels for plugins. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1875 | webview()->setZoomLevel(false, 0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1876 | } else { |
| 1877 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1878 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1879 | } |
| 1880 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1881 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1882 | // This zoom level was merely recorded transiently for this load. We can |
| 1883 | // erase it now. If at some point we reload this page, the browser will |
| 1884 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1885 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1886 | } |
| 1887 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1888 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1889 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1890 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1891 | params.transition = navigation_state->transition_type(); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1892 | if (!PageTransitionIsMainFrame(params.transition)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1893 | // If the main frame does a load, it should not be reported as a subframe |
| 1894 | // navigation. This can occur in the following case: |
| 1895 | // 1. You're on a site with frames. |
| 1896 | // 2. You do a subframe navigation. This is stored with transition type |
| 1897 | // MANUAL_SUBFRAME. |
| 1898 | // 3. You navigate to some non-frame site, say, google.com. |
| 1899 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1900 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1901 | // We don't want that, because any navigation that changes the toplevel |
| 1902 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1903 | // update the URL bar, etc). |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1904 | params.transition = PAGE_TRANSITION_LINK; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1905 | } |
| 1906 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1907 | // If we have a valid consumed client redirect source, |
| 1908 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1909 | // so we set the referrer and transition to match. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1910 | if (completed_client_redirect_src_.url.is_valid()) { |
| 1911 | DCHECK(completed_client_redirect_src_.url == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1912 | params.referrer = completed_client_redirect_src_; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1913 | params.transition = static_cast<PageTransition>( |
| 1914 | params.transition | PAGE_TRANSITION_CLIENT_REDIRECT); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1915 | } else { |
| 1916 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1917 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 1918 | params.referrer = GetReferrerFromRequest(frame, original_request); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1919 | } |
| 1920 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1921 | string16 method = request.httpMethod(); |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1922 | if (EqualsASCII(method, "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1923 | params.is_post = true; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1924 | params.post_id = ExtractPostId(item); |
| 1925 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1926 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1927 | // Send the user agent override back. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1928 | params.is_overriding_user_agent = internal_data->is_overriding_user_agent(); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1929 | |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1930 | // Track the URL of the original request. |
| 1931 | params.original_request_url = original_request.url(); |
| 1932 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1933 | params.history_list_was_cleared = |
| 1934 | navigation_state->history_list_was_cleared(); |
| 1935 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1936 | // Save some histogram data so we can compute the average memory used per |
| 1937 | // page load of the glyphs. |
| 1938 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1939 | webkit_glue::GetGlyphPageCount()); |
| 1940 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1941 | // This message needs to be sent before any of allowScripts(), |
| 1942 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1943 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1944 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1945 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1946 | } else { |
| 1947 | // Subframe navigation: the type depends on whether this navigation |
| 1948 | // generated a new session history entry. When they do generate a session |
| 1949 | // history entry, it means the user initiated the navigation and we should |
| 1950 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1951 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1952 | if (page_id_ > last_page_id_sent_to_browser_) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1953 | params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1954 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1955 | params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1956 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1957 | DCHECK(!navigation_state->history_list_was_cleared()); |
| 1958 | params.history_list_was_cleared = false; |
| 1959 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1960 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1961 | } |
| 1962 | |
| 1963 | last_page_id_sent_to_browser_ = |
| 1964 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1965 | |
| 1966 | // If we end up reusing this WebRequest (for example, due to a #ref click), |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1967 | // we don't want the transition type to persist. Just clear it. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1968 | navigation_state->set_transition_type(PAGE_TRANSITION_LINK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1972 | void RenderViewImpl::UpdateTitle(WebFrame* frame, |
| 1973 | const string16& title, |
| 1974 | WebTextDirection title_direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1975 | // Ignore all but top level navigations. |
| 1976 | if (frame->parent()) |
| 1977 | return; |
| 1978 | |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 1979 | base::debug::TraceLog::GetInstance()->UpdateProcessLabel( |
| 1980 | routing_id_, UTF16ToUTF8(title)); |
| 1981 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1982 | string16 shortened_title = title.substr(0, kMaxTitleChars); |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1983 | Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title, |
| 1984 | title_direction)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1985 | } |
| 1986 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1987 | void RenderViewImpl::UpdateEncoding(WebFrame* frame, |
| 1988 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1989 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1990 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1991 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1992 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1993 | last_encoding_name_ = encoding_name; |
| 1994 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1995 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1996 | } |
| 1997 | } |
| 1998 | |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 1999 | // Sends the last committed session history state to the browser so it will be |
| 2000 | // saved before we navigate to a new page. This must be called *before* the |
| 2001 | // page ID has been updated so we know what it was. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2002 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2003 | // If we have a valid page ID at this point, then it corresponds to the page |
| 2004 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 2005 | // there is no past session history to record. |
| 2006 | if (page_id_ == -1) |
| 2007 | return; |
| 2008 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2009 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2010 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 2011 | SendUpdateState(item); |
| 2012 | } |
| 2013 | |
| 2014 | void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2015 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2016 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2017 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2018 | // Don't send state updates for kSwappedOutURL. |
| 2019 | if (item.urlString() == WebString::fromUTF8(kSwappedOutURL)) |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 2020 | return; |
| 2021 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2022 | Send(new ViewHostMsg_UpdateState( |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 2023 | routing_id_, page_id_, HistoryItemToPageState(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2024 | } |
| 2025 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2026 | void RenderViewImpl::OpenURL(WebFrame* frame, |
| 2027 | const GURL& url, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2028 | const Referrer& referrer, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2029 | WebNavigationPolicy policy) { |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 2030 | ViewHostMsg_OpenURL_Params params; |
| 2031 | params.url = url; |
| 2032 | params.referrer = referrer; |
| 2033 | params.disposition = NavigationPolicyToDisposition(policy); |
| 2034 | params.frame_id = frame->identifier(); |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 2035 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2036 | if (ds) { |
[email protected] | 866fa2cc | 2013-07-22 22:19:52 | [diff] [blame] | 2037 | params.should_replace_current_entry = ds->replacesCurrentHistoryItem(); |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 2038 | } else { |
[email protected] | 866fa2cc | 2013-07-22 22:19:52 | [diff] [blame] | 2039 | params.should_replace_current_entry = false; |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 2040 | } |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 2041 | params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame^] | 2042 | if (GetContentClient()->renderer()->AllowPopup()) |
| 2043 | params.user_gesture = true; |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 2044 | |
| 2045 | if (policy == WebKit::WebNavigationPolicyNewBackgroundTab || |
| 2046 | policy == WebKit::WebNavigationPolicyNewForegroundTab || |
| 2047 | policy == WebKit::WebNavigationPolicyNewWindow || |
| 2048 | policy == WebKit::WebNavigationPolicyNewPopup) { |
| 2049 | WebUserGestureIndicator::consumeUserGesture(); |
| 2050 | } |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 2051 | |
| 2052 | Send(new ViewHostMsg_OpenURL(routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2053 | } |
| 2054 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2055 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2056 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2057 | void RenderViewImpl::LoadNavigationErrorPage( |
| 2058 | WebFrame* frame, |
| 2059 | const WebURLRequest& failed_request, |
| 2060 | const WebURLError& error, |
| 2061 | const std::string& html, |
| 2062 | bool replace) { |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2063 | std::string alt_html; |
| 2064 | const std::string* error_html; |
| 2065 | |
| 2066 | if (!html.empty()) { |
| 2067 | error_html = &html; |
| 2068 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2069 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 2070 | frame, failed_request, error, &alt_html, NULL); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2071 | error_html = &alt_html; |
| 2072 | } |
| 2073 | |
| 2074 | frame->loadHTMLString(*error_html, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2075 | GURL(kUnreachableWebDataURL), |
[email protected] | 21d61e5 | 2011-03-18 19:08:25 | [diff] [blame] | 2076 | error.unreachableURL, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 2077 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2078 | } |
| 2079 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2080 | bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2081 | const string16& message, |
| 2082 | const string16& default_value, |
| 2083 | const GURL& frame_url, |
| 2084 | string16* result) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2085 | bool success = false; |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2086 | string16 result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2087 | if (!result) |
| 2088 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2089 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2090 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 2091 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2092 | return success; |
| 2093 | } |
| 2094 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2095 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2096 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 2097 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 2098 | // it is particularly important that we do not call willEnterModalLoop as |
| 2099 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2100 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2101 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2102 | |
| 2103 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 2104 | return Send(message); |
| 2105 | } |
| 2106 | |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 2107 | void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) { |
| 2108 | int id = next_snapshot_id_++; |
| 2109 | pending_snapshots_.insert(std::make_pair(id, callback)); |
| 2110 | Send(new ViewHostMsg_GetWindowSnapshot(routing_id_, id)); |
| 2111 | } |
| 2112 | |
| 2113 | void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, |
| 2114 | const gfx::Size& size, const std::vector<unsigned char>& png) { |
| 2115 | PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id); |
| 2116 | DCHECK(it != pending_snapshots_.end()); |
| 2117 | it->second.Run(size, png); |
| 2118 | pending_snapshots_.erase(it); |
| 2119 | } |
| 2120 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2121 | // WebKit::WebViewClient ------------------------------------------------------ |
| 2122 | |
[email protected] | 916dfb6 | 2012-03-05 03:39:37 | [diff] [blame] | 2123 | WebView* RenderViewImpl::createView( |
| 2124 | WebFrame* creator, |
| 2125 | const WebURLRequest& request, |
| 2126 | const WebWindowFeatures& features, |
| 2127 | const WebString& frame_name, |
| 2128 | WebNavigationPolicy policy) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2129 | // Check to make sure we aren't overloading on popups. |
| 2130 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 2131 | return NULL; |
| 2132 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2133 | ViewHostMsg_CreateWindow_Params params; |
| 2134 | params.opener_id = routing_id_; |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2135 | params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame^] | 2136 | if (GetContentClient()->renderer()->AllowPopup()) |
| 2137 | params.user_gesture = true; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2138 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 2139 | params.session_storage_namespace_id = session_storage_namespace_id_; |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 2140 | if (frame_name != "_blank") |
| 2141 | params.frame_name = frame_name; |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 2142 | params.opener_frame_id = creator->identifier(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2143 | params.opener_url = creator->document().url(); |
[email protected] | 7f48b71 | 2013-01-25 01:48:30 | [diff] [blame] | 2144 | GURL security_url(creator->document().securityOrigin().toString().utf8()); |
| 2145 | if (!security_url.is_valid()) |
| 2146 | security_url = GURL(); |
| 2147 | params.opener_security_origin = security_url; |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2148 | params.opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
| 2149 | params.disposition = NavigationPolicyToDisposition(policy); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 2150 | if (!request.isNull()) { |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 2151 | params.target_url = request.url(); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 2152 | params.referrer = GetReferrerFromRequest(creator, request); |
| 2153 | } |
[email protected] | 453c1b2 | 2013-07-23 09:31:48 | [diff] [blame] | 2154 | params.features = features; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2155 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2156 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2157 | int32 main_frame_routing_id = MSG_ROUTING_NONE; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2158 | int32 surface_id = 0; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 2159 | int64 cloned_session_storage_namespace_id; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2160 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 2161 | RenderThread::Get()->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2162 | new ViewHostMsg_CreateWindow(params, |
| 2163 | &routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2164 | &main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2165 | &surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2166 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2167 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2168 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2169 | |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2170 | WebUserGestureIndicator::consumeUserGesture(); |
[email protected] | c5926242 | 2012-11-30 21:20:52 | [diff] [blame] | 2171 | |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 2172 | WebPreferences transferred_preferences = webkit_preferences_; |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 2173 | |
| 2174 | // Unless accelerated compositing has been explicitly disabled from the |
| 2175 | // command line (e.g. via the blacklist or about:flags) re-enable it for |
| 2176 | // new views that get spawned by this view. This gets around the issue that |
| 2177 | // background extension pages disable accelerated compositing via web prefs |
| 2178 | // but can themselves spawn a visible render view which should be allowed |
| 2179 | // use gpu acceleration. |
| 2180 | if (!webkit_preferences_.accelerated_compositing_enabled) { |
| 2181 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 2182 | if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing)) |
| 2183 | transferred_preferences.accelerated_compositing_enabled = true; |
| 2184 | } |
| 2185 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2186 | RenderViewImpl* view = RenderViewImpl::Create( |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2187 | routing_id_, |
| 2188 | renderer_preferences_, |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 2189 | transferred_preferences, |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2190 | shared_popup_counter_.get(), |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2191 | routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2192 | main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2193 | surface_id, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2194 | cloned_session_storage_namespace_id, |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 2195 | string16(), // WebCore will take care of setting the correct name. |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2196 | true, |
| 2197 | false, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 2198 | 1, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 2199 | screen_info_, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 2200 | accessibility_mode_, |
| 2201 | allow_partial_swap_); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2202 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2203 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2204 | // Record whether the creator frame is trying to suppress the opener field. |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2205 | view->opener_suppressed_ = params.opener_suppressed; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2206 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2207 | // Copy over the alternate error page URL so we can have alt error pages in |
| 2208 | // the new render view (we don't need the browser to send the URL back down). |
| 2209 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 2210 | |
| 2211 | return view->webview(); |
| 2212 | } |
| 2213 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2214 | WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 2215 | RenderWidget* widget = |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 2216 | RenderWidget::Create(routing_id_, popup_type, screen_info_); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2217 | return widget->webwidget(); |
| 2218 | } |
| 2219 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2220 | WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu( |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2221 | const WebPopupMenuInfo& popup_menu_info, |
| 2222 | WebExternalPopupMenuClient* popup_menu_client) { |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 2223 | // An IPC message is sent to the browser to build and display the actual |
| 2224 | // popup. The user could have time to click a different select by the time |
| 2225 | // the popup is shown. In that case external_popup_menu_ is non NULL. |
| 2226 | // By returning NULL in that case, we instruct WebKit to cancel that new |
| 2227 | // popup. So from the user perspective, only the first one will show, and |
| 2228 | // will have to close the first one before another one can be shown. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 2229 | if (external_popup_menu_) |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 2230 | return NULL; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2231 | external_popup_menu_.reset( |
| 2232 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
| 2233 | return external_popup_menu_.get(); |
| 2234 | } |
| 2235 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2236 | RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer( |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 2237 | webkit::ppapi::PluginInstance* plugin) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 2238 | #if defined(ENABLE_PLUGINS) |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 2239 | GURL active_url; |
[email protected] | d91ddfc | 2011-04-07 18:33:42 | [diff] [blame] | 2240 | if (webview() && webview()->mainFrame()) |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2241 | active_url = GURL(webview()->mainFrame()->document().url()); |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 2242 | RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create( |
[email protected] | bee6eb7 | 2012-07-26 03:47:32 | [diff] [blame] | 2243 | routing_id_, plugin, active_url, screen_info_); |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 2244 | widget->show(WebKit::WebNavigationPolicyIgnore); |
[email protected] | 92abcb83 | 2011-01-06 20:39:56 | [diff] [blame] | 2245 | return widget; |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 2246 | #else // defined(ENABLE_PLUGINS) |
| 2247 | NOTREACHED() << "CreatePepperFullscreenContainer: plugins disabled"; |
| 2248 | return NULL; |
| 2249 | #endif |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 2250 | } |
| 2251 | |
[email protected] | 2336748 | 2013-06-27 21:06:54 | [diff] [blame] | 2252 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() { |
[email protected] | b928936b | 2012-04-13 01:16:16 | [diff] [blame] | 2253 | CHECK(session_storage_namespace_id_ != |
| 2254 | dom_storage::kInvalidSessionStorageNamespaceId); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 2255 | return new WebStorageNamespaceImpl(session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 2256 | } |
| 2257 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2258 | void RenderViewImpl::didAddMessageToConsole( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2259 | const WebConsoleMessage& message, const WebString& source_name, |
| 2260 | unsigned source_line) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2261 | logging::LogSeverity log_severity = logging::LOG_VERBOSE; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 2262 | switch (message.level) { |
[email protected] | 80ac894 | 2013-01-30 22:53:22 | [diff] [blame] | 2263 | case WebConsoleMessage::LevelDebug: |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2264 | log_severity = logging::LOG_VERBOSE; |
| 2265 | break; |
| 2266 | case WebConsoleMessage::LevelLog: |
| 2267 | log_severity = logging::LOG_INFO; |
| 2268 | break; |
| 2269 | case WebConsoleMessage::LevelWarning: |
| 2270 | log_severity = logging::LOG_WARNING; |
| 2271 | break; |
| 2272 | case WebConsoleMessage::LevelError: |
| 2273 | log_severity = logging::LOG_ERROR; |
| 2274 | break; |
| 2275 | default: |
| 2276 | NOTREACHED(); |
| 2277 | } |
| 2278 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2279 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2280 | static_cast<int32>(log_severity), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 2281 | message.text, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2282 | static_cast<int32>(source_line), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 2283 | source_name)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2284 | } |
| 2285 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2286 | void RenderViewImpl::printPage(WebFrame* frame) { |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 2287 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2288 | PrintPage(frame, handling_input_event_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2289 | } |
| 2290 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2291 | WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2292 | return notification_provider_; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 2293 | } |
| 2294 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2295 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 2296 | const WebString& path, |
| 2297 | WebFileChooserCompletion* chooser_completion) { |
| 2298 | int id = enumeration_completion_id_++; |
| 2299 | enumeration_completions_[id] = chooser_completion; |
| 2300 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 2301 | routing_id_, |
| 2302 | id, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 2303 | base::FilePath::FromUTF16Unsafe(path))); |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 2304 | } |
| 2305 | |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 2306 | void RenderViewImpl::initializeHelperPluginWebFrame( |
| 2307 | WebKit::WebHelperPlugin* plugin) { |
[email protected] | 2f61bdd | 2013-07-02 18:38:47 | [diff] [blame] | 2308 | plugin->initializeFrame(main_render_frame_.get()); |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 2309 | } |
| 2310 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2311 | void RenderViewImpl::didStartLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2312 | if (is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 2313 | DVLOG(1) << "didStartLoading called while loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2314 | return; |
| 2315 | } |
| 2316 | |
| 2317 | is_loading_ = true; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2318 | |
| 2319 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 2320 | |
| 2321 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2322 | } |
| 2323 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2324 | void RenderViewImpl::didStopLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2325 | if (!is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 2326 | DVLOG(1) << "DidStopLoading called while not loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2327 | return; |
| 2328 | } |
| 2329 | |
| 2330 | is_loading_ = false; |
| 2331 | |
| 2332 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 2333 | // when done loading. This currently isn't an issue as the favicon is only |
| 2334 | // displayed when done loading. Ideally we would send notification when |
| 2335 | // finished parsing the head, but webkit doesn't support that yet. |
| 2336 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2337 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 2338 | |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2339 | if (load_progress_tracker_ != NULL) |
| 2340 | load_progress_tracker_->DidStopLoading(); |
| 2341 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 2342 | DidStopLoadingIcons(); |
| 2343 | |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 2344 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2345 | } |
| 2346 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2347 | void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, |
| 2348 | double load_progress) { |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2349 | if (load_progress_tracker_ != NULL) |
| 2350 | load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); |
| 2351 | } |
| 2352 | |
[email protected] | 550b0c9 | 2013-02-04 05:09:15 | [diff] [blame] | 2353 | void RenderViewImpl::didCancelCompositionOnSelectionChange() { |
| 2354 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 2355 | } |
| 2356 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2357 | void RenderViewImpl::didChangeSelection(bool is_empty_selection) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 2358 | if (!handling_input_event_ && !handling_select_range_) |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 2359 | return; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 2360 | |
[email protected] | fca5202 | 2012-04-03 17:00:50 | [diff] [blame] | 2361 | if (is_empty_selection) |
| 2362 | selection_text_.clear(); |
| 2363 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 2364 | SyncSelectionIfRequired(); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2365 | UpdateTextInputType(); |
| 2366 | #if defined(OS_ANDROID) |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 2367 | UpdateTextInputState(DO_NOT_SHOW_IME); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2368 | #endif |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2369 | } |
| 2370 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2371 | void RenderViewImpl::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 2372 | const std::string& name = UTF16ToUTF8(command_name); |
| 2373 | if (StartsWithASCII(name, "Move", true) || |
| 2374 | StartsWithASCII(name, "Insert", true) || |
| 2375 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2376 | return; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2377 | RenderThreadImpl::current()->RecordUserMetrics(name); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2378 | } |
| 2379 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2380 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2381 | if (edit_commands_.empty()) |
| 2382 | return false; |
| 2383 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2384 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2385 | if (!frame) |
| 2386 | return false; |
| 2387 | |
| 2388 | EditCommands::iterator it = edit_commands_.begin(); |
| 2389 | EditCommands::iterator end = edit_commands_.end(); |
| 2390 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2391 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2392 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 2393 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 2394 | // key (but it's the exception). Once one edit command is not executed, it |
| 2395 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2396 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 2397 | WebString::fromUTF8(it->value), |
| 2398 | GetFocusedNode())) |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2399 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2400 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2401 | } |
| 2402 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2403 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2404 | } |
| 2405 | |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2406 | WebKit::WebColorChooser* RenderViewImpl::createColorChooser( |
| 2407 | WebKit::WebColorChooserClient* client, |
| 2408 | const WebKit::WebColor& initial_color) { |
| 2409 | RendererWebColorChooserImpl* color_chooser = |
| 2410 | new RendererWebColorChooserImpl(this, client); |
| 2411 | color_chooser->Open(static_cast<SkColor>(initial_color)); |
| 2412 | return color_chooser; |
| 2413 | } |
| 2414 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2415 | bool RenderViewImpl::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 2416 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2417 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 2418 | // Do not open the file dialog in a hidden RenderView. |
| 2419 | if (is_hidden()) |
| 2420 | return false; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2421 | FileChooserParams ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2422 | if (params.directory) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2423 | ipc_params.mode = FileChooserParams::OpenFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2424 | else if (params.multiSelect) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2425 | ipc_params.mode = FileChooserParams::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame] | 2426 | else if (params.saveAs) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2427 | ipc_params.mode = FileChooserParams::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2428 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2429 | ipc_params.mode = FileChooserParams::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2430 | ipc_params.title = params.title; |
| 2431 | ipc_params.default_file_name = |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 2432 | base::FilePath::FromUTF16Unsafe(params.initialValue); |
[email protected] | f9a4c41a | 2012-05-30 00:05:32 | [diff] [blame] | 2433 | ipc_params.accept_types.reserve(params.acceptTypes.size()); |
| 2434 | for (size_t i = 0; i < params.acceptTypes.size(); ++i) |
| 2435 | ipc_params.accept_types.push_back(params.acceptTypes[i]); |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 2436 | #if defined(OS_ANDROID) |
[email protected] | b7b4beb | 2013-07-09 14:06:50 | [diff] [blame] | 2437 | ipc_params.capture = params.useMediaCapture; |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 2438 | #endif |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2439 | |
| 2440 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2441 | } |
| 2442 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2443 | void RenderViewImpl::runModalAlertDialog(WebFrame* frame, |
| 2444 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2445 | RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2446 | message, |
| 2447 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2448 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2449 | NULL); |
| 2450 | } |
| 2451 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2452 | bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame, |
| 2453 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2454 | return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2455 | message, |
| 2456 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2457 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2458 | NULL); |
| 2459 | } |
| 2460 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2461 | bool RenderViewImpl::runModalPromptDialog(WebFrame* frame, |
| 2462 | const WebString& message, |
| 2463 | const WebString& default_value, |
| 2464 | WebString* actual_value) { |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2465 | string16 result; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2466 | bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2467 | message, |
| 2468 | default_value, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2469 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2470 | &result); |
| 2471 | if (ok) |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2472 | actual_value->assign(result); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2473 | return ok; |
| 2474 | } |
| 2475 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2476 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2477 | WebFrame* frame, const WebString& message) { |
[email protected] | ab533826b | 2013-05-10 23:54:56 | [diff] [blame] | 2478 | bool is_reload = false; |
| 2479 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2480 | if (ds) |
| 2481 | is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload); |
| 2482 | return runModalBeforeUnloadDialog(frame, is_reload, message); |
| 2483 | } |
| 2484 | |
| 2485 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
| 2486 | WebFrame* frame, bool is_reload, const WebString& message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2487 | // If we are swapping out, we have already run the beforeunload handler. |
| 2488 | // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 2489 | // at all, to avoid running it twice. |
| 2490 | if (is_swapped_out_) |
| 2491 | return true; |
| 2492 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2493 | bool success = false; |
| 2494 | // This is an ignored return value, but is included so we can accept the same |
| 2495 | // response as RunJavaScriptMessage. |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2496 | string16 ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2497 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2498 | routing_id_, frame->document().url(), message, is_reload, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2499 | &success, &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2500 | return success; |
| 2501 | } |
| 2502 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2503 | void RenderViewImpl::showContextMenu( |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2504 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | 3175fea | 2013-05-16 10:57:48 | [diff] [blame] | 2505 | ContextMenuParams params = ContextMenuParamsBuilder::Build(data); |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 2506 | params.source_type = context_menu_source_type_; |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 2507 | if (context_menu_source_type_ == ui::MENU_SOURCE_TOUCH_EDIT_MENU) { |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 2508 | params.x = touch_editing_context_menu_location_.x(); |
| 2509 | params.y = touch_editing_context_menu_location_.y(); |
| 2510 | } |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2511 | |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2512 | // Plugins, e.g. PDF, don't currently update the render view when their |
| 2513 | // selected text changes, but the context menu params do contain the updated |
| 2514 | // selection. If that's the case, update the render view's state just prior |
| 2515 | // to showing the context menu. |
| 2516 | // TODO(asvitkine): http://crbug.com/152432 |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 2517 | if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_, |
| 2518 | selection_text_offset_, |
| 2519 | selection_range_, |
| 2520 | params)) { |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2521 | selection_text_ = params.selection_text; |
| 2522 | // TODO(asvitkine): Text offset and range is not available in this case. |
| 2523 | selection_text_offset_ = 0; |
| 2524 | selection_range_ = ui::Range(0, selection_text_.length()); |
| 2525 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 2526 | selection_text_, |
| 2527 | selection_text_offset_, |
| 2528 | selection_range_)); |
| 2529 | } |
| 2530 | |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2531 | // frame is NULL if invoked by BlockedPlugin. |
| 2532 | if (frame) |
| 2533 | params.frame_id = frame->identifier(); |
| 2534 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2535 | // Serializing a GURL longer than kMaxURLChars will fail, so don't do |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2536 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2537 | // in the context menu. |
| 2538 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2539 | // data encoded images. We should have a way to save them. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2540 | if (params.src_url.spec().size() > kMaxURLChars) |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2541 | params.src_url = GURL(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 2542 | context_menu_node_ = data.node; |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2543 | |
| 2544 | #if defined(OS_ANDROID) |
| 2545 | gfx::Rect start_rect; |
| 2546 | gfx::Rect end_rect; |
| 2547 | GetSelectionBounds(&start_rect, &end_rect); |
[email protected] | 326a234 | 2013-02-15 15:47:51 | [diff] [blame] | 2548 | params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom()); |
| 2549 | params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom()); |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2550 | #endif |
| 2551 | |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2552 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 2553 | |
| 2554 | FOR_EACH_OBSERVER( |
| 2555 | RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2556 | } |
| 2557 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2558 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2559 | } |
| 2560 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2561 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 2562 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2563 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2564 | if (latest_url == target_url_) |
| 2565 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2566 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2567 | // Tell the browser to display a destination link. |
| 2568 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2569 | target_url_status_ == TARGET_PENDING) { |
| 2570 | // If we have a request in-flight, save the URL to be sent when we |
| 2571 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2572 | // any existing pending sends. |
| 2573 | pending_target_url_ = latest_url; |
| 2574 | target_url_status_ = TARGET_PENDING; |
| 2575 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2576 | // URLs larger than |kMaxURLChars| cannot be sent through IPC - |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2577 | // see |ParamTraits<GURL>|. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2578 | if (latest_url.possibly_invalid_spec().size() > kMaxURLChars) |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2579 | latest_url = GURL(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2580 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2581 | target_url_ = latest_url; |
| 2582 | target_url_status_ = TARGET_INFLIGHT; |
| 2583 | } |
| 2584 | } |
| 2585 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 2586 | gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect( |
| 2587 | const gfx::RectF& rect) const { |
| 2588 | gfx::RectF window_rect = rect; |
| 2589 | window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor()); |
| 2590 | return window_rect; |
| 2591 | } |
| 2592 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2593 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
[email protected] | a183fb8 | 2012-12-14 04:46:22 | [diff] [blame] | 2594 | // No need to update state if no page has committed yet. |
| 2595 | if (page_id_ == -1) |
| 2596 | return; |
| 2597 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2598 | int delay; |
| 2599 | if (send_content_state_immediately_) |
| 2600 | delay = 0; |
| 2601 | else if (is_hidden()) |
| 2602 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2603 | else |
| 2604 | delay = kDelaySecondsForContentStateSync; |
| 2605 | |
| 2606 | if (nav_state_sync_timer_.IsRunning()) { |
| 2607 | // The timer is already running. If the delay of the timer maches the amount |
| 2608 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2609 | // gets started with the right delay. |
| 2610 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2611 | return; |
| 2612 | nav_state_sync_timer_.Stop(); |
| 2613 | } |
| 2614 | |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 2615 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2616 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2617 | } |
| 2618 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2619 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2620 | mouse_over_url_ = GURL(url); |
| 2621 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2622 | } |
| 2623 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2624 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2625 | focus_url_ = GURL(url); |
| 2626 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2627 | } |
| 2628 | |
[email protected] | 0407e42 | 2012-05-18 19:51:25 | [diff] [blame] | 2629 | void RenderViewImpl::startDragging(WebFrame* frame, |
| 2630 | const WebDragData& data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2631 | WebDragOperationsMask mask, |
| 2632 | const WebImage& image, |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2633 | const WebPoint& webImageOffset) { |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 2634 | DropData drop_data(DropDataBuilder::Build(data)); |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2635 | drop_data.referrer_policy = frame->document().referrerPolicy(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2636 | gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2637 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2638 | drop_data, |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2639 | mask, |
[email protected] | 97612707 | 2012-05-10 20:08:11 | [diff] [blame] | 2640 | image.getSkBitmap(), |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 2641 | imageOffset, |
| 2642 | possible_drag_event_info_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2643 | } |
| 2644 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2645 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2646 | return renderer_preferences_.can_accept_load_drops; |
| 2647 | } |
| 2648 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2649 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2650 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2651 | } |
| 2652 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2653 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2654 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2655 | } |
| 2656 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2657 | void RenderViewImpl::focusedNodeChanged(const WebNode& node) { |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 2658 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 2659 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 2660 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node)); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2661 | } |
| 2662 | |
[email protected] | 572a6ca | 2012-10-11 19:38:01 | [diff] [blame] | 2663 | void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
| 2664 | Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
| 2665 | } |
| 2666 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 2667 | void RenderViewImpl::didUpdateLayout() { |
| 2668 | // We don't always want to set up a timer, only if we've been put in that |
| 2669 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 2670 | // message. |
| 2671 | if (!send_preferred_size_changes_ || !webview()) |
| 2672 | return; |
| 2673 | |
| 2674 | if (check_preferred_size_timer_.IsRunning()) |
| 2675 | return; |
| 2676 | check_preferred_size_timer_.Start(FROM_HERE, |
| 2677 | TimeDelta::FromMilliseconds(0), this, |
| 2678 | &RenderViewImpl::CheckPreferredSize); |
| 2679 | } |
| 2680 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2681 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2682 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2683 | } |
| 2684 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2685 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2686 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2687 | } |
| 2688 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2689 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2690 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2691 | } |
| 2692 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2693 | void RenderViewImpl::postAccessibilityNotification( |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2694 | const WebAccessibilityObject& obj, |
| 2695 | WebAccessibilityNotification notification) { |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2696 | if (renderer_accessibility_) { |
| 2697 | renderer_accessibility_->HandleWebAccessibilityNotification( |
| 2698 | obj, notification); |
| 2699 | } |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2700 | } |
| 2701 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2702 | void RenderViewImpl::didUpdateInspectorSetting(const WebString& key, |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2703 | const WebString& value) { |
| 2704 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2705 | key.utf8(), |
| 2706 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2707 | } |
| 2708 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2709 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2710 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2711 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2712 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2713 | // we won't have to test for user gesture anymore and we can |
| 2714 | // move that code back to render_widget.cc |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2715 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 2716 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 2717 | Send(new ViewHostMsg_Focus(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2718 | } |
| 2719 | } |
| 2720 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2721 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2722 | // TODO(jcivelli): see TODO above in didFocus(). |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2723 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 2724 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 2725 | Send(new ViewHostMsg_Blur(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2726 | } |
| 2727 | } |
| 2728 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2729 | // We are supposed to get a single call to Show for a newly created RenderView |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2730 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2731 | // point to dispatch the ShowView message. |
| 2732 | // |
| 2733 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 2734 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2735 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2736 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2737 | if (did_show_) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2738 | // When supports_multiple_windows is disabled, popups are reusing |
| 2739 | // the same view. In some scenarios, this makes WebKit to call show() twice. |
[email protected] | c9edabd | 2013-05-23 13:56:24 | [diff] [blame] | 2740 | if (webkit_preferences_.supports_multiple_windows) |
| 2741 | NOTREACHED() << "received extraneous Show call"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2742 | return; |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2743 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2744 | did_show_ = true; |
| 2745 | |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2746 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2747 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2748 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2749 | if (!opened_by_user_gesture_) { |
| 2750 | // We exempt background tabs for compat with older versions of Chrome. |
| 2751 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2752 | // we probably don't need this check. |
| 2753 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2754 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2755 | } |
| 2756 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2757 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2758 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2759 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2760 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2761 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2762 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2763 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2764 | } |
| 2765 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2766 | void RenderViewImpl::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2767 | DCHECK(did_show_) << "should already have shown the view"; |
| 2768 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2769 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2770 | // showModalDialog to function properly. |
| 2771 | // |
| 2772 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2773 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2774 | // handed manner. |
| 2775 | // |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2776 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2777 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2778 | |
[email protected] | 08a1c810 | 2012-05-11 23:14:26 | [diff] [blame] | 2779 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal( |
| 2780 | routing_id_, opener_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2781 | } |
| 2782 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2783 | bool RenderViewImpl::enterFullScreen() { |
| 2784 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 2785 | return true; |
| 2786 | } |
| 2787 | |
| 2788 | void RenderViewImpl::exitFullScreen() { |
| 2789 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 2790 | } |
| 2791 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 2792 | bool RenderViewImpl::requestPointerLock() { |
| 2793 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2794 | } |
| 2795 | |
| 2796 | void RenderViewImpl::requestPointerUnlock() { |
| 2797 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2798 | } |
| 2799 | |
| 2800 | bool RenderViewImpl::isPointerLocked() { |
| 2801 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2802 | webwidget_mouse_lock_target_.get()); |
| 2803 | } |
| 2804 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2805 | void RenderViewImpl::didActivateCompositor(int input_handler_identifier) { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 2806 | #if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003 |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 2807 | InputHandlerManager* input_handler_manager = |
| 2808 | RenderThreadImpl::current()->input_handler_manager(); |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 2809 | if (input_handler_manager) { |
| 2810 | input_handler_manager->AddInputHandler( |
| 2811 | routing_id_, |
| 2812 | compositor_->GetInputHandler(), |
| 2813 | AsWeakPtr()); |
| 2814 | } |
[email protected] | 70cff2750 | 2013-01-17 09:16:49 | [diff] [blame] | 2815 | #endif |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2816 | |
| 2817 | RenderWidget::didActivateCompositor(input_handler_identifier); |
| 2818 | } |
| 2819 | |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2820 | void RenderViewImpl::didHandleGestureEvent( |
| 2821 | const WebGestureEvent& event, |
| 2822 | bool event_cancelled) { |
| 2823 | RenderWidget::didHandleGestureEvent(event, event_cancelled); |
| 2824 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2825 | DidHandleGestureEvent(event)); |
| 2826 | } |
| 2827 | |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 2828 | void RenderViewImpl::initializeLayerTreeView() { |
| 2829 | RenderWidget::initializeLayerTreeView(); |
| 2830 | RenderWidgetCompositor* rwc = compositor(); |
| 2831 | if (!rwc || !webview() || !webview()->devToolsAgent()) |
| 2832 | return; |
| 2833 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 2834 | } |
| 2835 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2836 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2837 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 2838 | WebKit::WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
| 2839 | const WebPluginParams& params) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 2840 | NOTREACHED(); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 2841 | return NULL; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2842 | } |
| 2843 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2844 | WebSharedWorker* RenderViewImpl::createSharedWorker( |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2845 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2846 | unsigned long long document_id) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 2847 | NOTREACHED(); |
| 2848 | return NULL; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2849 | } |
| 2850 | |
[email protected] | 97b150db | 2012-08-16 18:26:02 | [diff] [blame] | 2851 | WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
| 2852 | WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) { |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 2853 | FOR_EACH_OBSERVER( |
| 2854 | RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client)); |
[email protected] | 7198402c | 2011-04-11 12:15:17 | [diff] [blame] | 2855 | |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2856 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | 75abf38 | 2013-07-09 08:14:19 | [diff] [blame] | 2857 | #if defined(ENABLE_WEBRTC) |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 2858 | EnsureMediaStreamClient(); |
[email protected] | 75abf38 | 2013-07-09 08:14:19 | [diff] [blame] | 2859 | #if !defined(GOOGLE_TV) |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 2860 | if (media_stream_client_->IsMediaStream(url)) { |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 2861 | #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
| 2862 | bool found_neon = |
| 2863 | (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; |
| 2864 | UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon); |
| 2865 | #endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 2866 | return new WebMediaPlayerMS( |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 2867 | frame, client, AsWeakPtr(), media_stream_client_, new RenderMediaLog()); |
[email protected] | d05e216 | 2012-11-16 22:21:46 | [diff] [blame] | 2868 | } |
[email protected] | 75abf38 | 2013-07-09 08:14:19 | [diff] [blame] | 2869 | #endif // !defined(GOOGLE_TV) |
| 2870 | #endif // defined(ENABLE_WEBRTC) |
[email protected] | d05e216 | 2012-11-16 22:21:46 | [diff] [blame] | 2871 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2872 | #if defined(OS_ANDROID) |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2873 | GpuChannelHost* gpu_channel_host = |
| 2874 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2875 | CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2876 | if (!gpu_channel_host) { |
| 2877 | LOG(ERROR) << "Failed to establish GPU channel for media player"; |
| 2878 | return NULL; |
| 2879 | } |
| 2880 | |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 2881 | scoped_refptr<cc::ContextProvider> context_provider = |
| 2882 | RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); |
[email protected] | 13914c9 | 2013-06-13 22:42:42 | [diff] [blame] | 2883 | if (!context_provider.get()) { |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 2884 | LOG(ERROR) << "Failed to get context3d for media player"; |
| 2885 | return NULL; |
| 2886 | } |
| 2887 | |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2888 | if (!media_player_proxy_) { |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 2889 | media_player_proxy_ = new WebMediaPlayerProxyAndroid( |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2890 | this, media_player_manager_.get()); |
| 2891 | } |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 2892 | scoped_ptr<WebMediaPlayerAndroid> web_media_player_android( |
| 2893 | new WebMediaPlayerAndroid( |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 2894 | frame, |
| 2895 | client, |
[email protected] | 9aff54d | 2013-06-18 18:38:50 | [diff] [blame] | 2896 | AsWeakPtr(), |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 2897 | media_player_manager_.get(), |
| 2898 | media_player_proxy_, |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 2899 | new StreamTextureFactory( |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 2900 | context_provider->Context3d(), gpu_channel_host, routing_id_), |
| 2901 | new RenderMediaLog())); |
| 2902 | #if defined(ENABLE_WEBRTC) && defined(GOOGLE_TV) |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 2903 | if (media_stream_client_->IsMediaStream(url)) { |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 2904 | RTCVideoDecoderFactoryTv* factory = RenderThreadImpl::current() |
| 2905 | ->GetMediaStreamDependencyFactory()->decoder_factory_tv(); |
[email protected] | 75abf38 | 2013-07-09 08:14:19 | [diff] [blame] | 2906 | // |media_stream_client| and |factory| outlives |web_media_player_android|. |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 2907 | if (!factory->AcquireDemuxer() || |
| 2908 | !web_media_player_android->InjectMediaStream( |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 2909 | media_stream_client_, |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 2910 | factory, |
| 2911 | base::Bind( |
| 2912 | base::IgnoreResult(&RTCVideoDecoderFactoryTv::ReleaseDemuxer), |
| 2913 | base::Unretained(factory)))) { |
| 2914 | LOG(ERROR) << "Failed to inject media stream."; |
| 2915 | return NULL; |
| 2916 | } |
| 2917 | } |
| 2918 | #endif // defined(ENABLE_WEBRTC) && defined(GOOGLE_TV) |
| 2919 | return web_media_player_android.release(); |
| 2920 | #endif // defined(OS_ANDROID) |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2921 | |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 2922 | scoped_refptr<media::AudioRendererSink> sink; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2923 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
[email protected] | 17c4ce62f | 2013-05-03 19:54:02 | [diff] [blame] | 2924 | sink = RenderThreadImpl::current()->GetAudioRendererMixerManager()-> |
| 2925 | CreateInput(routing_id_); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2926 | DVLOG(1) << "Using AudioRendererMixerManager-provided sink: " << sink.get(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2927 | } |
| 2928 | |
[email protected] | b9a407e | 2013-07-24 07:30:02 | [diff] [blame] | 2929 | scoped_refptr<media::GpuVideoDecoderFactories> gpu_factories = |
[email protected] | 86e3a70 | 2013-07-24 12:22:53 | [diff] [blame] | 2930 | RenderThreadImpl::current()->GetGpuFactories( |
| 2931 | RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy()); |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2932 | |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 2933 | WebMediaPlayerParams params( |
[email protected] | c1330c8 | 2013-06-06 02:23:25 | [diff] [blame] | 2934 | RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(), |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 2935 | base::Bind(&ContentRendererClient::DeferMediaLoad, |
| 2936 | base::Unretained(GetContentClient()->renderer()), |
| 2937 | static_cast<RenderView*>(this)), |
| 2938 | sink, |
| 2939 | gpu_factories, |
| 2940 | new RenderMediaLog()); |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 2941 | return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2942 | } |
| 2943 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2944 | WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost( |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2945 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 2946 | NOTREACHED(); |
| 2947 | return NULL; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2948 | } |
| 2949 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2950 | WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { |
[email protected] | 8ff18107 | 2010-11-29 17:09:38 | [diff] [blame] | 2951 | return &cookie_jar_; |
| 2952 | } |
| 2953 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 2954 | void RenderViewImpl::didAccessInitialDocument(WebFrame* frame) { |
| 2955 | // Notify the browser process that it is no longer safe to show the pending |
| 2956 | // URL of the main frame, since a URL spoof is now possible. |
| 2957 | if (!frame->parent() && page_id_ == -1) |
| 2958 | Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_)); |
| 2959 | } |
| 2960 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 2961 | void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 2962 | NOTREACHED(); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 2963 | } |
| 2964 | |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 2965 | void RenderViewImpl::didDisownOpener(WebKit::WebFrame* frame) { |
[email protected] | 29ece2e | 2013-04-03 04:53:52 | [diff] [blame] | 2966 | // We only need to notify the browser if the active, top-level frame clears |
| 2967 | // its opener. We can ignore cases where a swapped out frame clears its |
| 2968 | // opener after hearing about it from the browser, and the browser does not |
| 2969 | // (yet) care about subframe openers. |
| 2970 | if (is_swapped_out_ || frame->parent()) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 2971 | return; |
| 2972 | |
| 2973 | // Notify WebContents and all its swapped out RenderViews. |
| 2974 | Send(new ViewHostMsg_DidDisownOpener(routing_id_)); |
| 2975 | } |
| 2976 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2977 | void RenderViewImpl::frameDetached(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2978 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2979 | } |
| 2980 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2981 | void RenderViewImpl::willClose(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2982 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2983 | } |
| 2984 | |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 2985 | void RenderViewImpl::didChangeName(WebFrame* frame, |
| 2986 | const WebString& name) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 2987 | NOTREACHED(); |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 2988 | } |
| 2989 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2990 | void RenderViewImpl::loadURLExternally( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2991 | WebFrame* frame, const WebURLRequest& request, |
| 2992 | WebNavigationPolicy policy) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 2993 | NOTREACHED(); |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2994 | } |
| 2995 | |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2996 | void RenderViewImpl::Repaint(const gfx::Size& size) { |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 2997 | OnRepaint(size); |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2998 | } |
| 2999 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 3000 | void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name, |
| 3001 | const std::string& value) { |
| 3002 | EditCommands edit_commands; |
| 3003 | edit_commands.push_back(EditCommand(name, value)); |
| 3004 | OnSetEditCommandsForNextKeyEvent(edit_commands); |
| 3005 | } |
| 3006 | |
| 3007 | void RenderViewImpl::ClearEditCommands() { |
| 3008 | edit_commands_.clear(); |
| 3009 | } |
| 3010 | |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 3011 | SSLStatus RenderViewImpl::GetSSLStatusOfFrame(WebKit::WebFrame* frame) const { |
[email protected] | 83c0abca | 2013-07-23 20:09:42 | [diff] [blame] | 3012 | std::string security_info; |
| 3013 | if (frame && frame->dataSource()) |
| 3014 | security_info = frame->dataSource()->response().securityInfo(); |
| 3015 | |
| 3016 | SSLStatus ssl_status; |
| 3017 | DeserializeSecurityInfo(security_info, |
| 3018 | &ssl_status.cert_id, |
| 3019 | &ssl_status.cert_status, |
| 3020 | &ssl_status.security_bits, |
| 3021 | &ssl_status.connection_status); |
| 3022 | return ssl_status; |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 3023 | } |
| 3024 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3025 | void RenderViewImpl::loadURLExternally( |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 3026 | WebFrame* frame, const WebURLRequest& request, |
| 3027 | WebNavigationPolicy policy, |
| 3028 | const WebString& suggested_name) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3029 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3030 | } |
| 3031 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3032 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3033 | WebFrame* frame, WebDataSource::ExtraData* extraData, |
| 3034 | const WebURLRequest& request, WebNavigationType type, |
| 3035 | WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 099df81cf | 2012-11-14 17:44:04 | [diff] [blame] | 3036 | if (request.url() != GURL(kSwappedOutURL) && |
| 3037 | GetContentClient()->renderer()->HandleNavigation(frame, request, type, |
| 3038 | default_policy, |
| 3039 | is_redirect)) { |
| 3040 | return WebKit::WebNavigationPolicyIgnore; |
| 3041 | } |
| 3042 | |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 3043 | Referrer referrer(GetReferrerFromRequest(frame, request)); |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3044 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3045 | if (is_swapped_out_) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3046 | if (request.url() != GURL(kSwappedOutURL)) { |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3047 | // Targeted links may try to navigate a swapped out frame. Allow the |
| 3048 | // browser process to navigate the tab instead. Note that it is also |
| 3049 | // possible for non-targeted navigations (from this view) to arrive |
| 3050 | // here just after we are swapped out. It's ok to send them to the |
| 3051 | // browser, as long as they're for the top level frame. |
| 3052 | // TODO(creis): Ensure this supports targeted form submissions when |
| 3053 | // fixing http://crbug.com/101395. |
| 3054 | if (frame->parent() == NULL) { |
| 3055 | OpenURL(frame, request.url(), referrer, default_policy); |
| 3056 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 3057 | } |
| 3058 | |
| 3059 | // We should otherwise ignore in-process iframe navigations, if they |
| 3060 | // arrive just after we are swapped out. |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 3061 | return WebKit::WebNavigationPolicyIgnore; |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3062 | } |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 3063 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3064 | // Allow kSwappedOutURL to complete. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3065 | return default_policy; |
| 3066 | } |
| 3067 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3068 | // Webkit is asking whether to navigate to a new URL. |
| 3069 | // This is fine normally, except if we're showing UI from one security |
| 3070 | // context and they're trying to navigate to a different context. |
| 3071 | const GURL& url = request.url(); |
| 3072 | |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 3073 | // A content initiated navigation may have originated from a link-click, |
| 3074 | // script, drag-n-drop operation, etc. |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3075 | bool is_content_initiated = static_cast<DocumentState*>(extraData)-> |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3076 | navigation_state()->is_content_initiated(); |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 3077 | |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3078 | // Experimental: |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 3079 | // If --enable-strict-site-isolation or --site-per-process is enabled, send |
| 3080 | // all top-level navigations to the browser to let it swap processes when |
| 3081 | // crossing site boundaries. This is currently expected to break some script |
| 3082 | // calls and navigations, such as form submissions. |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3083 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 3084 | bool force_swap_due_to_flag = |
| 3085 | command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
| 3086 | command_line.HasSwitch(switches::kSitePerProcess); |
| 3087 | if (force_swap_due_to_flag && |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3088 | !frame->parent() && (is_content_initiated || is_redirect)) { |
| 3089 | WebString origin_str = frame->document().securityOrigin().toString(); |
| 3090 | GURL frame_url(origin_str.utf8().data()); |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 3091 | // TODO(cevans): revisit whether this site check is still necessary once |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3092 | // crbug.com/101395 is fixed. |
[email protected] | ed32c21 | 2013-05-14 20:49:29 | [diff] [blame] | 3093 | bool same_domain_or_host = |
| 3094 | net::registry_controlled_domains::SameDomainOrHost( |
| 3095 | frame_url, |
| 3096 | url, |
| 3097 | net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 3098 | if (!same_domain_or_host || frame_url.scheme() != url.scheme()) { |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3099 | OpenURL(frame, url, referrer, default_policy); |
| 3100 | return WebKit::WebNavigationPolicyIgnore; |
| 3101 | } |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3102 | } |
| 3103 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3104 | // If the browser is interested, then give it a chance to look at the request. |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 3105 | if (is_content_initiated) { |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 3106 | bool is_form_post = ((type == WebKit::WebNavigationTypeFormSubmitted) || |
| 3107 | (type == WebKit::WebNavigationTypeFormResubmitted)) && |
| 3108 | EqualsASCII(request.httpMethod(), "POST"); |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3109 | bool browser_handles_request = |
| 3110 | renderer_preferences_.browser_handles_non_local_top_level_requests && |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 3111 | IsNonLocalTopLevelNavigation(url, frame, type, is_form_post); |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3112 | if (!browser_handles_request) { |
| 3113 | browser_handles_request = |
| 3114 | renderer_preferences_.browser_handles_all_top_level_requests && |
| 3115 | IsTopLevelNavigation(frame); |
| 3116 | } |
| 3117 | |
| 3118 | if (browser_handles_request) { |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 3119 | // Reset these counters as the RenderView could be reused for the next |
| 3120 | // navigation. |
| 3121 | page_id_ = -1; |
| 3122 | last_page_id_sent_to_browser_ = -1; |
| 3123 | OpenURL(frame, url, referrer, default_policy); |
| 3124 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 3125 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3126 | } |
| 3127 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3128 | // Use the frame's original request's URL rather than the document's URL for |
| 3129 | // subsequent checks. For a popup, the document's URL may become the opener |
| 3130 | // window's URL if the opener has called document.write(). |
| 3131 | // See http://crbug.com/93517. |
| 3132 | GURL old_url(frame->dataSource()->request().url()); |
| 3133 | |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3134 | // Detect when we're crossing a permission-based boundary (e.g. into or out of |
[email protected] | c39f9bf | 2011-02-12 00:43:55 | [diff] [blame] | 3135 | // an extension or app origin, leaving a WebUI page, etc). We only care about |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3136 | // top-level navigations (not iframes). But we sometimes navigate to |
| 3137 | // about:blank to clear a tab, and we want to still allow that. |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3138 | // |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3139 | // Note: this is known to break POST submissions when crossing process |
| 3140 | // boundaries until http://crbug.com/101395 is fixed. This is better for |
| 3141 | // security than loading a WebUI, extension or app page in the wrong process. |
| 3142 | // POST requests don't work because this mechanism does not preserve form |
| 3143 | // POST data. We will need to send the request's httpBody data up to the |
| 3144 | // browser process, and issue a special POST navigation in WebKit (via |
[email protected] | 8f4da8c | 2011-02-09 19:49:57 | [diff] [blame] | 3145 | // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl |
| 3146 | // for examples of how to send the httpBody data. |
[email protected] | 2762a1b | 2011-12-09 15:25:22 | [diff] [blame] | 3147 | if (!frame->parent() && is_content_initiated && |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3148 | !url.SchemeIs(chrome::kAboutScheme)) { |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3149 | bool send_referrer = false; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3150 | |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 3151 | // All navigations to or from WebUI URLs or within WebUI-enabled |
| 3152 | // RenderProcesses must be handled by the browser process so that the |
| 3153 | // correct bindings and data sources can be registered. |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3154 | // Similarly, navigations to view-source URLs or within ViewSource mode |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 3155 | // must be handled by the browser process (except for reloads - those are |
| 3156 | // safe to leave within the renderer). |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3157 | // Lastly, access to file:// URLs from non-file:// URL pages must be |
| 3158 | // handled by the browser so that ordinary renderer processes don't get |
| 3159 | // blessed with file permissions. |
| 3160 | int cumulative_bindings = RenderProcess::current()->GetEnabledBindings(); |
| 3161 | bool is_initial_navigation = page_id_ == -1; |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 3162 | bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) || |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3163 | (cumulative_bindings & BINDINGS_POLICY_WEB_UI) || |
[email protected] | dbdda540 | 2013-05-30 22:13:48 | [diff] [blame] | 3164 | url.SchemeIs(kViewSourceScheme) || |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 3165 | (frame->isViewSourceModeEnabled() && |
| 3166 | type != WebKit::WebNavigationTypeReload); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3167 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3168 | if (!should_fork && url.SchemeIs(chrome::kFileScheme)) { |
| 3169 | // Fork non-file to file opens. Check the opener URL if this is the |
| 3170 | // initial navigation in a newly opened window. |
| 3171 | GURL source_url(old_url); |
| 3172 | if (is_initial_navigation && source_url.is_empty() && frame->opener()) |
| 3173 | source_url = frame->opener()->top()->document().url(); |
| 3174 | DCHECK(!source_url.is_empty()); |
| 3175 | should_fork = !source_url.SchemeIs(chrome::kFileScheme); |
| 3176 | } |
| 3177 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3178 | if (!should_fork) { |
| 3179 | // Give the embedder a chance. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 3180 | should_fork = GetContentClient()->renderer()->ShouldFork( |
| 3181 | frame, url, request.httpMethod().utf8(), is_initial_navigation, |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 3182 | is_redirect, &send_referrer); |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | if (should_fork) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3186 | OpenURL( |
| 3187 | frame, url, send_referrer ? referrer : Referrer(), default_policy); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3188 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 3189 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 3193 | // its own process. This is done by sites like Gmail that try to open links |
| 3194 | // in new windows without script connections back to the original page. We |
| 3195 | // treat such cases as browser navigations (in which we will create a new |
| 3196 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 3197 | // |
| 3198 | // We use the following heuristic to decide whether to fork a new page in its |
| 3199 | // own process: |
| 3200 | // The parent page must open a new tab to about:blank, set the new tab's |
| 3201 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 3202 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 3203 | // |
| 3204 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 3205 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3206 | bool is_fork = |
| 3207 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 3208 | old_url == GURL(kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3209 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3210 | historyBackListCount() < 1 && |
| 3211 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3212 | // The parent page must have set the child's window.opener to null before |
| 3213 | // redirecting to the desired URL. |
| 3214 | frame->opener() == NULL && |
| 3215 | // Must be a top-level frame. |
| 3216 | frame->parent() == NULL && |
| 3217 | // Must not have issued the request from this page. |
| 3218 | is_content_initiated && |
| 3219 | // Must be targeted at the current tab. |
| 3220 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 3221 | // Must be a JavaScript navigation, which appears as "other". |
| 3222 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 3223 | |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 3224 | if (is_fork) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3225 | // Open the URL via the browser, not via WebKit. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3226 | OpenURL(frame, url, Referrer(), default_policy); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3227 | return WebKit::WebNavigationPolicyIgnore; |
| 3228 | } |
| 3229 | |
| 3230 | return default_policy; |
| 3231 | } |
| 3232 | |
[email protected] | f4f40a05 | 2013-04-19 15:28:11 | [diff] [blame] | 3233 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
| 3234 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 89bc54c6 | 2013-04-24 01:51:33 | [diff] [blame] | 3235 | WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3236 | return decidePolicyForNavigation(frame, |
| 3237 | frame->provisionalDataSource()->extraData(), |
[email protected] | 89bc54c6 | 2013-04-24 01:51:33 | [diff] [blame] | 3238 | request, type, default_policy, is_redirect); |
[email protected] | f4f40a05 | 2013-04-19 15:28:11 | [diff] [blame] | 3239 | } |
| 3240 | |
[email protected] | cd92296c | 2013-07-19 06:24:50 | [diff] [blame] | 3241 | bool RenderViewImpl::canHandleRequest( |
| 3242 | WebFrame* frame, const WebURLRequest& request) { |
| 3243 | // We allow WebKit to think that everything can be handled even though |
| 3244 | // browser-side we limit what we load. |
| 3245 | return true; |
| 3246 | } |
| 3247 | |
| 3248 | WebURLError RenderViewImpl::cannotHandleRequestError( |
| 3249 | WebFrame* frame, const WebURLRequest& request) { |
| 3250 | NOTREACHED(); // Since we said we can handle all requests. |
| 3251 | return WebURLError(); |
| 3252 | } |
| 3253 | |
| 3254 | WebURLError RenderViewImpl::cancelledError( |
| 3255 | WebFrame* frame, const WebURLRequest& request) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3256 | NOTREACHED(); |
| 3257 | return WebURLError(); |
[email protected] | cd92296c | 2013-07-19 06:24:50 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | void RenderViewImpl::unableToImplementPolicyWithError( |
| 3261 | WebFrame*, const WebURLError&) { |
| 3262 | NOTREACHED(); // Since we said we can handle all requests. |
| 3263 | } |
| 3264 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3265 | void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame, |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 3266 | const WebKit::WebFormElement& form) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3267 | NOTREACHED(); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 3268 | } |
| 3269 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3270 | void RenderViewImpl::willSubmitForm(WebFrame* frame, |
| 3271 | const WebFormElement& form) { |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 3272 | FOR_EACH_OBSERVER( |
| 3273 | RenderViewObserver, observers_, WillSubmitForm(frame, form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3274 | } |
| 3275 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3276 | void RenderViewImpl::willPerformClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3277 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 3278 | double fire_time) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3279 | // Replace any occurrences of swappedout:// with about:blank. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 3280 | const WebURL& blank_url = GURL(kAboutBlankURL); |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 3281 | |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 3282 | FOR_EACH_OBSERVER( |
| 3283 | RenderViewObserver, observers_, |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3284 | WillPerformClientRedirect(frame, |
| 3285 | from == GURL(kSwappedOutURL) ? blank_url : from, |
| 3286 | to, interval, fire_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3287 | } |
| 3288 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3289 | void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) { |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 3290 | FOR_EACH_OBSERVER( |
| 3291 | RenderViewObserver, observers_, DidCancelClientRedirect(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3292 | } |
| 3293 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3294 | void RenderViewImpl::didCompleteClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3295 | WebFrame* frame, const WebURL& from) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3296 | // Replace any occurrences of swappedout:// with about:blank. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 3297 | const WebURL& blank_url = GURL(kAboutBlankURL); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3298 | if (!frame->parent()) { |
| 3299 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3300 | // If there's no provisional data source, it's a reference fragment |
| 3301 | // navigation. |
| 3302 | completed_client_redirect_src_ = Referrer( |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3303 | from == GURL(kSwappedOutURL) ? blank_url : from, |
| 3304 | ds ? GetReferrerPolicyFromRequest(frame, ds->request()) : |
[email protected] | f36f409 | 2012-05-09 18:31:04 | [diff] [blame] | 3305 | frame->document().referrerPolicy()); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3306 | } |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 3307 | FOR_EACH_OBSERVER( |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3308 | RenderViewObserver, observers_, DidCompleteClientRedirect( |
| 3309 | frame, from == GURL(kSwappedOutURL) ? blank_url : from)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3310 | } |
| 3311 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3312 | void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3313 | bool content_initiated = !pending_navigation_params_.get(); |
| 3314 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3315 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3316 | if (!document_state) { |
| 3317 | document_state = new DocumentState; |
| 3318 | ds->setExtraData(document_state); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3319 | if (!content_initiated) |
| 3320 | PopulateDocumentStateFromPending(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3321 | } |
| 3322 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3323 | // Carry over the user agent override flag, if it exists. |
| 3324 | if (content_initiated && webview() && webview()->mainFrame() && |
| 3325 | webview()->mainFrame()->dataSource()) { |
| 3326 | DocumentState* old_document_state = |
| 3327 | DocumentState::FromDataSource(webview()->mainFrame()->dataSource()); |
| 3328 | if (old_document_state) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3329 | InternalDocumentStateData* internal_data = |
| 3330 | InternalDocumentStateData::FromDocumentState(document_state); |
| 3331 | InternalDocumentStateData* old_internal_data = |
| 3332 | InternalDocumentStateData::FromDocumentState(old_document_state); |
| 3333 | internal_data->set_is_overriding_user_agent( |
| 3334 | old_internal_data->is_overriding_user_agent()); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3335 | } |
| 3336 | } |
| 3337 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3338 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 3339 | // non-null NavigationState. |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3340 | if (content_initiated) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3341 | document_state->set_navigation_state( |
| 3342 | NavigationState::CreateContentInitiated()); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3343 | } else { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3344 | document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 3345 | pending_navigation_params_.reset(); |
| 3346 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3347 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3348 | // DocumentState::referred_by_prefetcher_ is true if we are |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3349 | // navigating from a page that used prefetching using a link on that |
| 3350 | // page. We are early enough in the request process here that we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3351 | // can still see the DocumentState of the previous page and set |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3352 | // this value appropriately. |
| 3353 | // TODO(gavinp): catch the important case of navigation in a new |
| 3354 | // renderer process. |
| 3355 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 3356 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3357 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3358 | const GURL referrer( |
| 3359 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 3360 | if (!referrer.is_empty() && |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3361 | DocumentState::FromDataSource( |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3362 | old_frame->dataSource())->was_prefetcher()) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 3363 | for (; old_frame; old_frame = old_frame->traverseNext(false)) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3364 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 3365 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3366 | document_state->set_was_referred_by_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3367 | break; |
| 3368 | } |
| 3369 | } |
| 3370 | } |
| 3371 | } |
| 3372 | } |
| 3373 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3374 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3375 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3376 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3377 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3378 | document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3379 | break; |
| 3380 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3381 | document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3382 | break; |
| 3383 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3384 | document_state->set_load_type( |
| 3385 | DocumentState::LINK_LOAD_CACHE_STALE_OK); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3386 | break; |
| 3387 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3388 | document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3389 | break; |
| 3390 | } |
| 3391 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3392 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 3393 | FOR_EACH_OBSERVER( |
| 3394 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3395 | } |
| 3396 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3397 | void RenderViewImpl::PopulateDocumentStateFromPending( |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3398 | DocumentState* document_state) { |
| 3399 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3400 | document_state->set_request_time(params.request_time); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3401 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3402 | InternalDocumentStateData* internal_data = |
| 3403 | InternalDocumentStateData::FromDocumentState(document_state); |
| 3404 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3405 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme) && |
| 3406 | params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { |
| 3407 | // We're doing a load of a page that was restored from the last session. By |
| 3408 | // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which |
| 3409 | // can result in stale data for pages that are set to expire. We explicitly |
| 3410 | // override that by setting the policy here so that as necessary we load |
| 3411 | // from the network. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3412 | internal_data->set_cache_policy_override( |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3413 | WebURLRequest::UseProtocolCachePolicy); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | if (IsReload(params)) |
| 3417 | document_state->set_load_type(DocumentState::RELOAD); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 3418 | else if (params.page_state.IsValid()) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3419 | document_state->set_load_type(DocumentState::HISTORY_LOAD); |
| 3420 | else |
| 3421 | document_state->set_load_type(DocumentState::NORMAL_LOAD); |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3422 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3423 | internal_data->set_referrer_policy(params.referrer.policy); |
| 3424 | internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent); |
| 3425 | internal_data->set_must_reset_scroll_and_scale_state( |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3426 | params.navigation_type == |
| 3427 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 3428 | document_state->set_can_load_local_resources(params.can_load_local_resources); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3429 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3430 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3431 | NavigationState* RenderViewImpl::CreateNavigationStateFromPending() { |
| 3432 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
| 3433 | NavigationState* navigation_state = NULL; |
| 3434 | |
| 3435 | // A navigation resulting from loading a javascript URL should not be treated |
| 3436 | // as a browser initiated event. Instead, we want it to look as if the page |
| 3437 | // initiated any load resulting from JS execution. |
| 3438 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
| 3439 | navigation_state = NavigationState::CreateBrowserInitiated( |
| 3440 | params.page_id, |
| 3441 | params.pending_history_list_offset, |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 3442 | params.should_clear_history_list, |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3443 | params.transition); |
| 3444 | navigation_state->set_transferred_request_child_id( |
| 3445 | params.transferred_request_child_id); |
| 3446 | navigation_state->set_transferred_request_request_id( |
| 3447 | params.transferred_request_request_id); |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 3448 | navigation_state->set_allow_download(params.allow_download); |
[email protected] | f050fde | 2013-03-21 00:40:45 | [diff] [blame] | 3449 | navigation_state->set_extra_headers(params.extra_headers); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3450 | } else { |
| 3451 | navigation_state = NavigationState::CreateContentInitiated(); |
| 3452 | } |
| 3453 | return navigation_state; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3454 | } |
| 3455 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3456 | void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) { |
| 3457 | bool enable_viewport = |
[email protected] | 06ea34a | 2012-05-07 18:52:10 | [diff] [blame] | 3458 | command_line.HasSwitch(switches::kEnableViewport); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3459 | bool enable_fixed_layout = |
| 3460 | command_line.HasSwitch(switches::kEnableFixedLayout); |
| 3461 | |
| 3462 | webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3463 | |
[email protected] | 47e932da | 2013-03-07 00:11:24 | [diff] [blame] | 3464 | // If viewport tag is enabled, then the WebKit side will take care |
| 3465 | // of setting the fixed layout size and page scale limits. |
| 3466 | if (enable_viewport) |
| 3467 | return; |
| 3468 | |
| 3469 | if (enable_fixed_layout) { |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3470 | std::string str = |
| 3471 | command_line.GetSwitchValueASCII(switches::kEnableFixedLayout); |
| 3472 | std::vector<std::string> tokens; |
| 3473 | base::SplitString(str, ',', &tokens); |
| 3474 | if (tokens.size() == 2) { |
| 3475 | int width, height; |
| 3476 | if (base::StringToInt(tokens[0], &width) && |
| 3477 | base::StringToInt(tokens[1], &height)) |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3478 | webview()->setFixedLayoutSize(WebSize(width, height)); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3479 | } |
| 3480 | } |
[email protected] | e4cd82e | 2013-04-10 15:20:38 | [diff] [blame] | 3481 | float maxPageScaleFactor = |
| 3482 | command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ; |
| 3483 | webview()->setPageScaleFactorLimits(1, maxPageScaleFactor); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3484 | } |
| 3485 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3486 | void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3487 | WebDataSource* ds = frame->provisionalDataSource(); |
[email protected] | 09c48ef5 | 2013-01-09 12:25:07 | [diff] [blame] | 3488 | |
| 3489 | // In fast/loader/stop-provisional-loads.html, we abort the load before this |
| 3490 | // callback is invoked. |
| 3491 | if (!ds) |
| 3492 | return; |
| 3493 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3494 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3495 | |
[email protected] | 890b06ca | 2012-12-13 21:07:36 | [diff] [blame] | 3496 | // We should only navigate to swappedout:// when is_swapped_out_ is true. |
| 3497 | CHECK((ds->request().url() != GURL(kSwappedOutURL)) || |
| 3498 | is_swapped_out_) << "Heard swappedout:// when not swapped out."; |
| 3499 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3500 | // Update the request time if WebKit has better knowledge of it. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3501 | if (document_state->request_time().is_null()) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3502 | double event_time = ds->triggeringEventTime(); |
| 3503 | if (event_time != 0.0) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3504 | document_state->set_request_time(Time::FromDoubleT(event_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3505 | } |
| 3506 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3507 | // Start time is only set after request time. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3508 | document_state->set_start_load_time(Time::Now()); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3509 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3510 | bool is_top_most = !frame->parent(); |
| 3511 | if (is_top_most) { |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 3512 | navigation_gesture_ = WebUserGestureIndicator::isProcessingUserGesture() ? |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 3513 | NavigationGestureUser : NavigationGestureAuto; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3514 | |
[email protected] | d06bcac | 2013-03-27 21:17:57 | [diff] [blame] | 3515 | // If the navigation is not triggered by a user gesture, e.g. by some ajax |
| 3516 | // callback, then inherit the submitted password form from the previous |
| 3517 | // state. This fixes the no password save issue for ajax login, tracked in |
| 3518 | // [http://crbug/43219]. Note that there are still some sites that this |
| 3519 | // fails for because they use some element other than a submit button to |
| 3520 | // trigger submission. |
| 3521 | if (navigation_gesture_ == NavigationGestureAuto) { |
| 3522 | DocumentState* old_document_state = DocumentState::FromDataSource( |
| 3523 | frame->dataSource()); |
| 3524 | const content::PasswordForm* old_password_form = |
| 3525 | old_document_state->password_form_data(); |
| 3526 | if (old_password_form) { |
| 3527 | document_state->set_password_form_data( |
| 3528 | make_scoped_ptr(new content::PasswordForm(*old_password_form))); |
| 3529 | } |
| 3530 | } |
| 3531 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3532 | // Make sure redirect tracking state is clear for the new load. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3533 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3534 | } else if (frame->parent()->isLoading()) { |
| 3535 | // Take note of AUTO_SUBFRAME loads here, so that we can know how to |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 3536 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3537 | document_state->navigation_state()->set_transition_type( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3538 | PAGE_TRANSITION_AUTO_SUBFRAME); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3539 | } |
| 3540 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3541 | FOR_EACH_OBSERVER( |
| 3542 | RenderViewObserver, observers_, DidStartProvisionalLoad(frame)); |
| 3543 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3544 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | d37c33e | 2012-10-12 13:35:13 | [diff] [blame] | 3545 | routing_id_, frame->identifier(), |
| 3546 | frame->parent() ? frame->parent()->identifier() : -1, |
[email protected] | 434bc9b | 2012-11-27 21:22:14 | [diff] [blame] | 3547 | is_top_most, ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3548 | } |
| 3549 | |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3550 | void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad( |
| 3551 | WebFrame* frame) { |
| 3552 | if (frame->parent()) |
| 3553 | return; |
| 3554 | // Received a redirect on the main frame. |
| 3555 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 3556 | if (!data_source) { |
| 3557 | // Should only be invoked when we have a data source. |
| 3558 | NOTREACHED(); |
| 3559 | return; |
| 3560 | } |
| 3561 | std::vector<GURL> redirects; |
| 3562 | GetRedirectChain(data_source, &redirects); |
| 3563 | if (redirects.size() >= 2) { |
| 3564 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
[email protected] | 434bc9b | 2012-11-27 21:22:14 | [diff] [blame] | 3565 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3566 | } |
| 3567 | } |
| 3568 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3569 | void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame, |
| 3570 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3571 | // Notify the browser that we failed a provisional load with an error. |
| 3572 | // |
| 3573 | // Note: It is important this notification occur before DidStopLoading so the |
| 3574 | // SSL manager can react to the provisional load failure before being |
| 3575 | // notified the load stopped. |
| 3576 | // |
| 3577 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3578 | DCHECK(ds); |
| 3579 | |
| 3580 | const WebURLRequest& failed_request = ds->request(); |
| 3581 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3582 | FOR_EACH_OBSERVER( |
| 3583 | RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error)); |
| 3584 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3585 | bool show_repost_interstitial = |
| 3586 | (error.reason == net::ERR_CACHE_MISS && |
| 3587 | EqualsASCII(failed_request.httpMethod(), "POST")); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3588 | |
| 3589 | ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 3590 | params.frame_id = frame->identifier(); |
| 3591 | params.is_main_frame = !frame->parent(); |
| 3592 | params.error_code = error.reason; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3593 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 3594 | frame, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3595 | failed_request, |
| 3596 | error, |
| 3597 | NULL, |
| 3598 | ¶ms.error_description); |
| 3599 | params.url = error.unreachableURL; |
| 3600 | params.showing_repost_interstitial = show_repost_interstitial; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3601 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3602 | routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3603 | |
| 3604 | // Don't display an error page if this is simply a cancelled load. Aside |
| 3605 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 3606 | if (error.reason == net::ERR_ABORTED) |
| 3607 | return; |
| 3608 | |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 3609 | if (RenderThreadImpl::current()->layout_test_mode()) |
[email protected] | ac7f5a0 | 2013-03-16 16:14:41 | [diff] [blame] | 3610 | return; |
| 3611 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3612 | // Make sure we never show errors in view source mode. |
| 3613 | frame->enableViewSourceMode(false); |
| 3614 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3615 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3616 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3617 | |
| 3618 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 3619 | // 'replace' load. This is necessary to avoid messing up session history. |
| 3620 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 3621 | // as session history is concerned. |
| 3622 | // |
| 3623 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 3624 | // the page id. |
| 3625 | // |
| 3626 | bool replace = |
| 3627 | navigation_state->pending_page_id() != -1 || |
[email protected] | 026aac2 | 2013-07-10 02:09:11 | [diff] [blame] | 3628 | PageTransitionCoreTypeIs(navigation_state->transition_type(), |
| 3629 | PAGE_TRANSITION_AUTO_SUBFRAME); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3630 | |
| 3631 | // If we failed on a browser initiated request, then make sure that our error |
| 3632 | // page load is regarded as the same browser initiated request. |
| 3633 | if (!navigation_state->is_content_initiated()) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3634 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 3635 | pending_navigation_params_->page_id = |
| 3636 | navigation_state->pending_page_id(); |
| 3637 | pending_navigation_params_->pending_history_list_offset = |
| 3638 | navigation_state->pending_history_list_offset(); |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 3639 | pending_navigation_params_->should_clear_history_list = |
| 3640 | navigation_state->history_list_was_cleared(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3641 | pending_navigation_params_->transition = |
| 3642 | navigation_state->transition_type(); |
| 3643 | pending_navigation_params_->request_time = |
| 3644 | document_state->request_time(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | // Provide the user with a more helpful error page? |
| 3648 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 3649 | return; |
| 3650 | |
| 3651 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3652 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3653 | } |
| 3654 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3655 | void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame, |
| 3656 | bool is_new_navigation) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3657 | DocumentState* document_state = |
| 3658 | DocumentState::FromDataSource(frame->dataSource()); |
| 3659 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3660 | InternalDocumentStateData* internal_data = |
| 3661 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3662 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3663 | if (document_state->commit_load_time().is_null()) |
| 3664 | document_state->set_commit_load_time(Time::Now()); |
| 3665 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3666 | if (internal_data->must_reset_scroll_and_scale_state()) { |
[email protected] | 06c7ba02 | 2012-12-17 19:24:12 | [diff] [blame] | 3667 | webview()->resetScrollAndScaleState(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3668 | internal_data->set_must_reset_scroll_and_scale_state(false); |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3669 | } |
[email protected] | 4b9c9e29 | 2013-07-18 19:13:28 | [diff] [blame] | 3670 | internal_data->set_use_error_page(false); |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3671 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3672 | if (is_new_navigation) { |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 3673 | // When we perform a new navigation, we need to update the last committed |
| 3674 | // session history entry with state for the page we are leaving. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3675 | UpdateSessionHistory(frame); |
| 3676 | |
| 3677 | // We bump our Page ID to correspond with the new session history entry. |
| 3678 | page_id_ = next_page_id_++; |
| 3679 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3680 | // Don't update history_page_ids_ (etc) for kSwappedOutURL, since |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 3681 | // we don't want to forget the entry that was there, and since we will |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3682 | // never come back to kSwappedOutURL. Note that we have to call |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3683 | // UpdateSessionHistory and update page_id_ even in this case, so that |
| 3684 | // the current entry gets a state update and so that we don't send a |
| 3685 | // state update to the wrong entry when we swap back in. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3686 | if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3687 | // Advance our offset in session history, applying the length limit. |
| 3688 | // There is now no forward history. |
| 3689 | history_list_offset_++; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3690 | if (history_list_offset_ >= kMaxSessionHistoryEntries) |
| 3691 | history_list_offset_ = kMaxSessionHistoryEntries - 1; |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3692 | history_list_length_ = history_list_offset_ + 1; |
| 3693 | history_page_ids_.resize(history_list_length_, -1); |
| 3694 | history_page_ids_[history_list_offset_] = page_id_; |
| 3695 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3696 | } else { |
| 3697 | // Inspect the navigation_state on this frame to see if the navigation |
| 3698 | // corresponds to a session history navigation... Note: |frame| may or |
| 3699 | // may not be the toplevel frame, but for the case of capturing session |
| 3700 | // history, the first committed frame suffices. We keep track of whether |
| 3701 | // we've seen this commit before so that only capture session history once |
| 3702 | // per navigation. |
| 3703 | // |
| 3704 | // Note that we need to check if the page ID changed. In the case of a |
| 3705 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 3706 | // previous URL and the current page ID, which would be wrong. |
| 3707 | if (navigation_state->pending_page_id() != -1 && |
| 3708 | navigation_state->pending_page_id() != page_id_ && |
| 3709 | !navigation_state->request_committed()) { |
| 3710 | // This is a successful session history navigation! |
| 3711 | UpdateSessionHistory(frame); |
| 3712 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3713 | |
| 3714 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 3715 | |
| 3716 | // If the history list is valid, our list of page IDs should be correct. |
| 3717 | DCHECK(history_list_length_ <= 0 || |
| 3718 | history_list_offset_ < 0 || |
| 3719 | history_list_offset_ >= history_list_length_ || |
| 3720 | history_page_ids_[history_list_offset_] == page_id_); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3721 | } |
| 3722 | } |
| 3723 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3724 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3725 | DidCommitProvisionalLoad(frame, is_new_navigation)); |
| 3726 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3727 | // Remember that we've already processed this request, so we don't update |
| 3728 | // the session history again. We do this regardless of whether this is |
| 3729 | // a session history navigation, because if we attempted a session history |
| 3730 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3731 | // new navigation. |
| 3732 | navigation_state->set_request_committed(true); |
| 3733 | |
| 3734 | UpdateURL(frame); |
| 3735 | |
| 3736 | // If this committed load was initiated by a client redirect, we're |
| 3737 | // at the last stop now, so clear it. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3738 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3739 | |
| 3740 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3741 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 3742 | |
| 3743 | if (!frame->parent()) { // Only for top frames. |
| 3744 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 3745 | if (render_thread_impl) { // Can be NULL in tests. |
| 3746 | render_thread_impl->histogram_customizer()-> |
| 3747 | RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(), |
| 3748 | g_view_map.Get().size()); |
| 3749 | } |
| 3750 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3751 | } |
| 3752 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3753 | void RenderViewImpl::didClearWindowObject(WebFrame* frame) { |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 3754 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3755 | DidClearWindowObject(frame)); |
| 3756 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3757 | if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 3758 | if (!dom_automation_controller_) |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3759 | dom_automation_controller_.reset(new DomAutomationController()); |
| 3760 | dom_automation_controller_->set_message_sender( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3761 | static_cast<RenderView*>(this)); |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3762 | dom_automation_controller_->set_routing_id(routing_id()); |
| 3763 | dom_automation_controller_->BindToJavascript(frame, |
| 3764 | "domAutomationController"); |
| 3765 | } |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 3766 | |
| 3767 | if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) { |
| 3768 | if (!stats_collection_controller_.get()) |
| 3769 | stats_collection_controller_.reset(new StatsCollectionController()); |
| 3770 | stats_collection_controller_->set_message_sender( |
| 3771 | static_cast<RenderView*>(this)); |
| 3772 | stats_collection_controller_->BindToJavascript(frame, |
| 3773 | "statsCollectionController"); |
| 3774 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3775 | } |
| 3776 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3777 | void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) { |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3778 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3779 | DidCreateDocumentElement(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3780 | } |
| 3781 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3782 | void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title, |
| 3783 | WebTextDirection direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 3784 | UpdateTitle(frame, title, direction); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3785 | |
| 3786 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3787 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3788 | } |
| 3789 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 3790 | void RenderViewImpl::didChangeIcon(WebFrame* frame, |
| 3791 | WebIconURL::Type icon_type) { |
| 3792 | if (frame->parent()) |
| 3793 | return; |
| 3794 | |
| 3795 | if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon) |
| 3796 | return; |
| 3797 | |
| 3798 | WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
| 3799 | std::vector<FaviconURL> urls; |
| 3800 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 3801 | urls.push_back(FaviconURL(icon_urls[i].iconURL(), |
| 3802 | ToFaviconType(icon_urls[i].iconType()))); |
| 3803 | } |
| 3804 | SendUpdateFaviconURL(urls); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3805 | } |
| 3806 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3807 | void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3808 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3809 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3810 | document_state->set_finish_document_load_time(Time::Now()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3811 | |
[email protected] | 622474d | 2010-11-04 09:21:08 | [diff] [blame] | 3812 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3813 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3814 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3815 | DidFinishDocumentLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3816 | |
| 3817 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3818 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3819 | } |
| 3820 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3821 | void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 3822 | if (webview()->mainFrame() == frame) { |
| 3823 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 3824 | page_id_)); |
| 3825 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3826 | } |
| 3827 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3828 | void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) { |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3829 | WebDataSource* ds = frame->dataSource(); |
| 3830 | DCHECK(ds); |
| 3831 | |
| 3832 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3833 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3834 | |
| 3835 | const WebURLRequest& failed_request = ds->request(); |
| 3836 | string16 error_description; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3837 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 3838 | frame, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3839 | failed_request, |
| 3840 | error, |
| 3841 | NULL, |
| 3842 | &error_description); |
| 3843 | Send(new ViewHostMsg_DidFailLoadWithError(routing_id_, |
| 3844 | frame->identifier(), |
| 3845 | failed_request.url(), |
| 3846 | !frame->parent(), |
| 3847 | error.reason, |
| 3848 | error_description)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3849 | } |
| 3850 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3851 | void RenderViewImpl::didFinishLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3852 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3853 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 1ac2ff1 | 2013-07-16 20:53:53 | [diff] [blame] | 3854 | if (document_state->finish_load_time().is_null()) { |
| 3855 | if (!frame->parent()) { |
| 3856 | TRACE_EVENT_INSTANT0("WebCore", "LoadFinished", |
| 3857 | TRACE_EVENT_SCOPE_PROCESS); |
| 3858 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3859 | document_state->set_finish_load_time(Time::Now()); |
[email protected] | 1ac2ff1 | 2013-07-16 20:53:53 | [diff] [blame] | 3860 | } |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3861 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3862 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); |
[email protected] | fdd94a0 | 2010-11-05 08:07:17 | [diff] [blame] | 3863 | |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3864 | Send(new ViewHostMsg_DidFinishLoad(routing_id_, |
| 3865 | frame->identifier(), |
| 3866 | ds->request().url(), |
| 3867 | !frame->parent())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3868 | } |
| 3869 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3870 | void RenderViewImpl::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3871 | WebFrame* frame, bool is_new_navigation) { |
| 3872 | // If this was a reference fragment navigation that we initiated, then we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3873 | // could end up having a non-null pending navigation params. We just need to |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3874 | // update the ExtraData on the datasource so that others who read the |
| 3875 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3876 | // initiate this navigation, then we need to take care to reset any pre- |
| 3877 | // existing navigation state to a content-initiated navigation state. |
| 3878 | // DidCreateDataSource conveniently takes care of this for us. |
| 3879 | didCreateDataSource(frame, frame->dataSource()); |
| 3880 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3881 | DocumentState* document_state = |
| 3882 | DocumentState::FromDataSource(frame->dataSource()); |
| 3883 | NavigationState* new_state = document_state->navigation_state(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3884 | new_state->set_was_within_same_page(true); |
| 3885 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3886 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 3887 | |
[email protected] | 750fcf87 | 2011-08-03 23:10:47 | [diff] [blame] | 3888 | WebDataSource* datasource = frame->view()->mainFrame()->dataSource(); |
| 3889 | UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3890 | } |
| 3891 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3892 | void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3893 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3894 | } |
| 3895 | |
[email protected] | cd92296c | 2013-07-19 06:24:50 | [diff] [blame] | 3896 | void RenderViewImpl::assignIdentifierToRequest( |
| 3897 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 3898 | // Ignore |
| 3899 | } |
| 3900 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3901 | void RenderViewImpl::willSendRequest(WebFrame* frame, |
| 3902 | unsigned identifier, |
| 3903 | WebURLRequest& request, |
| 3904 | const WebURLResponse& redirect_response) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3905 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3906 | } |
| 3907 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3908 | void RenderViewImpl::didReceiveResponse( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3909 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3910 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3911 | } |
| 3912 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3913 | void RenderViewImpl::didFinishResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3914 | WebFrame* frame, unsigned identifier) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3915 | InternalDocumentStateData* internal_data = |
| 3916 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 3917 | if (!internal_data->use_error_page()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3918 | return; |
| 3919 | |
[email protected] | 7bfc153f | 2011-09-23 22:00:20 | [diff] [blame] | 3920 | // Do not show error page when DevTools is attached. |
| 3921 | if (devtools_agent_->IsAttached()) |
| 3922 | return; |
| 3923 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3924 | // Display error page, if appropriate. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3925 | int http_status_code = internal_data->http_status_code(); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3926 | if (http_status_code == 404) { |
| 3927 | // On 404s, try a remote search page as a fallback. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3928 | const GURL& document_url = frame->document().url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3929 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3930 | const GURL& error_page_url = |
| 3931 | GetAlternateErrorPageURL(document_url, HTTP_404); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3932 | if (error_page_url.is_valid()) { |
| 3933 | WebURLError original_error; |
[email protected] | 2e9706c | 2011-06-09 16:49:47 | [diff] [blame] | 3934 | original_error.domain = "http"; |
| 3935 | original_error.reason = 404; |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3936 | original_error.unreachableURL = document_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3937 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3938 | internal_data->set_alt_error_page_fetcher( |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3939 | new AltErrorPageResourceFetcher( |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 3940 | error_page_url, frame, frame->dataSource()->request(), |
| 3941 | original_error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 3942 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 3943 | base::Unretained(this)))); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3944 | return; |
| 3945 | } |
| 3946 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3947 | |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 3948 | std::string error_domain; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3949 | if (GetContentClient()->renderer()->HasErrorPage( |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 3950 | http_status_code, &error_domain)) { |
| 3951 | WebURLError error; |
| 3952 | error.unreachableURL = frame->document().url(); |
| 3953 | error.domain = WebString::fromUTF8(error_domain); |
| 3954 | error.reason = http_status_code; |
| 3955 | |
| 3956 | LoadNavigationErrorPage( |
| 3957 | frame, frame->dataSource()->request(), error, std::string(), true); |
| 3958 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3959 | } |
| 3960 | |
[email protected] | cd92296c | 2013-07-19 06:24:50 | [diff] [blame] | 3961 | void RenderViewImpl::didFailResourceLoad( |
| 3962 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 3963 | // Ignore |
| 3964 | } |
| 3965 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3966 | void RenderViewImpl::didLoadResourceFromMemoryCache( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3967 | WebFrame* frame, const WebURLRequest& request, |
| 3968 | const WebURLResponse& response) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3969 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3970 | } |
| 3971 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3972 | void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3973 | NOTREACHED(); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3974 | } |
| 3975 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3976 | void RenderViewImpl::didRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 3977 | WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3978 | NOTREACHED(); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3979 | } |
| 3980 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3981 | void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3982 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3983 | } |
| 3984 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3985 | void RenderViewImpl::didCreateScriptContext(WebFrame* frame, |
| 3986 | v8::Handle<v8::Context> context, |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 3987 | int extension_group, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3988 | int world_id) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3989 | NOTREACHED(); |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 3990 | } |
| 3991 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3992 | void RenderViewImpl::willReleaseScriptContext(WebFrame* frame, |
| 3993 | v8::Handle<v8::Context> context, |
| 3994 | int world_id) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3995 | NOTREACHED(); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3996 | } |
| 3997 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3998 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 3999 | // We don't always want to send the change messages over IPC, only if we've |
| 4000 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 4001 | // message. |
| 4002 | if (!send_preferred_size_changes_ || !webview()) |
| 4003 | return; |
| 4004 | |
[email protected] | e76b797 | 2013-06-06 02:58:48 | [diff] [blame] | 4005 | gfx::Size size = webview()->contentsPreferredMinimumSize(); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 4006 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 4007 | if (size == preferred_size_) |
| 4008 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 4009 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 4010 | preferred_size_ = size; |
| 4011 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 4012 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4013 | } |
| 4014 | |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 4015 | BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 4016 | if (!browser_plugin_manager_.get()) |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 4017 | browser_plugin_manager_ = BrowserPluginManager::Create(this); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 4018 | return browser_plugin_manager_.get(); |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 4019 | } |
| 4020 | |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 4021 | void RenderViewImpl::EnsureMediaStreamClient() { |
[email protected] | 7082fb94 | 2012-05-16 23:44:59 | [diff] [blame] | 4022 | if (!RenderThreadImpl::current()) // Will be NULL during unit tests. |
[email protected] | 0838156 | 2012-05-15 20:55:40 | [diff] [blame] | 4023 | return; |
| 4024 | |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 4025 | #if defined(OS_ANDROID) |
[email protected] | ce585bf | 2013-03-14 16:25:16 | [diff] [blame] | 4026 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC)) |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 4027 | return; |
| 4028 | #endif |
| 4029 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 4030 | #if defined(ENABLE_WEBRTC) |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4031 | if (!media_stream_dispatcher_) |
| 4032 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 4033 | |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 4034 | if (!media_stream_client_) { |
| 4035 | MediaStreamImpl* media_stream_impl = new MediaStreamImpl( |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 4036 | this, |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4037 | media_stream_dispatcher_, |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 4038 | RenderThreadImpl::current()->GetMediaStreamDependencyFactory()); |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 4039 | media_stream_client_ = media_stream_impl; |
| 4040 | web_user_media_client_ = media_stream_impl; |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4041 | } |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 4042 | #endif |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4043 | } |
| 4044 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4045 | void RenderViewImpl::didChangeContentsSize(WebFrame* frame, |
| 4046 | const WebSize& size) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4047 | if (webview()->mainFrame() != frame) |
| 4048 | return; |
| 4049 | WebView* frameView = frame->view(); |
| 4050 | if (!frameView) |
| 4051 | return; |
| 4052 | |
| 4053 | bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); |
| 4054 | bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); |
| 4055 | |
| 4056 | if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || |
| 4057 | has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { |
| 4058 | Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( |
| 4059 | routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); |
| 4060 | |
| 4061 | cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; |
| 4062 | cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; |
| 4063 | } |
| 4064 | } |
| 4065 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4066 | void RenderViewImpl::UpdateScrollState(WebFrame* frame) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4067 | WebSize offset = frame->scrollOffset(); |
| 4068 | WebSize minimum_offset = frame->minimumScrollOffset(); |
| 4069 | WebSize maximum_offset = frame->maximumScrollOffset(); |
| 4070 | |
| 4071 | bool is_pinned_to_left = offset.width <= minimum_offset.width; |
| 4072 | bool is_pinned_to_right = offset.width >= maximum_offset.width; |
| 4073 | |
| 4074 | if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || |
| 4075 | is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { |
| 4076 | Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( |
| 4077 | routing_id_, is_pinned_to_left, is_pinned_to_right)); |
| 4078 | |
| 4079 | cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; |
| 4080 | cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; |
| 4081 | } |
[email protected] | 4e72174 | 2013-02-04 21:39:30 | [diff] [blame] | 4082 | |
| 4083 | Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4084 | } |
| 4085 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4086 | void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) { |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 4087 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4088 | |
| 4089 | if (webview()->mainFrame() == frame) |
| 4090 | UpdateScrollState(frame); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 4091 | |
| 4092 | FOR_EACH_OBSERVER( |
| 4093 | RenderViewObserver, observers_, DidChangeScrollOffset(frame)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4094 | } |
| 4095 | |
[email protected] | a9344092d | 2013-02-27 00:56:45 | [diff] [blame] | 4096 | void RenderViewImpl::willInsertBody(WebKit::WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4097 | NOTREACHED(); |
[email protected] | a9344092d | 2013-02-27 00:56:45 | [diff] [blame] | 4098 | } |
| 4099 | |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4100 | void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) { |
| 4101 | if (frame != webview()->mainFrame()) |
| 4102 | return; |
| 4103 | |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 4104 | InternalDocumentStateData* data = |
| 4105 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 4106 | data->set_did_first_visually_non_empty_layout(true); |
| 4107 | |
| 4108 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4109 | // Update body background color if necessary. |
| 4110 | SkColor bg_color = webwidget_->backgroundColor(); |
| 4111 | |
| 4112 | // If not initialized, default to white. Note that 0 is different from black |
| 4113 | // as black still has alpha 0xFF. |
| 4114 | if (!bg_color) |
| 4115 | bg_color = SK_ColorWHITE; |
| 4116 | |
| 4117 | if (bg_color != body_background_color_) { |
| 4118 | body_background_color_ = bg_color; |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4119 | Send(new ViewHostMsg_DidChangeBodyBackgroundColor( |
| 4120 | GetRoutingID(), bg_color)); |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4121 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4122 | #endif |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 4123 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4124 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4125 | void RenderViewImpl::SendFindReply(int request_id, |
| 4126 | int match_count, |
| 4127 | int ordinal, |
| 4128 | const WebRect& selection_rect, |
| 4129 | bool final_status_update) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4130 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 4131 | request_id, |
| 4132 | match_count, |
| 4133 | selection_rect, |
| 4134 | ordinal, |
| 4135 | final_status_update)); |
| 4136 | } |
| 4137 | |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 4138 | // static |
| 4139 | bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams( |
| 4140 | const string16& selection_text, |
| 4141 | size_t selection_text_offset, |
| 4142 | const ui::Range& selection_range, |
| 4143 | const ContextMenuParams& params) { |
| 4144 | string16 trimmed_selection_text; |
| 4145 | if (!selection_text.empty() && !selection_range.is_empty()) { |
| 4146 | const int start = selection_range.GetMin() - selection_text_offset; |
| 4147 | const size_t length = selection_range.length(); |
| 4148 | if (start >= 0 && start + length <= selection_text.length()) { |
| 4149 | TrimWhitespace(selection_text.substr(start, length), TRIM_ALL, |
| 4150 | &trimmed_selection_text); |
| 4151 | } |
| 4152 | } |
| 4153 | string16 trimmed_params_text; |
| 4154 | TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text); |
| 4155 | return trimmed_params_text != trimmed_selection_text; |
| 4156 | } |
| 4157 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4158 | void RenderViewImpl::reportFindInPageMatchCount(int request_id, |
| 4159 | int count, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4160 | bool final_update) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4161 | NOTREACHED(); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 4162 | } |
| 4163 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4164 | void RenderViewImpl::reportFindInPageSelection(int request_id, |
| 4165 | int active_match_ordinal, |
| 4166 | const WebRect& selection_rect) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4167 | NOTREACHED(); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 4168 | } |
| 4169 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4170 | void RenderViewImpl::openFileSystem( |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4171 | WebFrame* frame, |
[email protected] | 18cdb0e | 2013-03-19 16:37:53 | [diff] [blame] | 4172 | WebKit::WebFileSystemType type, |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4173 | long long size, |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 4174 | bool create, |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4175 | WebFileSystemCallbacks* callbacks) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4176 | NOTREACHED(); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4177 | } |
| 4178 | |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 4179 | void RenderViewImpl::deleteFileSystem( |
| 4180 | WebFrame* frame, |
[email protected] | 18cdb0e | 2013-03-19 16:37:53 | [diff] [blame] | 4181 | WebKit::WebFileSystemType type , |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 4182 | WebFileSystemCallbacks* callbacks) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4183 | NOTREACHED(); |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 4184 | } |
| 4185 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4186 | void RenderViewImpl::queryStorageUsageAndQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4187 | WebFrame* frame, |
| 4188 | WebStorageQuotaType type, |
| 4189 | WebStorageQuotaCallbacks* callbacks) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4190 | NOTREACHED(); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4191 | } |
| 4192 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4193 | void RenderViewImpl::requestStorageQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4194 | WebFrame* frame, |
| 4195 | WebStorageQuotaType type, |
| 4196 | unsigned long long requested_size, |
| 4197 | WebStorageQuotaCallbacks* callbacks) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4198 | NOTREACHED(); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4199 | } |
| 4200 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4201 | bool RenderViewImpl::willCheckAndDispatchMessageEvent( |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4202 | WebKit::WebFrame* sourceFrame, |
| 4203 | WebKit::WebFrame* targetFrame, |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4204 | WebKit::WebSecurityOrigin target_origin, |
| 4205 | WebKit::WebDOMMessageEvent event) { |
| 4206 | if (!is_swapped_out_) |
| 4207 | return false; |
| 4208 | |
| 4209 | ViewMsg_PostMessage_Params params; |
| 4210 | params.data = event.data().toString(); |
| 4211 | params.source_origin = event.origin(); |
| 4212 | if (!target_origin.isNull()) |
| 4213 | params.target_origin = target_origin.toString(); |
| 4214 | |
| 4215 | // Include the routing ID for the source frame, which the browser process |
| 4216 | // will translate into the routing ID for the equivalent frame in the target |
| 4217 | // process. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4218 | params.source_routing_id = MSG_ROUTING_NONE; |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4219 | RenderViewImpl* source_view = FromWebView(sourceFrame->view()); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4220 | if (source_view) |
| 4221 | params.source_routing_id = source_view->routing_id(); |
| 4222 | |
| 4223 | Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
| 4224 | return true; |
| 4225 | } |
| 4226 | |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 4227 | void RenderViewImpl::willOpenSocketStream( |
| 4228 | WebSocketStreamHandle* handle) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4229 | NOTREACHED(); |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 4230 | } |
| 4231 | |
[email protected] | ccee486 | 2012-10-03 18:34:26 | [diff] [blame] | 4232 | void RenderViewImpl::willStartUsingPeerConnectionHandler( |
| 4233 | WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4234 | NOTREACHED(); |
[email protected] | ccee486 | 2012-10-03 18:34:26 | [diff] [blame] | 4235 | } |
| 4236 | |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame] | 4237 | WebKit::WebString RenderViewImpl::acceptLanguages() { |
| 4238 | return WebString::fromUTF8(renderer_preferences_.accept_languages); |
| 4239 | } |
| 4240 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 4241 | WebKit::WebString RenderViewImpl::userAgentOverride( |
| 4242 | WebKit::WebFrame* frame, |
| 4243 | const WebKit::WebURL& url) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4244 | NOTREACHED(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 4245 | return WebKit::WebString(); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 4246 | } |
| 4247 | |
[email protected] | a3e217f | 2013-04-12 22:38:34 | [diff] [blame] | 4248 | WebString RenderViewImpl::doNotTrackValue(WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4249 | NOTREACHED(); |
| 4250 | return WebKit::WebString(); |
[email protected] | a3e217f | 2013-04-12 22:38:34 | [diff] [blame] | 4251 | } |
| 4252 | |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 4253 | bool RenderViewImpl::allowWebGL(WebFrame* frame, bool default_value) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4254 | NOTREACHED(); |
| 4255 | return false; |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | void RenderViewImpl::didLoseWebGLContext( |
| 4259 | WebKit::WebFrame* frame, |
| 4260 | int arb_robustness_status_code) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4261 | NOTREACHED(); |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 4262 | } |
| 4263 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4264 | // WebKit::WebPageSerializerClient implementation ------------------------------ |
| 4265 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4266 | void RenderViewImpl::didSerializeDataForFrame( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4267 | const WebURL& frame_url, |
| 4268 | const WebCString& data, |
| 4269 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4270 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4271 | routing_id(), |
| 4272 | frame_url, |
| 4273 | data.data(), |
| 4274 | static_cast<int32>(status))); |
| 4275 | } |
| 4276 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4277 | // RenderView implementation --------------------------------------------------- |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4278 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4279 | bool RenderViewImpl::Send(IPC::Message* message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4280 | return RenderWidget::Send(message); |
| 4281 | } |
| 4282 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4283 | int RenderViewImpl::GetRoutingID() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4284 | return routing_id_; |
| 4285 | } |
| 4286 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4287 | int RenderViewImpl::GetPageId() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4288 | return page_id_; |
| 4289 | } |
| 4290 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4291 | gfx::Size RenderViewImpl::GetSize() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4292 | return size(); |
| 4293 | } |
| 4294 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4295 | WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4296 | return webkit_preferences_; |
| 4297 | } |
| 4298 | |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 4299 | void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) { |
| 4300 | OnUpdateWebPreferences(preferences); |
| 4301 | } |
| 4302 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4303 | WebKit::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4304 | return webview(); |
| 4305 | } |
| 4306 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4307 | WebKit::WebNode RenderViewImpl::GetFocusedNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4308 | if (!webview()) |
| 4309 | return WebNode(); |
| 4310 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 4311 | if (focused_frame) { |
| 4312 | WebDocument doc = focused_frame->document(); |
| 4313 | if (!doc.isNull()) |
| 4314 | return doc.focusedNode(); |
| 4315 | } |
| 4316 | |
| 4317 | return WebNode(); |
| 4318 | } |
| 4319 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4320 | WebKit::WebNode RenderViewImpl::GetContextMenuNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4321 | return context_menu_node_; |
| 4322 | } |
| 4323 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4324 | bool RenderViewImpl::IsEditableNode(const WebNode& node) const { |
| 4325 | if (node.isNull()) |
| 4326 | return false; |
| 4327 | |
| 4328 | if (node.isContentEditable()) |
| 4329 | return true; |
| 4330 | |
| 4331 | if (node.isElementNode()) { |
| 4332 | const WebElement& element = node.toConst<WebElement>(); |
| 4333 | if (element.isTextFormControlElement()) |
| 4334 | return true; |
| 4335 | |
| 4336 | // Also return true if it has an ARIA role of 'textbox'. |
| 4337 | for (unsigned i = 0; i < element.attributeCount(); ++i) { |
| 4338 | if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) { |
| 4339 | if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox")) |
| 4340 | return true; |
| 4341 | break; |
| 4342 | } |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4343 | } |
| 4344 | } |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4345 | |
| 4346 | return false; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4347 | } |
| 4348 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4349 | WebKit::WebPlugin* RenderViewImpl::CreatePlugin( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4350 | WebKit::WebFrame* frame, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 4351 | const WebPluginInfo& info, |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4352 | const WebKit::WebPluginParams& params) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 4353 | WebKit::WebPlugin* pepper_webplugin = |
| 4354 | pepper_helper_->CreatePepperWebPlugin(info, params); |
| 4355 | |
| 4356 | if (pepper_webplugin) |
| 4357 | return pepper_webplugin; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4358 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 4359 | return new WebPluginImpl(frame, params, info.path, AsWeakPtr()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4360 | } |
| 4361 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4362 | void RenderViewImpl::EvaluateScript(const string16& frame_xpath, |
| 4363 | const string16& jscript, |
| 4364 | int id, |
| 4365 | bool notify_result) { |
[email protected] | 3b2a3a8 | 2013-02-20 15:29:31 | [diff] [blame] | 4366 | v8::HandleScope handle_scope; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4367 | v8::Handle<v8::Value> result; |
| 4368 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4369 | if (web_frame) |
| 4370 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); |
| 4371 | if (notify_result) { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4372 | base::ListValue list; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4373 | if (!result.IsEmpty() && web_frame) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4374 | v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 4375 | v8::Context::Scope context_scope(context); |
| 4376 | V8ValueConverterImpl converter; |
[email protected] | 3de391e8 | 2012-05-16 17:50:51 | [diff] [blame] | 4377 | converter.SetDateAllowed(true); |
[email protected] | e0658bc | 2012-09-17 04:05:24 | [diff] [blame] | 4378 | converter.SetRegExpAllowed(true); |
| 4379 | base::Value* result_value = converter.FromV8Value(result, context); |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4380 | list.Set(0, result_value ? result_value : base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4381 | } else { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4382 | list.Set(0, base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4383 | } |
| 4384 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
| 4385 | } |
| 4386 | } |
| 4387 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4388 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4389 | return (!send_preferred_size_changes_ || |
| 4390 | (disable_scrollbars_size_limit_.width() <= width || |
| 4391 | disable_scrollbars_size_limit_.height() <= height)); |
| 4392 | } |
| 4393 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4394 | int RenderViewImpl::GetEnabledBindings() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4395 | return enabled_bindings_; |
| 4396 | } |
| 4397 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4398 | bool RenderViewImpl::GetContentStateImmediately() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4399 | return send_content_state_immediately_; |
| 4400 | } |
| 4401 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4402 | float RenderViewImpl::GetFilteredTimePerFrame() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4403 | return filtered_time_per_frame(); |
| 4404 | } |
| 4405 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4406 | int RenderViewImpl::ShowContextMenu(ContextMenuClient* client, |
| 4407 | const ContextMenuParams& params) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4408 | DCHECK(client); // A null client means "internal" when we issue callbacks. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4409 | ContextMenuParams our_params(params); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4410 | our_params.custom_context.request_id = pending_context_menus_.Add(client); |
| 4411 | Send(new ViewHostMsg_ContextMenu(routing_id_, our_params)); |
| 4412 | return our_params.custom_context.request_id; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4413 | } |
| 4414 | |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 4415 | void RenderViewImpl::CancelContextMenu(int request_id) { |
| 4416 | DCHECK(pending_context_menus_.Lookup(request_id)); |
| 4417 | pending_context_menus_.Remove(request_id); |
| 4418 | } |
| 4419 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4420 | WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4421 | return visibilityState(); |
| 4422 | } |
| 4423 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4424 | void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame, |
| 4425 | const WebKit::WebString& message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4426 | return runModalAlertDialog(frame, message); |
| 4427 | } |
| 4428 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4429 | void RenderViewImpl::LoadURLExternally( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4430 | WebKit::WebFrame* frame, |
| 4431 | const WebKit::WebURLRequest& request, |
| 4432 | WebKit::WebNavigationPolicy policy) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4433 | main_render_frame_->loadURLExternally(frame, request, policy); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4434 | } |
| 4435 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4436 | void RenderViewImpl::DidStartLoading() { |
| 4437 | didStartLoading(); |
| 4438 | } |
| 4439 | |
| 4440 | void RenderViewImpl::DidStopLoading() { |
| 4441 | didStopLoading(); |
| 4442 | } |
| 4443 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4444 | void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4445 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4446 | reinterpret_cast<int64>(player), |
| 4447 | player->hasVideo(), |
| 4448 | player->hasAudio(), |
| 4449 | true)); |
| 4450 | } |
| 4451 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4452 | void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4453 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4454 | reinterpret_cast<int64>(player), |
| 4455 | player->hasVideo(), |
| 4456 | player->hasAudio(), |
| 4457 | false)); |
| 4458 | } |
| 4459 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4460 | void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4461 | DidPause(player); |
| 4462 | } |
| 4463 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4464 | void RenderViewImpl::SyncNavigationState() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4465 | if (!webview()) |
| 4466 | return; |
| 4467 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4468 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 4469 | SendUpdateState(item); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4470 | } |
| 4471 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4472 | void RenderViewImpl::SyncSelectionIfRequired() { |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4473 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4474 | if (!frame) |
| 4475 | return; |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4476 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4477 | string16 text; |
| 4478 | size_t offset; |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4479 | ui::Range range; |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 4480 | if (pepper_helper_->IsPluginFocused()) { |
| 4481 | pepper_helper_->GetSurroundingText(&text, &range); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4482 | offset = 0; // Pepper API does not support offset reporting. |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4483 | // TODO(kinaba): cut as needed. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4484 | } else { |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4485 | size_t location, length; |
| 4486 | if (!webview()->caretOrSelectionRange(&location, &length)) |
| 4487 | return; |
| 4488 | |
| 4489 | range = ui::Range(location, location + length); |
| 4490 | |
[email protected] | 6123214 | 2013-06-20 16:43:32 | [diff] [blame] | 4491 | if (webview()->textInputInfo().type != WebKit::WebTextInputTypeNone) { |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4492 | // If current focused element is editable, we will send 100 more chars |
| 4493 | // before and after selection. It is for input method surrounding text |
| 4494 | // feature. |
| 4495 | if (location > kExtraCharsBeforeAndAfterSelection) |
| 4496 | offset = location - kExtraCharsBeforeAndAfterSelection; |
| 4497 | else |
| 4498 | offset = 0; |
| 4499 | length = location + length - offset + kExtraCharsBeforeAndAfterSelection; |
| 4500 | WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); |
| 4501 | if (!webrange.isNull()) |
| 4502 | text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); |
| 4503 | } else { |
| 4504 | offset = location; |
| 4505 | text = frame->selectionAsText(); |
| 4506 | // http://crbug.com/101435 |
| 4507 | // In some case, frame->selectionAsText() returned text's length is not |
| 4508 | // equal to the length returned from webview()->caretOrSelectionRange(). |
| 4509 | // So we have to set the range according to text.length(). |
| 4510 | range.set_end(range.start() + text.length()); |
| 4511 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4512 | } |
| 4513 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4514 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 4515 | // the selection hasn't actually changed. We don't want to report these |
| 4516 | // because it will cause us to continually claim the X clipboard. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4517 | if (selection_text_offset_ != offset || |
| 4518 | selection_range_ != range || |
| 4519 | selection_text_ != text) { |
| 4520 | selection_text_ = text; |
| 4521 | selection_text_offset_ = offset; |
| 4522 | selection_range_ = range; |
| 4523 | Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range)); |
| 4524 | } |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 4525 | UpdateSelectionBounds(); |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4526 | } |
| 4527 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4528 | GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, |
| 4529 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4530 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4531 | // If the URL that failed was secure, then the embedding web page was not |
| 4532 | // expecting a network attacker to be able to manipulate its contents. As |
| 4533 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 4534 | // attacker to manipulate the contents of the response if we tried to use |
| 4535 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4536 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | // Grab the base URL from the browser process. |
| 4540 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4541 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4542 | |
| 4543 | // Strip query params from the failed URL. |
| 4544 | GURL::Replacements remove_params; |
| 4545 | remove_params.ClearUsername(); |
| 4546 | remove_params.ClearPassword(); |
| 4547 | remove_params.ClearQuery(); |
| 4548 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4549 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 4550 | std::string spec_to_send = url_to_send.spec(); |
| 4551 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 4552 | if (failed_url.has_query()) |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4553 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4554 | |
| 4555 | // Construct the query params to send to link doctor. |
| 4556 | std::string params(alternate_error_page_url_.query()); |
| 4557 | params.append("&url="); |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 4558 | params.append(net::EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4559 | params.append("&sourceid=chrome"); |
| 4560 | params.append("&error="); |
| 4561 | switch (error_type) { |
| 4562 | case DNS_ERROR: |
| 4563 | params.append("dnserror"); |
| 4564 | break; |
| 4565 | |
| 4566 | case HTTP_404: |
| 4567 | params.append("http404"); |
| 4568 | break; |
| 4569 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4570 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 4571 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4572 | break; |
| 4573 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4574 | default: |
| 4575 | NOTREACHED() << "unknown ErrorPageType"; |
| 4576 | } |
| 4577 | |
| 4578 | // OK, build the final url to return. |
| 4579 | GURL::Replacements link_doctor_params; |
| 4580 | link_doctor_params.SetQueryStr(params); |
| 4581 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 4582 | return url; |
| 4583 | } |
| 4584 | |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 4585 | GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const { |
| 4586 | WebDataSource* ds = frame->dataSource(); |
| 4587 | if (ds->hasUnreachableURL()) |
| 4588 | return ds->unreachableURL(); |
| 4589 | |
| 4590 | const WebURLRequest& request = ds->request(); |
| 4591 | return request.url(); |
| 4592 | } |
| 4593 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4594 | WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4595 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4596 | } |
| 4597 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4598 | void RenderViewImpl::OnFind(int request_id, |
| 4599 | const string16& search_text, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4600 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4601 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4602 | |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4603 | // Check if the plugin still exists in the document. |
| 4604 | if (main_frame->document().isPluginDocument() && |
| 4605 | GetWebPluginFromPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4606 | if (options.findNext) { |
| 4607 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4608 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4609 | } else { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4610 | if (!GetWebPluginFromPluginDocument()->startFind( |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 4611 | search_text, options.matchCase, request_id)) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 4612 | // Send "no results". |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4613 | SendFindReply(request_id, 0, 0, gfx::Rect(), true); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4614 | } |
| 4615 | } |
| 4616 | return; |
| 4617 | } |
| 4618 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4619 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4620 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4621 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 4622 | |
| 4623 | bool multi_frame = (frame_after_main != main_frame); |
| 4624 | |
| 4625 | // If we have multiple frames, we don't want to wrap the search within the |
| 4626 | // frame, so we check here if we only have main_frame in the chain. |
| 4627 | bool wrap_within_frame = !multi_frame; |
| 4628 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 4629 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4630 | bool result = false; |
| 4631 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4632 | // If something is selected when we start searching it means we cannot just |
| 4633 | // increment the current match ordinal; we need to re-generate it. |
| 4634 | WebRange current_selection = focused_frame->selectionRange(); |
| 4635 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4636 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4637 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4638 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4639 | |
| 4640 | if (!result) { |
| 4641 | // don't leave text selected as you move to the next frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4642 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
| 4643 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4644 | |
| 4645 | // Find the next frame, but skip the invisible ones. |
| 4646 | do { |
| 4647 | // What is the next frame to search? (we might be going backwards). Note |
| 4648 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4649 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4650 | search_frame->traverseNext(true) : |
| 4651 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4652 | } while (!search_frame->hasVisibleContent() && |
| 4653 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4654 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 4655 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4656 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
| 4657 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4658 | |
| 4659 | // If we have multiple frames and we have wrapped back around to the |
| 4660 | // focused frame, we need to search it once more allowing wrap within |
| 4661 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 4662 | // reported matches, but no frames after the focused_frame contain a |
| 4663 | // match for the search word(s). |
| 4664 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4665 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4666 | request_id, search_text, options, true, // Force wrapping. |
| 4667 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4668 | } |
| 4669 | } |
| 4670 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4671 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4672 | } while (!result && search_frame != focused_frame); |
| 4673 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4674 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4675 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4676 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4677 | } else { |
| 4678 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 4679 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 4680 | // yet what is active. |
| 4681 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 4682 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4683 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4684 | // If we find no matches then this will be our last status update. |
| 4685 | // Otherwise the scoping effort will send more results. |
| 4686 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4687 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4688 | SendFindReply(request_id, match_count, ordinal, selection_rect, |
| 4689 | final_status_update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4690 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4691 | // Scoping effort begins, starting with the mainframe. |
| 4692 | search_frame = main_frame; |
| 4693 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4694 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4695 | |
| 4696 | do { |
| 4697 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4698 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4699 | |
| 4700 | // We don't start another scoping effort unless at least one match has |
| 4701 | // been found. |
| 4702 | if (result) { |
| 4703 | // Start new scoping request. If the scoping function determines that it |
| 4704 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4705 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4706 | search_text, |
| 4707 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4708 | true); // reset the tickmarks |
| 4709 | } |
| 4710 | |
| 4711 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 4712 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4713 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4714 | } while (search_frame != main_frame); |
| 4715 | } |
| 4716 | } |
| 4717 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4718 | void RenderViewImpl::OnStopFinding(StopFindAction action) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4719 | WebView* view = webview(); |
| 4720 | if (!view) |
| 4721 | return; |
| 4722 | |
| 4723 | WebDocument doc = view->mainFrame()->document(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4724 | if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4725 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4726 | return; |
| 4727 | } |
| 4728 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4729 | bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4730 | if (clear_selection) { |
| 4731 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
| 4732 | GetFocusedNode()); |
| 4733 | } |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4734 | |
| 4735 | WebFrame* frame = view->mainFrame(); |
| 4736 | while (frame) { |
| 4737 | frame->stopFinding(clear_selection); |
| 4738 | frame = frame->traverseNext(false); |
| 4739 | } |
| 4740 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4741 | if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4742 | WebFrame* focused_frame = view->focusedFrame(); |
| 4743 | if (focused_frame) { |
| 4744 | WebDocument doc = focused_frame->document(); |
| 4745 | if (!doc.isNull()) { |
| 4746 | WebNode node = doc.focusedNode(); |
| 4747 | if (!node.isNull()) |
| 4748 | node.simulateClick(); |
| 4749 | } |
| 4750 | } |
| 4751 | } |
| 4752 | } |
| 4753 | |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4754 | #if defined(OS_ANDROID) |
| 4755 | void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| 4756 | float x, float y) { |
| 4757 | if (!webview()) |
| 4758 | return; |
| 4759 | |
| 4760 | WebFrame* main_frame = webview()->mainFrame(); |
| 4761 | WebRect selection_rect; |
| 4762 | int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), |
| 4763 | &selection_rect); |
| 4764 | if (ordinal == -1) { |
| 4765 | // Something went wrong, so send a no-op reply (force the main_frame to |
| 4766 | // report the current match count) in case the host is waiting for a |
| 4767 | // response due to rate-limiting). |
| 4768 | main_frame->increaseMatchCount(0, request_id); |
| 4769 | return; |
| 4770 | } |
| 4771 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4772 | SendFindReply(request_id, |
| 4773 | -1 /* number_of_matches */, |
| 4774 | ordinal, |
| 4775 | selection_rect, |
| 4776 | true /* final_update */); |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | void RenderViewImpl::OnFindMatchRects(int current_version) { |
| 4780 | if (!webview()) |
| 4781 | return; |
| 4782 | |
| 4783 | WebFrame* main_frame = webview()->mainFrame(); |
| 4784 | std::vector<gfx::RectF> match_rects; |
| 4785 | |
| 4786 | int rects_version = main_frame->findMatchMarkersVersion(); |
| 4787 | if (current_version != rects_version) { |
| 4788 | WebVector<WebFloatRect> web_match_rects; |
| 4789 | main_frame->findMatchRects(web_match_rects); |
| 4790 | match_rects.reserve(web_match_rects.size()); |
| 4791 | for (size_t i = 0; i < web_match_rects.size(); ++i) |
| 4792 | match_rects.push_back(gfx::RectF(web_match_rects[i])); |
| 4793 | } |
| 4794 | |
| 4795 | gfx::RectF active_rect = main_frame->activeFindMatchRect(); |
| 4796 | Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_, |
| 4797 | rects_version, |
| 4798 | match_rects, |
| 4799 | active_rect)); |
| 4800 | } |
| 4801 | #endif |
| 4802 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4803 | void RenderViewImpl::OnZoom(PageZoom zoom) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4804 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4805 | return; |
| 4806 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 4807 | webview()->hidePopups(); |
[email protected] | 854ab546 | 2011-11-22 20:48:10 | [diff] [blame] | 4808 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4809 | double old_zoom_level = webview()->zoomLevel(); |
| 4810 | double zoom_level; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4811 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4812 | zoom_level = 0; |
| 4813 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 4814 | // Previous zoom level is a whole number, so just increment/decrement. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4815 | zoom_level = old_zoom_level + zoom; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4816 | } else { |
| 4817 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 4818 | // not a whole number, or a plugin changed it to a custom value. We want |
| 4819 | // to go to the next whole number so that the user can always get back to |
| 4820 | // 100% with the keyboard/menu. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4821 | if ((old_zoom_level > 1 && zoom > 0) || |
| 4822 | (old_zoom_level < 1 && zoom < 0)) { |
| 4823 | zoom_level = static_cast<int>(old_zoom_level + zoom); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4824 | } else { |
| 4825 | // We're going towards 100%, so first go to the next whole number. |
| 4826 | zoom_level = static_cast<int>(old_zoom_level); |
| 4827 | } |
| 4828 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4829 | webview()->setZoomLevel(false, zoom_level); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4830 | zoomLevelChanged(); |
| 4831 | } |
| 4832 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4833 | void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x, |
| 4834 | int zoom_center_y) { |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4835 | ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y, |
| 4836 | kScalingIncrementForGesture); |
| 4837 | } |
| 4838 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4839 | void RenderViewImpl::ZoomFactorHelper(PageZoom zoom, |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4840 | int zoom_center_x, |
| 4841 | int zoom_center_y, |
| 4842 | float scaling_increment) { |
| 4843 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4844 | return; |
| 4845 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 4846 | double old_page_scale_factor = webview()->pageScaleFactor(); |
| 4847 | double page_scale_factor; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4848 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 4849 | page_scale_factor = 1.0; |
| 4850 | } else { |
| 4851 | page_scale_factor = old_page_scale_factor + |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4852 | (zoom > 0 ? scaling_increment : -scaling_increment); |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 4853 | } |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4854 | if (page_scale_factor > 0) { |
[email protected] | 8519136 | 2011-11-08 18:53:09 | [diff] [blame] | 4855 | webview()->setPageScaleFactor(page_scale_factor, |
| 4856 | WebPoint(zoom_center_x, zoom_center_y)); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4857 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4858 | } |
| 4859 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4860 | void RenderViewImpl::OnSetZoomLevel(double zoom_level) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 4861 | webview()->hidePopups(); |
| 4862 | webview()->setZoomLevel(false, zoom_level); |
| 4863 | zoomLevelChanged(); |
| 4864 | } |
| 4865 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4866 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 4867 | double zoom_level) { |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 4868 | #if !defined(OS_ANDROID) |
| 4869 | // On Android, page zoom isn't used, and in case of WebView, text zoom is used |
| 4870 | // for legacy WebView text scaling emulation. Thus, the code that resets |
| 4871 | // the zoom level from this map will be effectively resetting text zoom level. |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4872 | host_zoom_levels_[url] = zoom_level; |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 4873 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4874 | } |
| 4875 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4876 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4877 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4878 | } |
| 4879 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4880 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4881 | WebString no_encoding; |
| 4882 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4883 | } |
| 4884 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4885 | WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4886 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4887 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4888 | |
| 4889 | // xpath string can represent a frame deep down the tree (across multiple |
| 4890 | // frame DOMs). |
| 4891 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 4892 | // should break into 2 xpaths |
| 4893 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4894 | std::vector<string16> xpaths; |
| 4895 | base::SplitString(xpath, '\n', &xpaths); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4896 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4897 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4898 | for (std::vector<string16>::const_iterator i = xpaths.begin(); |
| 4899 | frame && i != xpaths.end(); ++i) { |
| 4900 | frame = frame->findChildByExpression(*i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4901 | } |
| 4902 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4903 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4904 | } |
| 4905 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4906 | void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, |
| 4907 | const string16& jscript, |
| 4908 | int id, |
| 4909 | bool notify_result) { |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 4910 | TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest", |
| 4911 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4912 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4913 | } |
| 4914 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4915 | void RenderViewImpl::OnPostMessageEvent( |
| 4916 | const ViewMsg_PostMessage_Params& params) { |
[email protected] | bf4a231 | 2013-04-23 00:32:11 | [diff] [blame] | 4917 | // TODO(nasko): Support sending to subframes. |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 4918 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4919 | |
| 4920 | // Find the source frame if it exists. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4921 | WebFrame* source_frame = NULL; |
| 4922 | if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 4923 | RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
| 4924 | if (source_view) |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 4925 | source_frame = source_view->webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | // Create an event with the message. The final parameter to initMessageEvent |
| 4929 | // is the last event ID, which is not used with postMessage. |
| 4930 | WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
| 4931 | WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 4932 | msg_event.initMessageEvent("message", |
| 4933 | // |canBubble| and |cancellable| are always false |
| 4934 | false, false, |
| 4935 | WebSerializedScriptValue::fromString(params.data), |
| 4936 | params.source_origin, source_frame, ""); |
| 4937 | |
| 4938 | // We must pass in the target_origin to do the security check on this side, |
| 4939 | // since it may have changed since the original postMessage call was made. |
| 4940 | WebSecurityOrigin target_origin; |
| 4941 | if (!params.target_origin.empty()) { |
| 4942 | target_origin = |
| 4943 | WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 4944 | } |
| 4945 | frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 4946 | } |
| 4947 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4948 | void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath, |
| 4949 | const std::string& css) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4950 | WebFrame* frame = GetChildFrame(frame_xpath); |
| 4951 | if (!frame) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 4952 | return; |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 4953 | |
[email protected] | 01cf589c | 2011-07-28 18:04:03 | [diff] [blame] | 4954 | frame->document().insertUserStyleSheet( |
| 4955 | WebString::fromUTF8(css), |
| 4956 | WebDocument::UserStyleAuthorLevel); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4957 | } |
| 4958 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4959 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 4960 | if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && |
| 4961 | !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { |
[email protected] | dcc72db | 2013-01-02 00:44:18 | [diff] [blame] | 4962 | RenderThread::Get()->RegisterExtension(WebUIExtension::Get()); |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 4963 | new WebUIExtensionData(this); |
| 4964 | } |
| 4965 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4966 | enabled_bindings_ |= enabled_bindings_flags; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 4967 | |
| 4968 | // Keep track of the total bindings accumulated in this process. |
| 4969 | RenderProcess::current()->AddBindings(enabled_bindings_flags); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4970 | } |
| 4971 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 4972 | void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4973 | const gfx::Point& client_point, |
| 4974 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4975 | WebDragOperationsMask ops, |
| 4976 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4977 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 4978 | DropDataToWebDragData(drop_data), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4979 | client_point, |
| 4980 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4981 | ops, |
| 4982 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4983 | |
| 4984 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 4985 | } |
| 4986 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4987 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 4988 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4989 | WebDragOperationsMask ops, |
| 4990 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4991 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 4992 | client_point, |
| 4993 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4994 | ops, |
| 4995 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4996 | |
| 4997 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 4998 | } |
| 4999 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5000 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5001 | webview()->dragTargetDragLeave(); |
| 5002 | } |
| 5003 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5004 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5005 | const gfx::Point& screen_point, |
| 5006 | int key_modifiers) { |
| 5007 | webview()->dragTargetDrop(client_point, screen_point, key_modifiers); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 5008 | |
| 5009 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5010 | } |
| 5011 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5012 | void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 5013 | const gfx::Point& screen_point, |
| 5014 | bool ended, |
| 5015 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5016 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5017 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 5018 | } else { |
| 5019 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5020 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5021 | } |
| 5022 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5023 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5024 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5025 | } |
| 5026 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5027 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 5028 | webkit_preferences_ = prefs; |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 5029 | webkit_glue::ApplyWebPreferences(webkit_preferences_, webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5030 | } |
| 5031 | |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 5032 | void RenderViewImpl::OnUpdateTimezone() { |
| 5033 | if (webview()) |
| 5034 | NotifyTimezoneChange(webview()->mainFrame()); |
| 5035 | } |
| 5036 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5037 | void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5038 | alternate_error_page_url_ = url; |
| 5039 | } |
| 5040 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5041 | void RenderViewImpl::OnCustomContextMenuAction( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5042 | const CustomContextMenuContext& custom_context, |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5043 | unsigned action) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5044 | if (custom_context.request_id) { |
| 5045 | // External context menu request, look in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5046 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5047 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 5048 | if (client) |
| 5049 | client->OnMenuAction(custom_context.request_id, action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5050 | } else { |
| 5051 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5052 | webview()->performCustomContextMenuAction(action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5053 | } |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 5054 | } |
| 5055 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5056 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5057 | int id, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 5058 | const std::vector<base::FilePath>& paths) { |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5059 | if (!enumeration_completions_[id]) |
| 5060 | return; |
| 5061 | |
| 5062 | WebVector<WebString> ws_file_names(paths.size()); |
| 5063 | for (size_t i = 0; i < paths.size(); ++i) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5064 | ws_file_names[i] = paths[i].AsUTF16Unsafe(); |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5065 | |
| 5066 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 5067 | enumeration_completions_.erase(id); |
| 5068 | } |
| 5069 | |
[email protected] | fb11b6a4 | 2012-03-14 07:25:12 | [diff] [blame] | 5070 | void RenderViewImpl::OnFileChooserResponse( |
[email protected] | ddb034b | 2012-06-26 20:31:39 | [diff] [blame] | 5071 | const std::vector<ui::SelectedFileInfo>& files) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5072 | // This could happen if we navigated to a different page before the user |
| 5073 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5074 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5075 | return; |
| 5076 | |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5077 | // Convert Chrome's SelectedFileInfo list to WebKit's. |
| 5078 | WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files( |
| 5079 | files.size()); |
| 5080 | for (size_t i = 0; i < files.size(); ++i) { |
| 5081 | WebFileChooserCompletion::SelectedFileInfo selected_file; |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5082 | selected_file.path = files[i].local_path.AsUTF16Unsafe(); |
| 5083 | selected_file.displayName = |
| 5084 | base::FilePath(files[i].display_name).AsUTF16Unsafe(); |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5085 | selected_files[i] = selected_file; |
| 5086 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 5087 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5088 | if (file_chooser_completions_.front()->completion) |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5089 | file_chooser_completions_.front()->completion->didChooseFile( |
| 5090 | selected_files); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5091 | file_chooser_completions_.pop_front(); |
| 5092 | |
| 5093 | // If there are more pending file chooser requests, schedule one now. |
| 5094 | if (!file_chooser_completions_.empty()) { |
| 5095 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 5096 | file_chooser_completions_.front()->params)); |
| 5097 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5098 | } |
| 5099 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5100 | void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
| 5101 | const gfx::Size& max_size) { |
| 5102 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5103 | if (!webview()) |
| 5104 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 5105 | auto_resize_mode_ = true; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5106 | webview()->enableAutoResizeMode(min_size, max_size); |
| 5107 | } |
| 5108 | |
| 5109 | void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) { |
| 5110 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5111 | if (!webview()) |
| 5112 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 5113 | auto_resize_mode_ = false; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5114 | webview()->disableAutoResizeMode(); |
| 5115 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 5116 | if (!new_size.IsEmpty()) { |
| 5117 | Resize(new_size, |
| 5118 | physical_backing_size_, |
| 5119 | overdraw_bottom_height_, |
| 5120 | resizer_rect_, |
| 5121 | is_fullscreen_, |
| 5122 | NO_RESIZE_ACK); |
| 5123 | } |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5124 | } |
| 5125 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 5126 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5127 | if (send_preferred_size_changes_) |
| 5128 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5129 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 5130 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5131 | // Start off with an initial preferred size notification (in case |
| 5132 | // |didUpdateLayout| was already called). |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 5133 | didUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 5134 | } |
| 5135 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5136 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5137 | const gfx::Size& disable_scrollbar_size_limit) { |
| 5138 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 5139 | } |
| 5140 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5141 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5142 | const RendererPreferences& renderer_prefs) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5143 | double old_zoom_level = renderer_preferences_.default_zoom_level; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5144 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 5145 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5146 | |
| 5147 | #if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5148 | if (renderer_prefs.use_custom_colors) { |
| 5149 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 5150 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
| 5151 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5152 | #if defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5153 | ui::NativeTheme::instance()->SetScrollbarColors( |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 5154 | renderer_prefs.thumb_inactive_color, |
| 5155 | renderer_prefs.thumb_active_color, |
| 5156 | renderer_prefs.track_color); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5157 | #endif // defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5158 | |
| 5159 | if (webview()) { |
| 5160 | #if defined(TOOLKIT_GTK) |
| 5161 | webview()->setScrollbarColors( |
| 5162 | renderer_prefs.thumb_inactive_color, |
| 5163 | renderer_prefs.thumb_active_color, |
| 5164 | renderer_prefs.track_color); |
| 5165 | #endif // defined(TOOLKIT_GTK) |
| 5166 | webview()->setSelectionColors( |
| 5167 | renderer_prefs.active_selection_bg_color, |
| 5168 | renderer_prefs.active_selection_fg_color, |
| 5169 | renderer_prefs.inactive_selection_bg_color, |
| 5170 | renderer_prefs.inactive_selection_fg_color); |
| 5171 | webview()->themeChanged(); |
| 5172 | } |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5173 | } |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5174 | #endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5175 | |
[email protected] | 107c053 | 2013-02-06 02:34:09 | [diff] [blame] | 5176 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 5177 | RenderThreadImpl::current()->SetFlingCurveParameters( |
| 5178 | renderer_prefs.touchpad_fling_profile, |
| 5179 | renderer_prefs.touchscreen_fling_profile); |
| 5180 | |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5181 | // If the zoom level for this page matches the old zoom default, and this |
| 5182 | // is not a plugin, update the zoom level to match the new default. |
| 5183 | if (webview() && !webview()->mainFrame()->document().isPluginDocument() && |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 5184 | !ZoomValuesEqual(old_zoom_level, |
| 5185 | renderer_preferences_.default_zoom_level) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5186 | ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5187 | webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level); |
| 5188 | zoomLevelChanged(); |
| 5189 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5190 | } |
| 5191 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5192 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 5193 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 5194 | if (webview()) |
| 5195 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 5196 | } |
| 5197 | |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 5198 | void RenderViewImpl::OnOrientationChangeEvent(int orientation) { |
| 5199 | webview()->mainFrame()->sendOrientationChangeEvent(orientation); |
| 5200 | } |
| 5201 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 5202 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 5203 | const WebPluginAction& action) { |
| 5204 | if (webview()) |
| 5205 | webview()->performPluginAction(action, location); |
| 5206 | } |
| 5207 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5208 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5209 | const GURL& page_url) { |
| 5210 | // Prepare list to storage all savable resource links. |
| 5211 | std::vector<GURL> resources_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5212 | std::vector<GURL> referrer_urls_list; |
| 5213 | std::vector<WebKit::WebReferrerPolicy> referrer_policies_list; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5214 | std::vector<GURL> frames_list; |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 5215 | SavableResourcesResult result(&resources_list, |
| 5216 | &referrer_urls_list, |
| 5217 | &referrer_policies_list, |
| 5218 | &frames_list); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5219 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5220 | // webkit/ doesn't know about Referrer. |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 5221 | if (!GetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5222 | webview(), |
| 5223 | page_url, |
| 5224 | &result, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5225 | const_cast<const char**>(GetSavableSchemes()))) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5226 | // If something is wrong when collecting all savable resource links, |
| 5227 | // send empty list to embedder(browser) to tell it failed. |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5228 | referrer_urls_list.clear(); |
| 5229 | referrer_policies_list.clear(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5230 | resources_list.clear(); |
| 5231 | frames_list.clear(); |
| 5232 | } |
| 5233 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5234 | std::vector<Referrer> referrers_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5235 | CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size()); |
| 5236 | for (unsigned i = 0; i < referrer_urls_list.size(); ++i) { |
| 5237 | referrers_list.push_back( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5238 | Referrer(referrer_urls_list[i], referrer_policies_list[i])); |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5239 | } |
| 5240 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5241 | // Send result of all savable resource links to embedder. |
| 5242 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 5243 | resources_list, |
| 5244 | referrers_list, |
| 5245 | frames_list)); |
| 5246 | } |
| 5247 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5248 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5249 | const std::vector<GURL>& links, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 5250 | const std::vector<base::FilePath>& local_paths, |
| 5251 | const base::FilePath& local_directory_name) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5252 | |
| 5253 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 5254 | WebVector<WebURL> weburl_links(links); |
| 5255 | |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5256 | // Convert std::vector of base::FilePath to WebVector<WebString> |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5257 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 5258 | for (size_t i = 0; i < local_paths.size(); i++) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5259 | webstring_paths[i] = local_paths[i].AsUTF16Unsafe(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5260 | |
| 5261 | WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links, |
| 5262 | webstring_paths, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5263 | local_directory_name.AsUTF16Unsafe()); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5264 | } |
| 5265 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5266 | void RenderViewImpl::OnShouldClose() { |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5267 | base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5268 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5269 | base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); |
| 5270 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, |
| 5271 | before_unload_start_time, |
| 5272 | before_unload_end_time)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5273 | } |
| 5274 | |
[email protected] | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 5275 | void RenderViewImpl::OnSwapOut() { |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5276 | // Only run unload if we're not swapped out yet, but send the ack either way. |
| 5277 | if (!is_swapped_out_) { |
| 5278 | // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 5279 | // different process. This involves running the unload handler and clearing |
| 5280 | // the page. Once WasSwappedOut is called, we also allow this process to |
| 5281 | // exit if there are no other active RenderViews in it. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5282 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5283 | // Send an UpdateState message before we get swapped out. |
| 5284 | SyncNavigationState(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5285 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5286 | // Synchronously run the unload handler before sending the ACK. |
| 5287 | webview()->dispatchUnloadEvent(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5288 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5289 | // Swap out and stop sending any IPC messages that are not ACKs. |
| 5290 | SetSwappedOut(true); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5291 | |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 5292 | // Now that we're swapped out and filtering IPC messages, stop loading to |
| 5293 | // ensure that no other in-progress navigation continues. We do this here |
| 5294 | // to avoid sending a DidStopLoading message to the browser process. |
| 5295 | OnStop(); |
| 5296 | |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 5297 | // Replace the page with a blank dummy URL. The unload handler will not be |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5298 | // run a second time, thanks to a check in FrameLoader::stopLoading. |
| 5299 | // TODO(creis): Need to add a better way to do this that avoids running the |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 5300 | // beforeunload handler. For now, we just run it a second time silently. |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5301 | NavigateToSwappedOutURL(webview()->mainFrame()); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 5302 | |
| 5303 | // Let WebKit know that this view is hidden so it can drop resources and |
| 5304 | // stop compositing. |
| 5305 | webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5306 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5307 | |
[email protected] | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 5308 | Send(new ViewHostMsg_SwapOut_ACK(routing_id_)); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5309 | } |
| 5310 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5311 | void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5312 | // We use loadRequest instead of loadHTMLString because the former commits |
| 5313 | // synchronously. Otherwise a new navigation can interrupt the navigation |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5314 | // to kSwappedOutURL. If that happens to be to the page we had been |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5315 | // showing, then WebKit will never send a commit and we'll be left spinning. |
[email protected] | 890b06ca | 2012-12-13 21:07:36 | [diff] [blame] | 5316 | CHECK(is_swapped_out_); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5317 | GURL swappedOutURL(kSwappedOutURL); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5318 | WebURLRequest request(swappedOutURL); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5319 | frame->loadRequest(request); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5320 | } |
| 5321 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5322 | void RenderViewImpl::OnClosePage() { |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 5323 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5324 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 5325 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 5326 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 5327 | // calling the FrameLoader's CloseURL method directly. This should be |
| 5328 | // revisited to avoid having two ways to close a page. Having a single way |
| 5329 | // to close that can run onunload is also useful for fixing |
| 5330 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5331 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5332 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5333 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5334 | } |
| 5335 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5336 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 5337 | #if defined(USE_AURA) |
| 5338 | // Aura doesn't care if we switch themes. |
| 5339 | #elif defined(OS_WIN) |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 5340 | ui::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 5341 | if (webview()) |
| 5342 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 5343 | #else // defined(OS_WIN) |
| 5344 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 5345 | NOTIMPLEMENTED(); |
| 5346 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5347 | } |
| 5348 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5349 | void RenderViewImpl::OnDisassociateFromPopupCount() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 5350 | if (decrement_shared_popup_at_destruction_) |
| 5351 | shared_popup_counter_->data--; |
| 5352 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 5353 | decrement_shared_popup_at_destruction_ = false; |
| 5354 | } |
| 5355 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5356 | bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 5357 | const WebURLError& error, |
| 5358 | bool replace) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5359 | // We only show alternate error pages in the main frame. They are |
| 5360 | // intended to assist the user when navigating, so there is not much |
| 5361 | // value in showing them for failed subframes. Ideally, we would be |
| 5362 | // able to use the TYPED transition type for this, but that flag is |
| 5363 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5364 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5365 | return false; |
| 5366 | |
| 5367 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 5368 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5369 | int ec = error.reason; |
| 5370 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 5371 | ec != net::ERR_CONNECTION_FAILED && |
| 5372 | ec != net::ERR_CONNECTION_REFUSED && |
| 5373 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5374 | ec != net::ERR_CONNECTION_TIMED_OUT) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5375 | return false; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5376 | } |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5377 | |
| 5378 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5379 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5380 | if (!error_page_url.is_valid()) |
| 5381 | return false; |
| 5382 | |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5383 | WebDataSource* ds = frame->provisionalDataSource(); |
| 5384 | const WebURLRequest& failed_request = ds->request(); |
| 5385 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5386 | // Load an empty page first so there is an immediate response to the error, |
| 5387 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5388 | frame->loadHTMLString(std::string(), |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5389 | GURL(kUnreachableWebDataURL), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5390 | error.unreachableURL, |
| 5391 | replace); |
| 5392 | |
| 5393 | // Now, create a fetcher for the error page and associate it with the data |
| 5394 | // source we just created via the LoadHTMLString call. That way if another |
| 5395 | // navigation occurs, the fetcher will get destroyed. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 5396 | InternalDocumentStateData* internal_data = |
| 5397 | InternalDocumentStateData::FromDataSource(frame->provisionalDataSource()); |
| 5398 | internal_data->set_alt_error_page_fetcher( |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5399 | new AltErrorPageResourceFetcher( |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5400 | error_page_url, frame, failed_request, error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 5401 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 5402 | base::Unretained(this)))); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5403 | return true; |
| 5404 | } |
| 5405 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5406 | void RenderViewImpl::AltErrorPageFinished(WebFrame* frame, |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5407 | const WebURLRequest& original_request, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5408 | const WebURLError& original_error, |
| 5409 | const std::string& html) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5410 | // Here, we replace the blank page we loaded previously. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 5411 | // If we failed to download the alternate error page, LoadNavigationErrorPage |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5412 | // will simply display a default error page. |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5413 | LoadNavigationErrorPage(frame, original_request, original_error, html, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5414 | } |
| 5415 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5416 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5417 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5418 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5419 | } |
| 5420 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5421 | void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5422 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5423 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5424 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 5425 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5426 | ShouldDisplayScrollbars(params.new_size.width(), |
| 5427 | params.new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5428 | } |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 5429 | UpdateScrollState(webview()->mainFrame()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5430 | } |
| 5431 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5432 | RenderWidget::OnResize(params); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5433 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 5434 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5435 | void RenderViewImpl::WillInitiatePaint() { |
| 5436 | // Notify the pepper plugins that we're about to paint. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5437 | pepper_helper_->ViewWillInitiatePaint(); |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5438 | } |
| 5439 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5440 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5441 | // Notify the pepper plugins that we've painted, and are waiting to flush. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5442 | pepper_helper_->ViewInitiatedPaint(); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5443 | } |
| 5444 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5445 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5446 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 5447 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 5448 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 5449 | // won't change out from under us. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5450 | pepper_helper_->ViewFlushedPaint(); |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 5451 | |
[email protected] | 5b1dec8c | 2012-02-07 04:35:38 | [diff] [blame] | 5452 | // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 5453 | // See crbug.com/112921. |
| 5454 | if (!webview()) |
| 5455 | return; |
| 5456 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5457 | WebFrame* main_frame = webview()->mainFrame(); |
| 5458 | |
| 5459 | // If we have a provisional frame we are between the start and commit stages |
| 5460 | // of loading and we don't want to save stats. |
| 5461 | if (!main_frame->provisionalDataSource()) { |
| 5462 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5463 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 5464 | InternalDocumentStateData* data = |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 5465 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 5466 | if (data->did_first_visually_non_empty_layout() && |
| 5467 | !data->did_first_visually_non_empty_paint()) { |
| 5468 | data->set_did_first_visually_non_empty_paint(true); |
| 5469 | Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_, |
| 5470 | page_id_)); |
| 5471 | } |
| 5472 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5473 | // TODO(jar): The following code should all be inside a method, probably in |
| 5474 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5475 | Time now = Time::Now(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5476 | if (document_state->first_paint_time().is_null()) { |
| 5477 | document_state->set_first_paint_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5478 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5479 | if (document_state->first_paint_after_load_time().is_null() && |
| 5480 | !document_state->finish_load_time().is_null()) { |
| 5481 | document_state->set_first_paint_after_load_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5482 | } |
| 5483 | } |
| 5484 | } |
| 5485 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5486 | webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint( |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5487 | const gfx::Rect& paint_bounds, |
| 5488 | TransportDIB** dib, |
| 5489 | gfx::Rect* location, |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 5490 | gfx::Rect* clip, |
| 5491 | float* scale_factor) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5492 | return pepper_helper_->GetBitmapForOptimizedPluginPaint( |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 5493 | paint_bounds, dib, location, clip, scale_factor); |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5494 | } |
| 5495 | |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5496 | gfx::Vector2d RenderViewImpl::GetScrollOffset() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5497 | WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5498 | return gfx::Vector2d(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 5499 | } |
| 5500 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5501 | void RenderViewImpl::OnClearFocusedNode() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5502 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5503 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5504 | } |
| 5505 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5506 | void RenderViewImpl::OnSetBackground(const SkBitmap& background) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5507 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5508 | webview()->setIsTransparent(!background.empty()); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 5509 | if (compositor_) |
| 5510 | compositor_->setHasTransparentBackground(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5511 | |
| 5512 | SetBackground(background); |
| 5513 | } |
| 5514 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5515 | void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) { |
| 5516 | if (accessibility_mode_ == new_mode) |
| 5517 | return; |
| 5518 | accessibility_mode_ = new_mode; |
| 5519 | if (renderer_accessibility_) { |
| 5520 | delete renderer_accessibility_; |
| 5521 | renderer_accessibility_ = NULL; |
| 5522 | } |
| 5523 | if (accessibility_mode_ == AccessibilityModeComplete) |
| 5524 | renderer_accessibility_ = new RendererAccessibilityComplete(this); |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 5525 | #if !defined(OS_ANDROID) |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5526 | else if (accessibility_mode_ == AccessibilityModeEditableTextOnly) |
| 5527 | renderer_accessibility_ = new RendererAccessibilityFocusOnly(this); |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 5528 | #endif |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5529 | } |
| 5530 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5531 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5532 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5533 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 5534 | |
| 5535 | #if defined(OS_MACOSX) |
| 5536 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5537 | for (plugin_it = plugin_delegates_.begin(); |
| 5538 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5539 | (*plugin_it)->SetWindowFocus(active); |
| 5540 | } |
| 5541 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5542 | } |
| 5543 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5544 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5545 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5546 | // Inform plugins that their container has changed visibility. |
| 5547 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5548 | for (plugin_it = plugin_delegates_.begin(); |
| 5549 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5550 | (*plugin_it)->SetContainerVisibility(visible); |
| 5551 | } |
| 5552 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5553 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5554 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 5555 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5556 | // Inform plugins that their window's frame has changed. |
| 5557 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5558 | for (plugin_it = plugin_delegates_.begin(); |
| 5559 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5560 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 5561 | } |
| 5562 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5563 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5564 | void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text, |
| 5565 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5566 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5567 | // applies to it or not, so inform all the delegates. |
| 5568 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5569 | for (plugin_it = plugin_delegates_.begin(); |
| 5570 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5571 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5572 | } |
| 5573 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5574 | #endif // OS_MACOSX |
| 5575 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5576 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5577 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5578 | WebView* doomed = webview(); |
| 5579 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 5580 | g_view_map.Get().erase(doomed); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 5581 | g_routing_id_view_map.Get().erase(routing_id_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5582 | } |
| 5583 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5584 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 5585 | ClearEditCommands(); |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5586 | } |
| 5587 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5588 | bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 5589 | context_menu_source_type_ = ui::MENU_SOURCE_MOUSE; |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5590 | possible_drag_event_info_.event_source = |
| 5591 | ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 5592 | possible_drag_event_info_.event_location = |
| 5593 | gfx::Point(event.globalX, event.globalY); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5594 | pepper_helper_->WillHandleMouseEvent(); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 5595 | |
| 5596 | // If the mouse is locked, only the current owner of the mouse lock can |
| 5597 | // process mouse events. |
| 5598 | return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 5599 | } |
| 5600 | |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 5601 | bool RenderViewImpl::WillHandleKeyEvent(const WebKit::WebKeyboardEvent& event) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 5602 | context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD; |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 5603 | return false; |
| 5604 | } |
| 5605 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5606 | bool RenderViewImpl::WillHandleGestureEvent( |
| 5607 | const WebKit::WebGestureEvent& event) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 5608 | context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5609 | possible_drag_event_info_.event_source = |
| 5610 | ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH; |
| 5611 | possible_drag_event_info_.event_location = |
| 5612 | gfx::Point(event.globalX, event.globalY); |
| 5613 | return false; |
| 5614 | } |
| 5615 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 5616 | void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 5617 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5618 | } |
| 5619 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5620 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 5621 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 5622 | } |
| 5623 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 5624 | bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const { |
| 5625 | if (!webview()) |
| 5626 | return false; |
| 5627 | return webview()->hasTouchEventHandlersAt(point); |
| 5628 | } |
| 5629 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5630 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5631 | RenderWidget::OnWasHidden(); |
| 5632 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 5633 | #if defined(OS_ANDROID) |
[email protected] | bc42744 | 2013-07-13 02:53:08 | [diff] [blame] | 5634 | // Inform RendererMediaPlayerManager to release all media player resources. |
[email protected] | 1c36bea | 2013-07-01 13:43:01 | [diff] [blame] | 5635 | // unless some audio is playing. |
[email protected] | 263135d | 2012-11-15 13:01:56 | [diff] [blame] | 5636 | // If something is in progress the resource will not be freed, it will |
| 5637 | // only be freed once the tab is destroyed or if the user navigates away |
| 5638 | // via WebMediaPlayerAndroid::Destroy |
[email protected] | 1c36bea | 2013-07-01 13:43:01 | [diff] [blame] | 5639 | media_player_manager_->ReleaseMediaResources(); |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 5640 | |
| 5641 | #if defined(ENABLE_WEBRTC) |
| 5642 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 5643 | SuspendDevices(true); |
| 5644 | #endif |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 5645 | #endif |
| 5646 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 5647 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5648 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5649 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5650 | // Inform PPAPI plugins that their page is no longer visible. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5651 | pepper_helper_->PageVisibilityChanged(false); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5652 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5653 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5654 | // Inform NPAPI plugins that their container is no longer visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5655 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5656 | for (plugin_it = plugin_delegates_.begin(); |
| 5657 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5658 | (*plugin_it)->SetContainerVisibility(false); |
| 5659 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5660 | #endif // OS_MACOSX |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5661 | } |
| 5662 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 5663 | void RenderViewImpl::OnWasShown(bool needs_repainting) { |
| 5664 | RenderWidget::OnWasShown(needs_repainting); |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5665 | |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 5666 | #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 5667 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 5668 | SuspendDevices(false); |
| 5669 | #endif |
| 5670 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 5671 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5672 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5673 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5674 | // Inform PPAPI plugins that their page is visible. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5675 | pepper_helper_->PageVisibilityChanged(true); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5676 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5677 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5678 | // Inform NPAPI plugins that their container is now visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5679 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5680 | for (plugin_it = plugin_delegates_.begin(); |
| 5681 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5682 | (*plugin_it)->SetContainerVisibility(true); |
| 5683 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5684 | #endif // OS_MACOSX |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5685 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5686 | |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 5687 | GURL RenderViewImpl::GetURLForGraphicsContext3D() { |
| 5688 | DCHECK(webview()); |
| 5689 | if (webview()->mainFrame()) |
| 5690 | return GURL(webview()->mainFrame()->document().url()); |
| 5691 | else |
| 5692 | return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5693 | } |
| 5694 | |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 5695 | bool RenderViewImpl::ForceCompositingModeEnabled() { |
| 5696 | return webkit_preferences_.force_compositing_mode; |
| 5697 | } |
| 5698 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5699 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5700 | RenderWidget::OnSetFocus(enable); |
| 5701 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5702 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5703 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5704 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5705 | for (plugin_it = plugin_delegates_.begin(); |
| 5706 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5707 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5708 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5709 | // activation state to change just like a call to setIsActive. |
| 5710 | if (enable) |
| 5711 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5712 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5713 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5714 | } |
| 5715 | } |
[email protected] | a01da568 | 2012-06-30 00:37:31 | [diff] [blame] | 5716 | // Notify all Pepper plugins. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5717 | pepper_helper_->OnSetFocus(enable); |
[email protected] | 32103299 | 2012-11-08 01:01:27 | [diff] [blame] | 5718 | // Notify all BrowserPlugins of the RenderView's focus state. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 5719 | if (browser_plugin_manager_.get()) |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 5720 | browser_plugin_manager_->UpdateFocusState(); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5721 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5722 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5723 | void RenderViewImpl::PpapiPluginFocusChanged() { |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 5724 | UpdateTextInputType(); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5725 | UpdateSelectionBounds(); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5726 | } |
| 5727 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5728 | void RenderViewImpl::PpapiPluginTextInputTypeChanged() { |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 5729 | UpdateTextInputType(); |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 5730 | if (renderer_accessibility_) |
| 5731 | renderer_accessibility_->FocusedNodeChanged(WebNode()); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5732 | } |
| 5733 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5734 | void RenderViewImpl::PpapiPluginCaretPositionChanged() { |
| 5735 | UpdateSelectionBounds(); |
| 5736 | } |
| 5737 | |
[email protected] | b25b3ee | 2012-01-13 05:19:54 | [diff] [blame] | 5738 | bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5739 | if (!pepper_helper_->IsPluginFocused()) |
[email protected] | b25b3ee | 2012-01-13 05:19:54 | [diff] [blame] | 5740 | return false; |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5741 | *rect = pepper_helper_->GetCaretBounds(); |
[email protected] | b25b3ee | 2012-01-13 05:19:54 | [diff] [blame] | 5742 | return true; |
| 5743 | } |
| 5744 | |
[email protected] | 397c2396 | 2012-05-21 07:09:32 | [diff] [blame] | 5745 | void RenderViewImpl::SimulateImeSetComposition( |
| 5746 | const string16& text, |
| 5747 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 5748 | int selection_start, |
| 5749 | int selection_end) { |
| 5750 | OnImeSetComposition(text, underlines, selection_start, selection_end); |
| 5751 | } |
| 5752 | |
| 5753 | void RenderViewImpl::SimulateImeConfirmComposition( |
| 5754 | const string16& text, |
| 5755 | const ui::Range& replacement_range) { |
[email protected] | 0e45bd0 | 2013-07-12 20:20:02 | [diff] [blame] | 5756 | OnImeConfirmComposition(text, replacement_range, false); |
[email protected] | 397c2396 | 2012-05-21 07:09:32 | [diff] [blame] | 5757 | } |
| 5758 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5759 | void RenderViewImpl::PpapiPluginCancelComposition() { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 5760 | Send(new ViewHostMsg_ImeCancelComposition(routing_id()));; |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 5761 | #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA) |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 5762 | UpdateCompositionInfo(true); |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 5763 | #endif |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5764 | } |
| 5765 | |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 5766 | void RenderViewImpl::PpapiPluginSelectionChanged() { |
| 5767 | SyncSelectionIfRequired(); |
| 5768 | } |
| 5769 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5770 | void RenderViewImpl::PpapiPluginCreated(RendererPpapiHost* host) { |
[email protected] | 236bf85 | 2012-07-27 22:49:36 | [diff] [blame] | 5771 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 5772 | DidCreatePepperPlugin(host)); |
| 5773 | } |
| 5774 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5775 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5776 | const string16& text, |
| 5777 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 5778 | int selection_start, |
| 5779 | int selection_end) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5780 | if (pepper_helper_->IsPluginFocused()) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5781 | // When a PPAPI plugin has focus, we bypass WebKit. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5782 | pepper_helper_->OnImeSetComposition(text, |
| 5783 | underlines, |
| 5784 | selection_start, |
| 5785 | selection_end); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5786 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5787 | #if defined(OS_WIN) |
| 5788 | // When a plug-in has focus, we create platform-specific IME data used by |
| 5789 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 5790 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 5791 | // instance ID is the same one as the specified ID.) |
| 5792 | if (focused_plugin_id_ >= 0) { |
| 5793 | std::vector<int> clauses; |
| 5794 | std::vector<int> target; |
| 5795 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 5796 | clauses.push_back(underlines[i].startOffset); |
| 5797 | clauses.push_back(underlines[i].endOffset); |
| 5798 | if (underlines[i].thick) { |
| 5799 | target.clear(); |
| 5800 | target.push_back(underlines[i].startOffset); |
| 5801 | target.push_back(underlines[i].endOffset); |
| 5802 | } |
| 5803 | } |
| 5804 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5805 | for (it = plugin_delegates_.begin(); |
| 5806 | it != plugin_delegates_.end(); ++it) { |
| 5807 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 5808 | focused_plugin_id_); |
| 5809 | } |
| 5810 | return; |
| 5811 | } |
| 5812 | #endif |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5813 | RenderWidget::OnImeSetComposition(text, |
| 5814 | underlines, |
| 5815 | selection_start, |
| 5816 | selection_end); |
| 5817 | } |
| 5818 | } |
| 5819 | |
[email protected] | 0e45bd0 | 2013-07-12 20:20:02 | [diff] [blame] | 5820 | void RenderViewImpl::OnImeConfirmComposition(const string16& text, |
| 5821 | const ui::Range& replacement_range, |
| 5822 | bool keep_selection) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5823 | if (pepper_helper_->IsPluginFocused()) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5824 | // When a PPAPI plugin has focus, we bypass WebKit. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5825 | pepper_helper_->OnImeConfirmComposition(text); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5826 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5827 | #if defined(OS_WIN) |
| 5828 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 5829 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 5830 | // it to WebKit to prevent WebKit from controlling IMEs. |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 5831 | // TODO(thakis): Honor |replacement_range| for plugins? |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5832 | if (focused_plugin_id_ >= 0) { |
| 5833 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5834 | for (it = plugin_delegates_.begin(); |
| 5835 | it != plugin_delegates_.end(); ++it) { |
| 5836 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 5837 | } |
| 5838 | return; |
| 5839 | } |
| 5840 | #endif |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5841 | if (replacement_range.IsValid() && webview()) { |
| 5842 | // Select the text in |replacement_range|, it will then be replaced by |
| 5843 | // text added by the call to RenderWidget::OnImeConfirmComposition(). |
| 5844 | if (WebFrame* frame = webview()->focusedFrame()) { |
[email protected] | 4bacb82 | 2011-11-02 15:10:16 | [diff] [blame] | 5845 | WebRange webrange = WebRange::fromDocumentRange( |
| 5846 | frame, replacement_range.start(), replacement_range.length()); |
| 5847 | if (!webrange.isNull()) |
[email protected] | 884f900 | 2012-08-21 19:33:58 | [diff] [blame] | 5848 | frame->selectRange(webrange); |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5849 | } |
| 5850 | } |
[email protected] | 0e45bd0 | 2013-07-12 20:20:02 | [diff] [blame] | 5851 | RenderWidget::OnImeConfirmComposition(text, |
| 5852 | replacement_range, |
| 5853 | keep_selection); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5854 | } |
| 5855 | } |
| 5856 | |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 5857 | void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) { |
| 5858 | RenderWidget::SetDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 5859 | if (webview()) { |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 5860 | webview()->setDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 5861 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 5862 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 5863 | webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled( |
| 5864 | ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_)); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 5865 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 5866 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 5867 | webview()->settings()-> |
| 5868 | setAcceleratedCompositingForFixedRootBackgroundEnabled( |
| 5869 | ShouldUseAcceleratedFixedRootBackground(device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 5870 | } |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 5871 | if (auto_resize_mode_) |
| 5872 | AutoResizeCompositor(); |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 5873 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 5874 | if (browser_plugin_manager_.get()) |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 5875 | browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_); |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 5876 | } |
| 5877 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5878 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5879 | return pepper_helper_->IsPluginFocused() ? |
| 5880 | pepper_helper_->GetTextInputType() : RenderWidget::GetTextInputType(); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5881 | } |
| 5882 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5883 | void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5884 | if (pepper_helper_->IsPluginFocused()) { |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5885 | // TODO(kinaba) http://crbug.com/101101 |
| 5886 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 5887 | // use the caret position as an empty range for now. It will be updated |
| 5888 | // after Pepper API equips features related to surrounding text retrieval. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5889 | gfx::Rect caret = pepper_helper_->GetCaretBounds(); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5890 | *start = caret; |
| 5891 | *end = caret; |
| 5892 | return; |
| 5893 | } |
| 5894 | RenderWidget::GetSelectionBounds(start, end); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 5895 | } |
| 5896 | |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 5897 | #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA) |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 5898 | void RenderViewImpl::GetCompositionCharacterBounds( |
| 5899 | std::vector<gfx::Rect>* bounds) { |
| 5900 | DCHECK(bounds); |
| 5901 | bounds->clear(); |
| 5902 | |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 5903 | if (pepper_helper_->IsPluginFocused()) { |
| 5904 | return; |
| 5905 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 5906 | if (!webview()) |
| 5907 | return; |
| 5908 | size_t start_offset = 0; |
| 5909 | size_t character_count = 0; |
| 5910 | if (!webview()->compositionRange(&start_offset, &character_count)) |
| 5911 | return; |
| 5912 | if (character_count == 0) |
| 5913 | return; |
| 5914 | |
| 5915 | WebKit::WebFrame* frame = webview()->focusedFrame(); |
| 5916 | if (!frame) |
| 5917 | return; |
| 5918 | |
| 5919 | bounds->reserve(character_count); |
| 5920 | WebKit::WebRect webrect; |
| 5921 | for (size_t i = 0; i < character_count; ++i) { |
| 5922 | if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { |
| 5923 | DLOG(ERROR) << "Could not retrieve character rectangle at " << i; |
| 5924 | bounds->clear(); |
| 5925 | return; |
| 5926 | } |
| 5927 | bounds->push_back(webrect); |
| 5928 | } |
| 5929 | } |
| 5930 | |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 5931 | void RenderViewImpl::GetCompositionRange(ui::Range* range) { |
| 5932 | if (pepper_helper_->IsPluginFocused()) { |
| 5933 | return; |
| 5934 | } |
| 5935 | RenderWidget::GetCompositionRange(range); |
| 5936 | } |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 5937 | #endif |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 5938 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5939 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5940 | return pepper_helper_->IsPluginFocused() ? |
| 5941 | pepper_helper_->CanComposeInline() : true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5942 | } |
| 5943 | |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 5944 | void RenderViewImpl::InstrumentWillBeginFrame() { |
| 5945 | if (!webview()) |
| 5946 | return; |
| 5947 | if (!webview()->devToolsAgent()) |
| 5948 | return; |
| 5949 | webview()->devToolsAgent()->didBeginFrame(); |
| 5950 | } |
| 5951 | |
| 5952 | void RenderViewImpl::InstrumentDidBeginFrame() { |
| 5953 | if (!webview()) |
| 5954 | return; |
| 5955 | if (!webview()->devToolsAgent()) |
| 5956 | return; |
| 5957 | // TODO(jamesr/caseq): Decide if this needs to be renamed. |
| 5958 | webview()->devToolsAgent()->didComposite(); |
| 5959 | } |
| 5960 | |
| 5961 | void RenderViewImpl::InstrumentDidCancelFrame() { |
| 5962 | if (!webview()) |
| 5963 | return; |
| 5964 | if (!webview()->devToolsAgent()) |
| 5965 | return; |
| 5966 | webview()->devToolsAgent()->didCancelFrame(); |
| 5967 | } |
| 5968 | |
| 5969 | void RenderViewImpl::InstrumentWillComposite() { |
| 5970 | if (!webview()) |
| 5971 | return; |
| 5972 | if (!webview()->devToolsAgent()) |
| 5973 | return; |
| 5974 | webview()->devToolsAgent()->willComposite(); |
| 5975 | } |
| 5976 | |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 5977 | bool RenderViewImpl::AllowPartialSwap() const { |
| 5978 | return allow_partial_swap_; |
| 5979 | } |
| 5980 | |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5981 | #if defined(OS_WIN) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5982 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5983 | if (focused) |
| 5984 | focused_plugin_id_ = plugin_id; |
| 5985 | else |
| 5986 | focused_plugin_id_ = -1; |
| 5987 | } |
| 5988 | #endif |
| 5989 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5990 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5991 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5992 | Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5993 | } |
| 5994 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5995 | void RenderViewImpl::StartPluginIme() { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5996 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5997 | // This message can be sent during event-handling, and needs to be delivered |
| 5998 | // within that context. |
| 5999 | msg->set_unblock(true); |
| 6000 | Send(msg); |
| 6001 | } |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 6002 | #endif // defined(OS_MACOSX) |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 6003 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6004 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6005 | const FileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 6006 | WebFileChooserCompletion* completion) { |
| 6007 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 6008 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 6009 | // This sanity check prevents too many file choose requests from getting |
| 6010 | // queued which could DoS the user. Getting these is most likely a |
| 6011 | // programming error (there are many ways to DoS the user so it's not |
| 6012 | // considered a "real" security check), either in JS requesting many file |
| 6013 | // choosers to pop up, or in a plugin. |
| 6014 | // |
| 6015 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 6016 | // a file picker, which will address this issue in a better way. |
| 6017 | return false; |
| 6018 | } |
| 6019 | |
| 6020 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 6021 | new PendingFileChooser(params, completion))); |
| 6022 | if (file_chooser_completions_.size() == 1) { |
| 6023 | // Actually show the browse dialog when this is the first request. |
| 6024 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 6025 | } |
| 6026 | return true; |
| 6027 | } |
| 6028 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6029 | WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 6030 | if (!geolocation_dispatcher_) |
| 6031 | geolocation_dispatcher_ = new GeolocationDispatcher(this); |
| 6032 | return geolocation_dispatcher_; |
[email protected] | 7e0c470 | 2010-12-31 14:06:25 | [diff] [blame] | 6033 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6034 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6035 | WebKit::WebSpeechInputController* RenderViewImpl::speechInputController( |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6036 | WebKit::WebSpeechInputListener* listener) { |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6037 | #if defined(ENABLE_INPUT_SPEECH) |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6038 | if (!input_tag_speech_dispatcher_) |
| 6039 | input_tag_speech_dispatcher_ = |
| 6040 | new InputTagSpeechDispatcher(this, listener); |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6041 | #endif |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6042 | return input_tag_speech_dispatcher_; |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6043 | } |
| 6044 | |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6045 | WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6046 | if (!speech_recognition_dispatcher_) |
| 6047 | speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6048 | return speech_recognition_dispatcher_; |
| 6049 | } |
| 6050 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6051 | WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 6052 | if (!device_orientation_dispatcher_) |
| 6053 | device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this); |
| 6054 | return device_orientation_dispatcher_; |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 6055 | } |
| 6056 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6057 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 6058 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6059 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 6060 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 6061 | // different). |
| 6062 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 6063 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6064 | int minimum_percent = static_cast<int>( |
| 6065 | WebView::zoomLevelToZoomFactor(minimum_level) * 100); |
| 6066 | int maximum_percent = static_cast<int>( |
| 6067 | WebView::zoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6068 | |
| 6069 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 6070 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 6071 | } |
| 6072 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6073 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6074 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6075 | float zoom_level = webview()->zoomLevel(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 6076 | |
| 6077 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged()); |
| 6078 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6079 | // Tell the browser which url got zoomed so it can update the menu and the |
| 6080 | // saved values if necessary |
| 6081 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6082 | routing_id_, zoom_level, remember, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 6083 | GURL(webview()->mainFrame()->document().url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6084 | } |
| 6085 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6086 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
| 6087 | const WebString& base_url, |
| 6088 | const WebString& url, |
| 6089 | const WebString& title) { |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 6090 | bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6091 | GURL base(base_url); |
| 6092 | GURL absolute_url = base.Resolve(UTF16ToUTF8(url)); |
| 6093 | if (base.GetOrigin() != absolute_url.GetOrigin()) { |
| 6094 | return; |
| 6095 | } |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 6096 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
| 6097 | UTF16ToUTF8(scheme), |
| 6098 | absolute_url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 6099 | title, |
| 6100 | user_gesture)); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6101 | } |
| 6102 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6103 | WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6104 | WebKit::WebPageVisibilityState current_state = is_hidden() ? |
| 6105 | WebKit::WebPageVisibilityStateHidden : |
| 6106 | WebKit::WebPageVisibilityStateVisible; |
| 6107 | WebKit::WebPageVisibilityState override_state = current_state; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6108 | if (GetContentClient()->renderer()-> |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6109 | ShouldOverridePageVisibilityState(this, |
| 6110 | &override_state)) |
| 6111 | return override_state; |
| 6112 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 6113 | } |
| 6114 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6115 | WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 6116 | EnsureMediaStreamClient(); |
| 6117 | return web_user_media_client_; |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6118 | } |
| 6119 | |
[email protected] | a0629af9 | 2012-08-08 00:39:37 | [diff] [blame] | 6120 | void RenderViewImpl::draggableRegionsChanged() { |
| 6121 | FOR_EACH_OBSERVER( |
| 6122 | RenderViewObserver, |
| 6123 | observers_, |
| 6124 | DraggableRegionsChanged(webview()->mainFrame())); |
| 6125 | } |
| 6126 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6127 | #if defined(OS_ANDROID) |
| 6128 | WebContentDetectionResult RenderViewImpl::detectContentAround( |
| 6129 | const WebHitTestResult& touch_hit) { |
| 6130 | DCHECK(!touch_hit.isNull()); |
| 6131 | DCHECK(!touch_hit.node().isNull()); |
| 6132 | DCHECK(touch_hit.node().isTextNode()); |
| 6133 | |
| 6134 | // Process the position with all the registered content detectors until |
| 6135 | // a match is found. Priority is provided by their relative order. |
| 6136 | for (ContentDetectorList::const_iterator it = content_detectors_.begin(); |
| 6137 | it != content_detectors_.end(); ++it) { |
| 6138 | ContentDetector::Result content = (*it)->FindTappedContent(touch_hit); |
| 6139 | if (content.valid) { |
| 6140 | return WebContentDetectionResult(content.content_boundaries, |
| 6141 | UTF8ToUTF16(content.text), content.intent_url); |
| 6142 | } |
| 6143 | } |
| 6144 | return WebContentDetectionResult(); |
| 6145 | } |
| 6146 | |
| 6147 | void RenderViewImpl::scheduleContentIntent(const WebURL& intent) { |
| 6148 | // Introduce a short delay so that the user can notice the content. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 6149 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6150 | FROM_HERE, |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 6151 | base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, |
| 6152 | AsWeakPtr(), |
| 6153 | intent, |
| 6154 | expected_content_intent_id_), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6155 | base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); |
| 6156 | } |
| 6157 | |
| 6158 | void RenderViewImpl::cancelScheduledContentIntents() { |
| 6159 | ++expected_content_intent_id_; |
| 6160 | } |
| 6161 | |
| 6162 | void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, |
| 6163 | size_t request_id) { |
| 6164 | if (request_id != expected_content_intent_id_) |
| 6165 | return; |
| 6166 | |
| 6167 | // Remove the content highlighting if any. |
| 6168 | scheduleComposite(); |
| 6169 | |
| 6170 | if (!intent.is_empty()) |
| 6171 | Send(new ViewHostMsg_StartContentIntent(routing_id_, intent)); |
| 6172 | } |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 6173 | |
| 6174 | bool RenderViewImpl::openDateTimeChooser( |
| 6175 | const WebKit::WebDateTimeChooserParams& params, |
| 6176 | WebKit::WebDateTimeChooserCompletion* completion) { |
| 6177 | date_time_picker_client_.reset( |
| 6178 | new RendererDateTimePicker(this, params, completion)); |
| 6179 | return date_time_picker_client_->Open(); |
| 6180 | } |
| 6181 | |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6182 | #endif // defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6183 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6184 | void RenderViewImpl::OnAsyncFileOpened( |
| 6185 | base::PlatformFileError error_code, |
| 6186 | IPC::PlatformFileForTransit file_for_transit, |
| 6187 | int message_id) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6188 | pepper_helper_->OnAsyncFileOpened( |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 6189 | error_code, |
| 6190 | IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
| 6191 | message_id); |
| 6192 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6193 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6194 | void RenderViewImpl::OnPpapiBrokerChannelCreated( |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 6195 | int request_id, |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 6196 | base::ProcessId broker_pid, |
[email protected] | d5430507 | 2011-06-22 20:58:43 | [diff] [blame] | 6197 | const IPC::ChannelHandle& handle) { |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 6198 | pepper_helper_->OnPpapiBrokerChannelCreated(request_id, broker_pid, handle); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 6199 | } |
| 6200 | |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 6201 | void RenderViewImpl::OnPpapiBrokerPermissionResult( |
| 6202 | int request_id, |
| 6203 | bool result) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6204 | pepper_helper_->OnPpapiBrokerPermissionResult(request_id, result); |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 6205 | } |
| 6206 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6207 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6208 | void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) { |
[email protected] | 68dc3ba | 2010-12-06 21:43:15 | [diff] [blame] | 6209 | if (external_popup_menu_ == NULL) { |
| 6210 | // Crash reports from the field indicate that we can be notified with a |
| 6211 | // NULL external popup menu (we probably get notified twice). |
| 6212 | // If you hit this please file a bug against jcivelli and include the page |
| 6213 | // and steps to repro. |
| 6214 | NOTREACHED(); |
| 6215 | return; |
| 6216 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6217 | external_popup_menu_->DidSelectItem(selected_index); |
| 6218 | external_popup_menu_.reset(); |
| 6219 | } |
| 6220 | #endif |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 6221 | |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6222 | #if defined(OS_ANDROID) |
| 6223 | void RenderViewImpl::OnSelectPopupMenuItems( |
| 6224 | bool canceled, |
| 6225 | const std::vector<int>& selected_indices) { |
| 6226 | // It is possible to receive more than one of these calls if the user presses |
| 6227 | // a select faster than it takes for the show-select-popup IPC message to make |
| 6228 | // it to the browser UI thread. Ignore the extra-messages. |
| 6229 | // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 6230 | if (!external_popup_menu_) |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6231 | return; |
| 6232 | |
| 6233 | external_popup_menu_->DidSelectItems(canceled, selected_indices); |
| 6234 | external_popup_menu_.reset(); |
| 6235 | } |
| 6236 | #endif |
| 6237 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6238 | void RenderViewImpl::OnContextMenuClosed( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6239 | const CustomContextMenuContext& custom_context) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6240 | if (custom_context.request_id) { |
| 6241 | // External request, should be in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6242 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6243 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 6244 | if (client) { |
| 6245 | client->OnMenuClosed(custom_context.request_id); |
| 6246 | pending_context_menus_.Remove(custom_context.request_id); |
| 6247 | } |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6248 | } else { |
| 6249 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 6250 | context_menu_node_.reset(); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6251 | } |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 6252 | } |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6253 | |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 6254 | void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 6255 | context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU; |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 6256 | touch_editing_context_menu_location_ = location; |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 6257 | if (webview()) |
| 6258 | webview()->showContextMenu(); |
| 6259 | } |
| 6260 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6261 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6262 | if (!webview()) |
| 6263 | return; |
| 6264 | WebFrame* main_frame = webview()->mainFrame(); |
| 6265 | if (!main_frame) |
| 6266 | return; |
| 6267 | main_frame->enableViewSourceMode(true); |
| 6268 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 6269 | |
[email protected] | c7654a23 | 2013-06-12 21:04:44 | [diff] [blame] | 6270 | #if defined(OS_ANDROID) |
[email protected] | 64d0e19 | 2011-12-09 14:44:20 | [diff] [blame] | 6271 | void RenderViewImpl::OnJavaBridgeInit() { |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6272 | DCHECK(!java_bridge_dispatcher_); |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6273 | java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 6274 | } |
[email protected] | da81627 | 2013-05-15 21:31:17 | [diff] [blame] | 6275 | #endif |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 6276 | |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 6277 | void RenderViewImpl::OnDisownOpener() { |
| 6278 | if (!webview()) |
| 6279 | return; |
| 6280 | |
| 6281 | WebFrame* main_frame = webview()->mainFrame(); |
| 6282 | if (main_frame && main_frame->opener()) |
| 6283 | main_frame->setOpener(NULL); |
| 6284 | } |
| 6285 | |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6286 | #if defined(OS_ANDROID) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6287 | bool RenderViewImpl::didTapMultipleTargets( |
| 6288 | const WebKit::WebGestureEvent& event, |
| 6289 | const WebVector<WebRect>& target_rects) { |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 6290 | // Never show a disambiguation popup when accessibility is enabled, |
| 6291 | // as this interferes with "touch exploration". |
| 6292 | if (accessibility_mode_ == AccessibilityModeComplete) |
| 6293 | return false; |
| 6294 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6295 | gfx::Rect finger_rect( |
| 6296 | event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2, |
| 6297 | event.data.tap.width, event.data.tap.height); |
| 6298 | gfx::Rect zoom_rect; |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6299 | float new_total_scale = |
| 6300 | DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( |
| 6301 | finger_rect, target_rects, GetSize(), |
| 6302 | gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(), |
| 6303 | device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect); |
| 6304 | if (!new_total_scale) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6305 | return false; |
| 6306 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6307 | gfx::Size canvas_size = gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), |
| 6308 | new_total_scale)); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6309 | TransportDIB* transport_dib = NULL; |
| 6310 | { |
| 6311 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 6312 | RenderProcess::current()->GetDrawingCanvas(&transport_dib, |
| 6313 | gfx::Rect(canvas_size))); |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 6314 | if (!canvas) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6315 | return false; |
| 6316 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6317 | // TODO(trchen): Cleanup the device scale factor mess. |
| 6318 | // device scale will be applied in WebKit |
| 6319 | // --> zoom_rect doesn't include device scale, |
| 6320 | // but WebKit will still draw on zoom_rect * device_scale_factor_ |
| 6321 | canvas->scale(new_total_scale / device_scale_factor_, |
| 6322 | new_total_scale / device_scale_factor_); |
| 6323 | canvas->translate(-zoom_rect.x() * device_scale_factor_, |
| 6324 | -zoom_rect.y() * device_scale_factor_); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6325 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6326 | webwidget_->paint(webkit_glue::ToWebCanvas(canvas.get()), zoom_rect, |
| 6327 | WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent); |
| 6328 | } |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6329 | |
| 6330 | gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect( |
| 6331 | ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect))); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6332 | Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_, |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6333 | physical_window_zoom_rect, |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6334 | canvas_size, |
| 6335 | transport_dib->id())); |
| 6336 | |
| 6337 | return true; |
| 6338 | } |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6339 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6340 | |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 6341 | unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const { |
| 6342 | return history_list_length_; |
| 6343 | } |
| 6344 | |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 6345 | void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) { |
| 6346 | if (enable) { |
| 6347 | if (has_focus()) |
| 6348 | return; |
| 6349 | OnSetActive(true); |
| 6350 | OnSetFocus(true); |
| 6351 | } else { |
| 6352 | if (!has_focus()) |
| 6353 | return; |
| 6354 | OnSetFocus(false); |
| 6355 | OnSetActive(false); |
| 6356 | } |
| 6357 | } |
| 6358 | |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 6359 | void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) { |
[email protected] | b54fe45 | 2013-06-07 14:01:53 | [diff] [blame] | 6360 | ViewMsg_Resize_Params params; |
| 6361 | params.screen_info = screen_info_; |
| 6362 | params.screen_info.deviceScaleFactor = factor; |
| 6363 | params.new_size = size(); |
| 6364 | params.physical_backing_size = |
| 6365 | gfx::ToCeiledSize(gfx::ScaleSize(size(), factor)); |
| 6366 | params.overdraw_bottom_height = 0.f; |
| 6367 | params.resizer_rect = WebRect(); |
| 6368 | params.is_fullscreen = is_fullscreen(); |
| 6369 | OnResize(params); |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 6370 | } |
| 6371 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 6372 | void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size, |
| 6373 | const gfx::Size& max_size) { |
| 6374 | OnEnableAutoResize(min_size, max_size); |
| 6375 | } |
| 6376 | |
| 6377 | void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) { |
| 6378 | OnDisableAutoResize(new_size); |
| 6379 | } |
| 6380 | |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 6381 | void RenderViewImpl::SetMediaStreamClientForTesting( |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 6382 | MediaStreamClient* media_stream_client) { |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 6383 | DCHECK(!media_stream_client_); |
| 6384 | DCHECK(!web_user_media_client_); |
| 6385 | media_stream_client_ = media_stream_client; |
| 6386 | } |
| 6387 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6388 | void RenderViewImpl::OnReleaseDisambiguationPopupDIB( |
| 6389 | TransportDIB::Handle dib_handle) { |
| 6390 | TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
| 6391 | RenderProcess::current()->ReleaseTransportDIB(dib); |
| 6392 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6393 | |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 6394 | void RenderViewImpl::DidCommitCompositorFrame() { |
| 6395 | RenderWidget::DidCommitCompositorFrame(); |
| 6396 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame()); |
| 6397 | } |
| 6398 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 6399 | void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) { |
| 6400 | if (!urls.empty()) |
| 6401 | Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls)); |
| 6402 | } |
| 6403 | |
| 6404 | void RenderViewImpl::DidStopLoadingIcons() { |
| 6405 | int icon_types = WebIconURL::TypeFavicon; |
| 6406 | if (TouchEnabled()) |
| 6407 | icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
| 6408 | |
| 6409 | WebVector<WebIconURL> icon_urls = |
| 6410 | webview()->mainFrame()->iconURLs(icon_types); |
| 6411 | |
| 6412 | std::vector<FaviconURL> urls; |
| 6413 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 6414 | WebURL url = icon_urls[i].iconURL(); |
| 6415 | if (!url.isEmpty()) |
| 6416 | urls.push_back(FaviconURL(url, |
| 6417 | ToFaviconType(icon_urls[i].iconType()))); |
| 6418 | } |
| 6419 | SendUpdateFaviconURL(urls); |
| 6420 | } |
| 6421 | |
| 6422 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6423 | } // namespace content |