[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] | 28fccb3 | 2013-08-29 22:25:46 | [diff] [blame] | 18 | #include "base/i18n/char_iterator.h" |
[email protected] | b1cf337 | 2011-04-20 21:28:10 | [diff] [blame] | 19 | #include "base/json/json_writer.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 20 | #include "base/lazy_instance.h" |
[email protected] | cffd752 | 2012-10-23 19:10:58 | [diff] [blame] | 21 | #include "base/memory/scoped_ptr.h" |
[email protected] | 7ccb707 | 2013-06-10 20:56:28 | [diff] [blame] | 22 | #include "base/message_loop/message_loop_proxy.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 23 | #include "base/metrics/histogram.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 24 | #include "base/path_service.h" |
[email protected] | d3b4ee2 | 2013-07-24 22:50:06 | [diff] [blame] | 25 | #include "base/process/kill.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 26 | #include "base/strings/string_number_conversions.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 27 | #include "base/strings/string_piece.h" |
[email protected] | 27c0573 | 2013-02-15 21:55:49 | [diff] [blame] | 28 | #include "base/strings/string_split.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 29 | #include "base/strings/string_util.h" |
[email protected] | 40d11e0 | 2013-03-28 17:43:14 | [diff] [blame] | 30 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 31 | #include "base/strings/utf_string_conversions.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 32 | #include "base/time/time.h" |
[email protected] | a8cb3b73b | 2013-08-12 05:50:50 | [diff] [blame] | 33 | #include "content/child/appcache/appcache_dispatcher.h" |
| 34 | #include "content/child/appcache/web_application_cache_host_impl.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 35 | #include "content/child/child_thread.h" |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 36 | #include "content/child/npapi/webplugin_delegate_impl.h" |
[email protected] | 541b7b0 | 2013-06-07 00:59:34 | [diff] [blame] | 37 | #include "content/child/request_extra_data.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 38 | #include "content/child/webmessageportchannel_impl.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 39 | #include "content/common/clipboard_messages.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 40 | #include "content/common/database_messages.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 41 | #include "content/common/dom_storage/dom_storage_types.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] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 47 | #include "content/common/socket_stream_handle_data.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 48 | #include "content/common/ssl_status_serialization.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 49 | #include "content/common/view_messages.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 50 | #include "content/public/common/bindings_policy.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 51 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 52 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 53 | #include "content/public/common/content_switches.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 54 | #include "content/public/common/context_menu_params.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 55 | #include "content/public/common/drop_data.h" |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 56 | #include "content/public/common/favicon_url.h" |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 57 | #include "content/public/common/file_chooser_params.h" |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 58 | #include "content/public/common/page_zoom.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] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 68 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 69 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 70 | #include "content/public/renderer/web_preferences.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] | 7b77f6cb | 2013-07-25 16:23:14 | [diff] [blame] | 101 | #include "content/renderer/media/midi_dispatcher.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 102 | #include "content/renderer/media/render_media_log.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] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 109 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 110 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 111 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 112 | #include "content/renderer/render_view_impl_params.h" |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 113 | #include "content/renderer/render_view_mouse_lock_dispatcher.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 114 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 115 | #include "content/renderer/renderer_date_time_picker.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 116 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 117 | #include "content/renderer/renderer_webcolorchooser_impl.h" |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 118 | #include "content/renderer/savable_resources.h" |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 119 | #include "content/renderer/speech_recognition_dispatcher.h" |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 120 | #include "content/renderer/stats_collection_controller.h" |
| 121 | #include "content/renderer/stats_collection_observer.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 122 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 123 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 124 | #include "content/renderer/web_ui_extension.h" |
| 125 | #include "content/renderer/web_ui_extension_data.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 126 | #include "content/renderer/websharedworker_proxy.h" |
[email protected] | f596114 | 2013-04-17 23:09:42 | [diff] [blame] | 127 | #include "media/audio/audio_output_device.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 128 | #include "media/base/audio_renderer_mixer_input.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 129 | #include "media/base/filter_collection.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 130 | #include "media/base/media_switches.h" |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 131 | #include "media/filters/audio_renderer_impl.h" |
[email protected] | 1cad880 | 2013-08-13 16:54:32 | [diff] [blame] | 132 | #include "media/filters/gpu_video_accelerator_factories.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 133 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 134 | #include "net/base/escape.h" |
| 135 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 136 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 137 | #include "net/http/http_util.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 138 | #include "third_party/WebKit/public/platform/WebCString.h" |
| 139 | #include "third_party/WebKit/public/platform/WebDragData.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 140 | #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 141 | #include "third_party/WebKit/public/platform/WebImage.h" |
| 142 | #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 143 | #include "third_party/WebKit/public/platform/WebPoint.h" |
| 144 | #include "third_party/WebKit/public/platform/WebRect.h" |
| 145 | #include "third_party/WebKit/public/platform/WebSize.h" |
| 146 | #include "third_party/WebKit/public/platform/WebSocketStreamHandle.h" |
| 147 | #include "third_party/WebKit/public/platform/WebString.h" |
| 148 | #include "third_party/WebKit/public/platform/WebURL.h" |
| 149 | #include "third_party/WebKit/public/platform/WebURLError.h" |
| 150 | #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 151 | #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 152 | #include "third_party/WebKit/public/platform/WebVector.h" |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 153 | #include "third_party/WebKit/public/web/WebAXObject.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 154 | #include "third_party/WebKit/public/web/WebColorName.h" |
| 155 | #include "third_party/WebKit/public/web/WebDOMEvent.h" |
| 156 | #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" |
| 157 | #include "third_party/WebKit/public/web/WebDataSource.h" |
| 158 | #include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h" |
| 159 | #include "third_party/WebKit/public/web/WebDateTimeChooserParams.h" |
| 160 | #include "third_party/WebKit/public/web/WebDevToolsAgent.h" |
| 161 | #include "third_party/WebKit/public/web/WebDocument.h" |
| 162 | #include "third_party/WebKit/public/web/WebElement.h" |
| 163 | #include "third_party/WebKit/public/web/WebFileChooserParams.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 164 | #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 165 | #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 166 | #include "third_party/WebKit/public/web/WebFormElement.h" |
| 167 | #include "third_party/WebKit/public/web/WebFrame.h" |
[email protected] | 6bd867b | 2013-07-24 22:10:20 | [diff] [blame] | 168 | #include "third_party/WebKit/public/web/WebGlyphCache.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 169 | #include "third_party/WebKit/public/web/WebHelperPlugin.h" |
| 170 | #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 171 | #include "third_party/WebKit/public/web/WebInputElement.h" |
| 172 | #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 173 | #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" |
| 174 | #include "third_party/WebKit/public/web/WebNavigationPolicy.h" |
| 175 | #include "third_party/WebKit/public/web/WebNodeList.h" |
| 176 | #include "third_party/WebKit/public/web/WebPageSerializer.h" |
| 177 | #include "third_party/WebKit/public/web/WebPlugin.h" |
| 178 | #include "third_party/WebKit/public/web/WebPluginAction.h" |
| 179 | #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 180 | #include "third_party/WebKit/public/web/WebPluginDocument.h" |
| 181 | #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 182 | #include "third_party/WebKit/public/web/WebRange.h" |
[email protected] | 91f0576 | 2013-08-21 02:55:09 | [diff] [blame] | 183 | #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 184 | #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 185 | #include "third_party/WebKit/public/web/WebSearchableFormData.h" |
| 186 | #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 187 | #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 188 | #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
| 189 | #include "third_party/WebKit/public/web/WebSettings.h" |
| 190 | #include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h" |
| 191 | #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 192 | #include "third_party/WebKit/public/web/WebUserMediaClient.h" |
| 193 | #include "third_party/WebKit/public/web/WebView.h" |
| 194 | #include "third_party/WebKit/public/web/WebWindowFeatures.h" |
| 195 | #include "third_party/WebKit/public/web/default/WebRenderTheme.h" |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 196 | #include "ui/base/ui_base_switches_util.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 197 | #include "ui/gfx/native_widget_types.h" |
| 198 | #include "ui/gfx/point.h" |
| 199 | #include "ui/gfx/rect.h" |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 200 | #include "ui/gfx/rect_conversions.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 201 | #include "ui/gfx/size_conversions.h" |
[email protected] | 4344a3c | 2013-01-17 23:49:20 | [diff] [blame] | 202 | #include "ui/shell_dialogs/selected_file_info.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 203 | #include "v8/include/v8.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 204 | #include "webkit/child/weburlresponse_extradata_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 205 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 206 | #if defined(OS_ANDROID) |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 207 | #include <cpu-features.h> |
| 208 | |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 209 | #include "content/common/android/device_telephony_info.h" |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 210 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 211 | #include "content/renderer/android/address_detector.h" |
| 212 | #include "content/renderer/android/content_detector.h" |
| 213 | #include "content/renderer/android/email_detector.h" |
| 214 | #include "content/renderer/android/phone_number_detector.h" |
[email protected] | 3a59bb9 | 2013-08-22 18:54:08 | [diff] [blame] | 215 | #include "content/renderer/android/synchronous_compositor_factory.h" |
[email protected] | bc42744 | 2013-07-13 02:53:08 | [diff] [blame] | 216 | #include "content/renderer/media/android/renderer_media_player_manager.h" |
[email protected] | 3aaba57 | 2013-08-10 15:10:38 | [diff] [blame] | 217 | #include "content/renderer/media/android/stream_texture_factory_android_impl.h" |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 218 | #include "content/renderer/media/android/webmediaplayer_android.h" |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 219 | #include "content/renderer/media/android/webmediaplayer_proxy_android.h" |
[email protected] | c277d3c | 2013-07-15 21:49:37 | [diff] [blame] | 220 | #include "skia/ext/platform_canvas.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 221 | #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 222 | #include "third_party/WebKit/public/platform/WebFloatRect.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 223 | #include "third_party/WebKit/public/web/WebHitTestResult.h" |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 224 | #include "ui/gfx/rect_f.h" |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 225 | |
| 226 | #if defined(GOOGLE_TV) |
| 227 | #include "content/renderer/media/rtc_video_decoder_bridge_tv.h" |
| 228 | #include "content/renderer/media/rtc_video_decoder_factory_tv.h" |
| 229 | #endif |
| 230 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 231 | #elif defined(OS_WIN) |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 232 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 233 | // * theming |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 234 | #include "ui/native_theme/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 235 | #elif defined(USE_X11) |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 236 | #include "ui/native_theme/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 237 | #elif defined(OS_MACOSX) |
| 238 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 239 | #endif |
| 240 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 241 | #if defined(ENABLE_PLUGINS) |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 242 | #include "content/renderer/npapi/webplugin_delegate_proxy.h" |
| 243 | #include "content/renderer/npapi/webplugin_impl.h" |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 244 | #include "content/renderer/pepper/pepper_browser_connection.h" |
| 245 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 246 | #include "content/renderer/pepper/pepper_plugin_registry.h" |
| 247 | #include "content/renderer/pepper/pepper_webplugin_impl.h" |
| 248 | #include "content/renderer/pepper/plugin_module.h" |
| 249 | #endif |
| 250 | |
[email protected] | 9ac667e | 2013-09-09 12:49:21 | [diff] [blame] | 251 | #if defined(ENABLE_WEBRTC) |
| 252 | #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 253 | #endif |
| 254 | |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 255 | using WebKit::WebAXObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 256 | using WebKit::WebApplicationCacheHost; |
| 257 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 258 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 259 | using WebKit::WebColor; |
| 260 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 261 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 262 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 263 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 264 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 265 | using WebKit::WebDataSource; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 266 | using WebKit::WebDocument; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 267 | using WebKit::WebDOMEvent; |
| 268 | using WebKit::WebDOMMessageEvent; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 269 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 270 | using WebKit::WebDragOperation; |
| 271 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 272 | using WebKit::WebEditingAction; |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 273 | using WebKit::WebElement; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 274 | using WebKit::WebExternalPopupMenu; |
| 275 | using WebKit::WebExternalPopupMenuClient; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 276 | using WebKit::WebFileChooserCompletion; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 277 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 278 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 279 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 280 | using WebKit::WebFrame; |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 281 | using WebKit::WebGestureEvent; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 282 | using WebKit::WebHistoryItem; |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 283 | using WebKit::WebHTTPBody; |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 284 | using WebKit::WebIconURL; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 285 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 286 | using WebKit::WebInputElement; |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 287 | using WebKit::WebInputEvent; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 288 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 289 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 290 | using WebKit::WebMediaPlayerClient; |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 291 | using WebKit::WebMouseEvent; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 292 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 293 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 294 | using WebKit::WebNode; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 295 | using WebKit::WebPageSerializer; |
| 296 | using WebKit::WebPageSerializerClient; |
[email protected] | 50da23d0 | 2012-04-13 17:47:48 | [diff] [blame] | 297 | using WebKit::WebPeerConnection00Handler; |
| 298 | using WebKit::WebPeerConnection00HandlerClient; |
| 299 | using WebKit::WebPeerConnectionHandler; |
| 300 | using WebKit::WebPeerConnectionHandlerClient; |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 301 | using WebKit::WebPluginAction; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 302 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 303 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 304 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 305 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 306 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 307 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 308 | using WebKit::WebRect; |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 309 | using WebKit::WebReferrerPolicy; |
[email protected] | 91f0576 | 2013-08-21 02:55:09 | [diff] [blame] | 310 | using WebKit::WebRuntimeFeatures; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 311 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 312 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 313 | using WebKit::WebSecurityOrigin; |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 314 | using WebKit::WebSecurityPolicy; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 315 | using WebKit::WebSerializedScriptValue; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 316 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 317 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 318 | using WebKit::WebSize; |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 319 | using WebKit::WebSocketStreamHandle; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 320 | using WebKit::WebStorageNamespace; |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 321 | using WebKit::WebStorageQuotaCallbacks; |
| 322 | using WebKit::WebStorageQuotaError; |
| 323 | using WebKit::WebStorageQuotaType; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 324 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 325 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 326 | using WebKit::WebTextDirection; |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 327 | using WebKit::WebTouchEvent; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 328 | using WebKit::WebURL; |
| 329 | using WebKit::WebURLError; |
| 330 | using WebKit::WebURLRequest; |
| 331 | using WebKit::WebURLResponse; |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 332 | using WebKit::WebUserGestureIndicator; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 333 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 334 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 335 | using WebKit::WebWidget; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 336 | using WebKit::WebWindowFeatures; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 337 | using base::Time; |
| 338 | using base::TimeDelta; |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 339 | using webkit_glue::WebURLResponseExtraDataImpl; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 340 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 341 | #if defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 342 | using WebKit::WebContentDetectionResult; |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 343 | using WebKit::WebFloatPoint; |
| 344 | using WebKit::WebFloatRect; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 345 | using WebKit::WebHitTestResult; |
| 346 | #endif |
| 347 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 348 | namespace content { |
| 349 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 350 | //----------------------------------------------------------------------------- |
| 351 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 352 | typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 353 | static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 354 | typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap; |
| 355 | static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map = |
| 356 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 357 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 358 | // Time, in seconds, we delay before sending content state changes (such as form |
| 359 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 360 | // spamming the browser. |
| 361 | // To avoid having tab/session restore require sending a message to get the |
| 362 | // current content state during tab closing we use a shorter timeout for the |
| 363 | // foreground renderer. This means there is a small window of time from which |
| 364 | // content state is modified and not sent to session restore, but this is |
| 365 | // better than having to wake up all renderers during shutdown. |
| 366 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 367 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 368 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 369 | static const size_t kExtraCharsBeforeAndAfterSelection = 100; |
| 370 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 371 | static const float kScalingIncrement = 0.1f; |
| 372 | |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 373 | static const float kScalingIncrementForGesture = 0.01f; |
| 374 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 375 | #if defined(OS_ANDROID) |
| 376 | // Delay between tapping in content and launching the associated android intent. |
| 377 | // Used to allow users see what has been recognized as content. |
| 378 | static const size_t kContentIntentDelayMilliseconds = 700; |
| 379 | #endif |
| 380 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 381 | static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = |
| 382 | NULL; |
| 383 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 384 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 385 | // Replace any occurrences of swappedout:// with about:blank. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 386 | const WebURL& blank_url = GURL(kAboutBlankURL); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 387 | WebVector<WebURL> urls; |
| 388 | ds->redirectChain(urls); |
| 389 | result->reserve(urls.size()); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 390 | for (size_t i = 0; i < urls.size(); ++i) { |
| 391 | if (urls[i] != GURL(kSwappedOutURL)) |
| 392 | result->push_back(urls[i]); |
| 393 | else |
| 394 | result->push_back(blank_url); |
| 395 | } |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 396 | } |
| 397 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 398 | // If |data_source| is non-null and has an InternalDocumentStateData associated |
| 399 | // with it, the AltErrorPageResourceFetcher is reset. |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 400 | static void StopAltErrorPageFetcher(WebDataSource* data_source) { |
| 401 | if (data_source) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 402 | InternalDocumentStateData* internal_data = |
| 403 | InternalDocumentStateData::FromDataSource(data_source); |
| 404 | if (internal_data) |
| 405 | internal_data->set_alt_error_page_fetcher(NULL); |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 409 | static bool IsReload(const ViewMsg_Navigate_Params& params) { |
| 410 | return |
| 411 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 412 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE || |
| 413 | params.navigation_type == |
| 414 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 417 | // static |
| 418 | WebReferrerPolicy RenderViewImpl::GetReferrerPolicyFromRequest( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 419 | WebFrame* frame, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 420 | const WebURLRequest& request) { |
| 421 | return request.extraData() ? |
| 422 | static_cast<RequestExtraData*>(request.extraData())->referrer_policy() : |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 423 | frame->document().referrerPolicy(); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 424 | } |
| 425 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 426 | // static |
| 427 | Referrer RenderViewImpl::GetReferrerFromRequest( |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 428 | WebFrame* frame, |
| 429 | const WebURLRequest& request) { |
| 430 | return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 431 | GetReferrerPolicyFromRequest(frame, request)); |
| 432 | } |
| 433 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 434 | // static |
| 435 | WebURLResponseExtraDataImpl* RenderViewImpl::GetExtraDataFromResponse( |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 436 | const WebURLResponse& response) { |
| 437 | return static_cast<WebURLResponseExtraDataImpl*>( |
| 438 | response.extraData()); |
| 439 | } |
| 440 | |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 441 | NOINLINE static void CrashIntentionally() { |
| 442 | // NOTE(shess): Crash directly rather than using NOTREACHED() so |
| 443 | // that the signature is easier to triage in crash reports. |
| 444 | volatile int* zero = NULL; |
| 445 | *zero = 0; |
| 446 | } |
| 447 | |
[email protected] | 2132d6b | 2013-06-05 00:15:43 | [diff] [blame] | 448 | #if defined(ADDRESS_SANITIZER) |
| 449 | NOINLINE static void MaybeTriggerAsanError(const GURL& url) { |
| 450 | // NOTE(rogerm): We intentionally perform an invalid heap access here in |
| 451 | // order to trigger an Address Sanitizer (ASAN) error report. |
| 452 | static const char kCrashDomain[] = "crash"; |
| 453 | static const char kHeapOverflow[] = "/heap-overflow"; |
| 454 | static const char kHeapUnderflow[] = "/heap-underflow"; |
| 455 | static const char kUseAfterFree[] = "/use-after-free"; |
| 456 | static const int kArraySize = 5; |
| 457 | |
| 458 | if (!url.DomainIs(kCrashDomain, sizeof(kCrashDomain) - 1)) |
| 459 | return; |
| 460 | |
| 461 | if (!url.has_path()) |
| 462 | return; |
| 463 | |
| 464 | scoped_ptr<int[]> array(new int[kArraySize]); |
| 465 | std::string crash_type(url.path()); |
| 466 | int dummy = 0; |
| 467 | if (crash_type == kHeapOverflow) { |
| 468 | dummy = array[kArraySize]; |
| 469 | } else if (crash_type == kHeapUnderflow ) { |
| 470 | dummy = array[-1]; |
| 471 | } else if (crash_type == kUseAfterFree) { |
| 472 | int* dangling = array.get(); |
| 473 | array.reset(); |
| 474 | dummy = dangling[kArraySize / 2]; |
| 475 | } |
| 476 | |
| 477 | // Make sure the assignments to the dummy value aren't optimized away. |
| 478 | base::debug::Alias(&dummy); |
| 479 | } |
| 480 | #endif // ADDRESS_SANITIZER |
| 481 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 482 | static void MaybeHandleDebugURL(const GURL& url) { |
| 483 | if (!url.SchemeIs(chrome::kChromeUIScheme)) |
| 484 | return; |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 485 | if (url == GURL(kChromeUICrashURL)) { |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 486 | CrashIntentionally(); |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 487 | } else if (url == GURL(kChromeUIKillURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 488 | base::KillProcess(base::GetCurrentProcessHandle(), 1, false); |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 489 | } else if (url == GURL(kChromeUIHangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 490 | for (;;) { |
| 491 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 492 | } |
[email protected] | 50f86bc | 2012-11-01 19:59:13 | [diff] [blame] | 493 | } else if (url == GURL(kChromeUIShorthangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 494 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 495 | } |
[email protected] | 2132d6b | 2013-06-05 00:15:43 | [diff] [blame] | 496 | |
| 497 | #if defined(ADDRESS_SANITIZER) |
| 498 | MaybeTriggerAsanError(url); |
| 499 | #endif // ADDRESS_SANITIZER |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 500 | } |
| 501 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 502 | // Returns false unless this is a top-level navigation. |
| 503 | static bool IsTopLevelNavigation(WebFrame* frame) { |
| 504 | return frame->parent() == NULL; |
| 505 | } |
| 506 | |
| 507 | // Returns false unless this is a top-level navigation that crosses origins. |
| 508 | static bool IsNonLocalTopLevelNavigation(const GURL& url, |
| 509 | WebFrame* frame, |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 510 | WebNavigationType type, |
| 511 | bool is_form_post) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 512 | if (!IsTopLevelNavigation(frame)) |
| 513 | return false; |
| 514 | |
| 515 | // Navigations initiated within Webkit are not sent out to the external host |
| 516 | // in the following cases. |
| 517 | // 1. The url scheme is not http/https |
| 518 | // 2. The origin of the url and the opener is the same in which case the |
| 519 | // opener relationship is maintained. |
| 520 | // 3. Reloads/form submits/back forward navigations |
[email protected] | e9a8204 | 2013-09-15 03:38:29 | [diff] [blame] | 521 | if (!url.SchemeIs(kHttpScheme) && !url.SchemeIs(kHttpsScheme)) |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 522 | return false; |
| 523 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 524 | if (type != WebKit::WebNavigationTypeReload && |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 525 | type != WebKit::WebNavigationTypeBackForward && !is_form_post) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 526 | // The opener relationship between the new window and the parent allows the |
| 527 | // new window to script the parent and vice versa. This is not allowed if |
| 528 | // the origins of the two domains are different. This can be treated as a |
| 529 | // top level navigation and routed back to the host. |
| 530 | WebKit::WebFrame* opener = frame->opener(); |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 531 | if (!opener) |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 532 | return true; |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 533 | |
| 534 | if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
| 535 | return true; |
| 536 | } |
| 537 | return false; |
| 538 | } |
| 539 | |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 540 | static void NotifyTimezoneChange(WebKit::WebFrame* frame) { |
[email protected] | e1907b43 | 2013-09-04 16:11:14 | [diff] [blame] | 541 | v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 542 | v8::Context::Scope context_scope(frame->mainWorldScriptContext()); |
| 543 | v8::Date::DateTimeConfigurationChangeNotification(); |
| 544 | WebKit::WebFrame* child = frame->firstChild(); |
| 545 | for (; child; child = child->nextSibling()) |
| 546 | NotifyTimezoneChange(child); |
| 547 | } |
| 548 | |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 549 | static WindowOpenDisposition NavigationPolicyToDisposition( |
| 550 | WebNavigationPolicy policy) { |
| 551 | switch (policy) { |
| 552 | case WebKit::WebNavigationPolicyIgnore: |
| 553 | return IGNORE_ACTION; |
| 554 | case WebKit::WebNavigationPolicyDownload: |
| 555 | return SAVE_TO_DISK; |
| 556 | case WebKit::WebNavigationPolicyCurrentTab: |
| 557 | return CURRENT_TAB; |
| 558 | case WebKit::WebNavigationPolicyNewBackgroundTab: |
| 559 | return NEW_BACKGROUND_TAB; |
| 560 | case WebKit::WebNavigationPolicyNewForegroundTab: |
| 561 | return NEW_FOREGROUND_TAB; |
| 562 | case WebKit::WebNavigationPolicyNewWindow: |
| 563 | return NEW_WINDOW; |
| 564 | case WebKit::WebNavigationPolicyNewPopup: |
| 565 | return NEW_POPUP; |
| 566 | default: |
| 567 | NOTREACHED() << "Unexpected WebNavigationPolicy"; |
| 568 | return IGNORE_ACTION; |
| 569 | } |
| 570 | } |
| 571 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 572 | // Returns true if the device scale is high enough that losing subpixel |
| 573 | // antialiasing won't have a noticeable effect on text quality. |
| 574 | static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) { |
| 575 | #if defined(OS_ANDROID) |
| 576 | // On Android, we never have subpixel antialiasing. |
| 577 | return true; |
| 578 | #else |
| 579 | return device_scale_factor > 1.5f; |
| 580 | #endif |
| 581 | |
| 582 | } |
| 583 | |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 584 | static bool ShouldUseFixedPositionCompositing(float device_scale_factor) { |
| 585 | // Compositing for fixed-position elements is dependent on |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 586 | // device_scale_factor if no flag is set. http://crbug.com/172738 |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 587 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 588 | |
| 589 | if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition)) |
| 590 | return false; |
| 591 | |
| 592 | if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition)) |
| 593 | return true; |
| 594 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 595 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 596 | } |
| 597 | |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 598 | static bool ShouldUseAcceleratedCompositingForOverflowScroll( |
| 599 | float device_scale_factor) { |
| 600 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 601 | |
| 602 | if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll)) |
| 603 | return true; |
| 604 | |
| 605 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 606 | } |
| 607 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 608 | static bool ShouldUseTransitionCompositing(float device_scale_factor) { |
| 609 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 610 | |
| 611 | if (command_line.HasSwitch(switches::kDisableCompositingForTransition)) |
| 612 | return false; |
| 613 | |
| 614 | if (command_line.HasSwitch(switches::kEnableCompositingForTransition)) |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 615 | return true; |
| 616 | |
[email protected] | 9a7f6e1 | 2013-06-11 07:05:13 | [diff] [blame] | 617 | // TODO(ajuma): Re-enable this by default for high-DPI once the problem |
| 618 | // of excessive layer promotion caused by overlap has been addressed. |
| 619 | // http://crbug.com/178119. |
| 620 | return false; |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 621 | } |
| 622 | |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 623 | static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) { |
| 624 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 625 | |
| 626 | if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground)) |
| 627 | return false; |
| 628 | |
| 629 | if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground)) |
| 630 | return true; |
| 631 | |
| 632 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 633 | } |
| 634 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 635 | static FaviconURL::IconType ToFaviconType(WebKit::WebIconURL::Type type) { |
| 636 | switch (type) { |
| 637 | case WebKit::WebIconURL::TypeFavicon: |
| 638 | return FaviconURL::FAVICON; |
| 639 | case WebKit::WebIconURL::TypeTouch: |
| 640 | return FaviconURL::TOUCH_ICON; |
| 641 | case WebKit::WebIconURL::TypeTouchPrecomposed: |
| 642 | return FaviconURL::TOUCH_PRECOMPOSED_ICON; |
| 643 | case WebKit::WebIconURL::TypeInvalid: |
| 644 | return FaviconURL::INVALID_ICON; |
| 645 | } |
| 646 | return FaviconURL::INVALID_ICON; |
| 647 | } |
| 648 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 649 | /////////////////////////////////////////////////////////////////////////////// |
| 650 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 651 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 652 | PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c) |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 653 | : params(p), |
| 654 | completion(c) { |
| 655 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 656 | FileChooserParams params; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 657 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 658 | }; |
| 659 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 660 | namespace { |
| 661 | |
| 662 | class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { |
| 663 | public: |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 664 | explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget) |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 665 | : webwidget_(webwidget) {} |
| 666 | |
| 667 | virtual void OnLockMouseACK(bool succeeded) OVERRIDE { |
| 668 | if (succeeded) |
| 669 | webwidget_->didAcquirePointerLock(); |
| 670 | else |
| 671 | webwidget_->didNotAcquirePointerLock(); |
| 672 | } |
| 673 | |
| 674 | virtual void OnMouseLockLost() OVERRIDE { |
| 675 | webwidget_->didLosePointerLock(); |
| 676 | } |
| 677 | |
| 678 | virtual bool HandleMouseLockedInputEvent( |
| 679 | const WebKit::WebMouseEvent &event) OVERRIDE { |
| 680 | // The WebWidget handles mouse lock in WebKit's handleInputEvent(). |
| 681 | return false; |
| 682 | } |
| 683 | |
| 684 | private: |
| 685 | WebKit::WebWidget* webwidget_; |
| 686 | }; |
| 687 | |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 688 | int64 ExtractPostId(const WebHistoryItem& item) { |
| 689 | if (item.isNull()) |
| 690 | return -1; |
| 691 | |
| 692 | if (item.httpBody().isNull()) |
| 693 | return -1; |
| 694 | |
| 695 | return item.httpBody().identifier(); |
| 696 | } |
| 697 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 698 | bool TouchEnabled() { |
| 699 | // Based on the definition of chrome::kEnableTouchIcon. |
| 700 | #if defined(OS_ANDROID) |
| 701 | return true; |
| 702 | #else |
| 703 | return false; |
| 704 | #endif |
| 705 | } |
| 706 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 707 | WebDragData DropDataToWebDragData(const DropData& drop_data) { |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 708 | std::vector<WebDragData::Item> item_list; |
| 709 | |
| 710 | // These fields are currently unused when dragging into WebKit. |
| 711 | DCHECK(drop_data.download_metadata.empty()); |
| 712 | DCHECK(drop_data.file_contents.empty()); |
| 713 | DCHECK(drop_data.file_description_filename.empty()); |
| 714 | |
| 715 | if (!drop_data.text.is_null()) { |
| 716 | WebDragData::Item item; |
| 717 | item.storageType = WebDragData::Item::StorageTypeString; |
| 718 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| 719 | item.stringData = drop_data.text.string(); |
| 720 | item_list.push_back(item); |
| 721 | } |
| 722 | |
| 723 | // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it |
| 724 | // meaningful to write an empty URL to the clipboard? |
| 725 | if (!drop_data.url.is_empty()) { |
| 726 | WebDragData::Item item; |
| 727 | item.storageType = WebDragData::Item::StorageTypeString; |
| 728 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 729 | item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
| 730 | item.title = drop_data.url_title; |
| 731 | item_list.push_back(item); |
| 732 | } |
| 733 | |
| 734 | if (!drop_data.html.is_null()) { |
| 735 | WebDragData::Item item; |
| 736 | item.storageType = WebDragData::Item::StorageTypeString; |
| 737 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 738 | item.stringData = drop_data.html.string(); |
| 739 | item.baseURL = drop_data.html_base_url; |
| 740 | item_list.push_back(item); |
| 741 | } |
| 742 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 743 | for (std::vector<DropData::FileInfo>::const_iterator it = |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 744 | drop_data.filenames.begin(); |
| 745 | it != drop_data.filenames.end(); |
| 746 | ++it) { |
| 747 | WebDragData::Item item; |
| 748 | item.storageType = WebDragData::Item::StorageTypeFilename; |
| 749 | item.filenameData = it->path; |
| 750 | item.displayNameData = it->display_name; |
| 751 | item_list.push_back(item); |
| 752 | } |
| 753 | |
| 754 | for (std::map<base::string16, base::string16>::const_iterator it = |
| 755 | drop_data.custom_data.begin(); |
| 756 | it != drop_data.custom_data.end(); |
| 757 | ++it) { |
| 758 | WebDragData::Item item; |
| 759 | item.storageType = WebDragData::Item::StorageTypeString; |
| 760 | item.stringType = it->first; |
| 761 | item.stringData = it->second; |
| 762 | item_list.push_back(item); |
| 763 | } |
| 764 | |
| 765 | WebDragData result; |
| 766 | result.initialize(); |
| 767 | result.setItems(item_list); |
| 768 | result.setFilesystemId(drop_data.filesystem_id); |
| 769 | return result; |
| 770 | } |
| 771 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 772 | } // namespace |
| 773 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 774 | RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) |
| 775 | : RenderWidget(WebKit::WebPopupTypeNone, |
| 776 | params->screen_info, |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 777 | params->swapped_out, |
| 778 | params->hidden), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 779 | webkit_preferences_(params->webkit_prefs), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 780 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 781 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 782 | send_preferred_size_changes_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 783 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 784 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 785 | opened_by_user_gesture_(true), |
| 786 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 787 | page_id_(-1), |
| 788 | last_page_id_sent_to_browser_(-1), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 789 | next_page_id_(params->next_page_id), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 790 | history_list_offset_(-1), |
| 791 | history_list_length_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 792 | target_url_status_(TARGET_NONE), |
[email protected] | bbef1d3 | 2011-10-25 14:36:55 | [diff] [blame] | 793 | selection_text_offset_(0), |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 794 | selection_range_(gfx::Range::InvalidRange()), |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 795 | #if defined(OS_ANDROID) |
| 796 | top_controls_constraints_(cc::BOTH), |
| 797 | #endif |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 798 | cached_is_main_frame_pinned_to_left_(false), |
| 799 | cached_is_main_frame_pinned_to_right_(false), |
| 800 | cached_has_main_frame_horizontal_scrollbar_(false), |
| 801 | cached_has_main_frame_vertical_scrollbar_(false), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 802 | cookie_jar_(this), |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 803 | notification_provider_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 804 | geolocation_dispatcher_(NULL), |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 805 | input_tag_speech_dispatcher_(NULL), |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 806 | speech_recognition_dispatcher_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 807 | device_orientation_dispatcher_(NULL), |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 808 | media_stream_dispatcher_(NULL), |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 809 | browser_plugin_manager_(NULL), |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 810 | media_stream_client_(NULL), |
| 811 | web_user_media_client_(NULL), |
[email protected] | f39b9d5 | 2013-07-28 08:03:44 | [diff] [blame] | 812 | midi_dispatcher_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 813 | devtools_agent_(NULL), |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 814 | accessibility_mode_(AccessibilityModeOff), |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 815 | renderer_accessibility_(NULL), |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 816 | java_bridge_dispatcher_(NULL), |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 817 | mouse_lock_dispatcher_(NULL), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 818 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 819 | body_background_color_(SK_ColorWHITE), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 820 | expected_content_intent_id_(0), |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 821 | media_player_proxy_(NULL), |
[email protected] | a756427 | 2013-04-19 14:24:46 | [diff] [blame] | 822 | #endif |
| 823 | #if defined(OS_WIN) |
| 824 | focused_plugin_id_(-1), |
| 825 | #endif |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 826 | #if defined(ENABLE_PLUGINS) |
| 827 | focused_pepper_plugin_(NULL), |
| 828 | pepper_last_mouse_event_target_(NULL), |
| 829 | #endif |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 830 | enumeration_completion_id_(0), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 831 | load_progress_tracker_(new LoadProgressTracker(this)), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 832 | session_storage_namespace_id_(params->session_storage_namespace_id), |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 833 | handling_select_range_(false), |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 834 | next_snapshot_id_(0), |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 835 | allow_partial_swap_(params->allow_partial_swap), |
[email protected] | 07fb8d5 | 2013-08-07 17:03:51 | [diff] [blame] | 836 | context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | void RenderViewImpl::Initialize(RenderViewImplParams* params) { |
[email protected] | 2f61bdd | 2013-07-02 18:38:47 | [diff] [blame] | 840 | RenderFrameImpl* main_frame = RenderFrameImpl::Create( |
| 841 | this, params->main_frame_routing_id); |
| 842 | main_render_frame_.reset(main_frame); |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 843 | routing_id_ = params->routing_id; |
| 844 | surface_id_ = params->surface_id; |
| 845 | if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created) |
| 846 | opener_id_ = params->opener_id; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 847 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 848 | // Ensure we start with a valid next_page_id_ from the browser. |
| 849 | DCHECK_GE(next_page_id_, 0); |
| 850 | |
[email protected] | 21b3a6ae | 2011-11-30 00:45:29 | [diff] [blame] | 851 | #if defined(ENABLE_NOTIFICATIONS) |
| 852 | notification_provider_ = new NotificationProvider(this); |
| 853 | #else |
| 854 | notification_provider_ = NULL; |
| 855 | #endif |
| 856 | |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 857 | webwidget_ = WebView::create(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 858 | webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 859 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 860 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 861 | |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 862 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 863 | stats_collection_observer_.reset(new StatsCollectionObserver(this)); |
| 864 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 865 | #if defined(OS_ANDROID) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 866 | content::DeviceTelephonyInfo device_info; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 867 | |
| 868 | const std::string region_code = |
| 869 | command_line.HasSwitch(switches::kNetworkCountryIso) |
| 870 | ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 871 | : device_info.GetNetworkCountryIso(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 872 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 873 | new AddressDetector())); |
| 874 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 875 | new PhoneNumberDetector(region_code))); |
| 876 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 877 | new EmailDetector())); |
| 878 | #endif |
| 879 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 880 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 881 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 882 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 883 | AddRef(); |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 884 | if (is_hidden_) |
| 885 | RenderThread::Get()->WidgetHidden(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 886 | |
| 887 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 888 | // completing initialization. Otherwise, we can finish it now. |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 889 | if (opener_id_ == MSG_ROUTING_NONE) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 890 | did_show_ = true; |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 891 | CompleteInit(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 892 | } |
| 893 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 894 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 895 | g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this)); |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 896 | webview()->setDeviceScaleFactor(device_scale_factor_); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 897 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 898 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 899 | webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled( |
| 900 | ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_)); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 901 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 902 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 903 | webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled( |
| 904 | ShouldUseAcceleratedFixedRootBackground(device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 905 | |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 906 | ApplyWebPreferences(webkit_preferences_, webview()); |
[email protected] | 2f61bdd | 2013-07-02 18:38:47 | [diff] [blame] | 907 | webview()->initializeMainFrame(main_render_frame_.get()); |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 908 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 909 | if (switches::IsTouchDragDropEnabled()) |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 910 | webview()->settings()->setTouchDragDropEnabled(true); |
| 911 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 912 | if (switches::IsTouchEditingEnabled()) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 913 | webview()->settings()->setTouchEditingEnabled(true); |
| 914 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 915 | if (!params->frame_name.empty()) |
| 916 | webview()->mainFrame()->setName(params->frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 917 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 918 | OnSetRendererPrefs(params->renderer_prefs); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 919 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 920 | #if defined(ENABLE_WEBRTC) |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 921 | if (!media_stream_dispatcher_) |
| 922 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 923 | #endif |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 924 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 925 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 926 | #if defined(OS_MACOSX) |
| 927 | new TextInputClientObserver(this); |
| 928 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 929 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 930 | #if defined(OS_ANDROID) |
[email protected] | bc42744 | 2013-07-13 02:53:08 | [diff] [blame] | 931 | media_player_manager_.reset(new RendererMediaPlayerManager()); |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 932 | #endif |
| 933 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 934 | // The next group of objects all implement RenderViewObserver, so are deleted |
| 935 | // along with the RenderView automatically. |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 936 | devtools_agent_ = new DevToolsAgent(this); |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 937 | if (RenderWidgetCompositor* rwc = compositor()) { |
| 938 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 939 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 940 | mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 941 | new ImageLoadingHelper(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 942 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 943 | // Create renderer_accessibility_ if needed. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 944 | OnSetAccessibilityMode(params->accessibility_mode); |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 945 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 946 | new IdleUserDetector(this); |
| 947 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 948 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 949 | enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION; |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 950 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 951 | enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION; |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 952 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 953 | ProcessViewLayoutFlags(command_line); |
[email protected] | 7ddea980 | 2012-02-22 23:08:05 | [diff] [blame] | 954 | |
[email protected] | b9bad12 | 2013-07-29 20:32:33 | [diff] [blame] | 955 | #if defined(ENABLE_PLUGINS) |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 956 | new PepperBrowserConnection(this); |
[email protected] | b9bad12 | 2013-07-29 20:32:33 | [diff] [blame] | 957 | #endif |
| 958 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 959 | GetContentClient()->renderer()->RenderViewCreated(this); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 960 | |
| 961 | // If we have an opener_id but we weren't created by a renderer, then |
| 962 | // it's the browser asking us to set our opener to another RenderView. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 963 | if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) { |
| 964 | RenderViewImpl* opener_view = FromRoutingID(params->opener_id); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 965 | if (opener_view) |
| 966 | webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | // If we are initially swapped out, navigate to kSwappedOutURL. |
| 970 | // This ensures we are in a unique origin that others cannot script. |
| 971 | if (is_swapped_out_) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 972 | NavigateToSwappedOutURL(webview()->mainFrame()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 973 | } |
| 974 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 975 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 976 | history_page_ids_.clear(); |
| 977 | |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 978 | base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_); |
| 979 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 980 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 981 | while (!file_chooser_completions_.empty()) { |
| 982 | if (file_chooser_completions_.front()->completion) { |
| 983 | file_chooser_completions_.front()->completion->didChooseFile( |
| 984 | WebVector<WebString>()); |
| 985 | } |
| 986 | file_chooser_completions_.pop_front(); |
| 987 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 988 | |
[email protected] | 8ed1d3f | 2013-02-20 11:45:55 | [diff] [blame] | 989 | #if defined(OS_ANDROID) |
| 990 | // The date/time picker client is both a scoped_ptr member of this class and |
| 991 | // a RenderViewObserver. Reset it to prevent double deletion. |
| 992 | date_time_picker_client_.reset(); |
| 993 | #endif |
| 994 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 995 | #ifndef NDEBUG |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 996 | // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 997 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 998 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 999 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 1000 | RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 1001 | for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 1002 | it != routing_id_views->end(); ++it) |
| 1003 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1004 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1005 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1006 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1007 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1011 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1012 | ViewMap* views = g_view_map.Pointer(); |
| 1013 | ViewMap::iterator it = views->find(webview); |
| 1014 | return it == views->end() ? NULL : it->second; |
| 1015 | } |
| 1016 | |
| 1017 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1018 | RenderView* RenderView::FromWebView(WebKit::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1019 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | /*static*/ |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 1023 | RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) { |
| 1024 | RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
| 1025 | RoutingIDViewMap::iterator it = views->find(routing_id); |
| 1026 | return it == views->end() ? NULL : it->second; |
| 1027 | } |
| 1028 | |
| 1029 | /*static*/ |
| 1030 | RenderView* RenderView::FromRoutingID(int routing_id) { |
| 1031 | return RenderViewImpl::FromRoutingID(routing_id); |
| 1032 | } |
| 1033 | |
| 1034 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1035 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 1036 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1037 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 1038 | if (!visitor->Visit(it->second)) |
| 1039 | return; |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1044 | RenderViewImpl* RenderViewImpl::Create( |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1045 | int32 opener_id, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1046 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1047 | const WebPreferences& webkit_prefs, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1048 | int32 routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1049 | int32 main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1050 | int32 surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1051 | int64 session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1052 | const string16& frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1053 | bool is_renderer_created, |
| 1054 | bool swapped_out, |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 1055 | bool hidden, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1056 | int32 next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1057 | const WebKit::WebScreenInfo& screen_info, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 1058 | AccessibilityMode accessibility_mode, |
| 1059 | bool allow_partial_swap) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1060 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1061 | RenderViewImplParams params( |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1062 | opener_id, |
| 1063 | renderer_prefs, |
| 1064 | webkit_prefs, |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1065 | routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1066 | main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1067 | surface_id, |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1068 | session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1069 | frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1070 | is_renderer_created, |
| 1071 | swapped_out, |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 1072 | hidden, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1073 | next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1074 | screen_info, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 1075 | accessibility_mode, |
| 1076 | allow_partial_swap); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1077 | RenderViewImpl* render_view = NULL; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1078 | if (g_create_render_view_impl) |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1079 | render_view = g_create_render_view_impl(¶ms); |
| 1080 | else |
| 1081 | render_view = new RenderViewImpl(¶ms); |
| 1082 | render_view->Initialize(¶ms); |
| 1083 | return render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | // static |
| 1087 | void RenderViewImpl::InstallCreateHook( |
| 1088 | RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) { |
| 1089 | CHECK(!g_create_render_view_impl); |
| 1090 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1091 | } |
| 1092 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1093 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1094 | observers_.AddObserver(observer); |
| 1095 | } |
| 1096 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1097 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 1098 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1099 | observers_.RemoveObserver(observer); |
| 1100 | } |
| 1101 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1102 | WebKit::WebView* RenderViewImpl::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 1103 | return static_cast<WebKit::WebView*>(webwidget()); |
| 1104 | } |
| 1105 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 1106 | #if defined(ENABLE_PLUGINS) |
| 1107 | void RenderViewImpl::PepperInstanceCreated(PepperPluginInstanceImpl* instance) { |
| 1108 | active_pepper_instances_.insert(instance); |
| 1109 | } |
| 1110 | |
| 1111 | void RenderViewImpl::PepperInstanceDeleted(PepperPluginInstanceImpl* instance) { |
| 1112 | active_pepper_instances_.erase(instance); |
| 1113 | |
| 1114 | if (pepper_last_mouse_event_target_ == instance) |
| 1115 | pepper_last_mouse_event_target_ = NULL; |
| 1116 | if (focused_pepper_plugin_ == instance) |
| 1117 | PepperFocusChanged(instance, false); |
| 1118 | } |
| 1119 | |
| 1120 | void RenderViewImpl::PepperDidChangeCursor( |
| 1121 | PepperPluginInstanceImpl* instance, |
| 1122 | const WebKit::WebCursorInfo& cursor) { |
| 1123 | // Update the cursor appearance immediately if the requesting plugin is the |
| 1124 | // one which receives the last mouse event. Otherwise, the new cursor won't be |
| 1125 | // picked up until the plugin gets the next input event. That is bad if, e.g., |
| 1126 | // the plugin would like to set an invisible cursor when there isn't any user |
| 1127 | // input for a while. |
| 1128 | if (instance == pepper_last_mouse_event_target_) |
| 1129 | didChangeCursor(cursor); |
| 1130 | } |
| 1131 | |
| 1132 | void RenderViewImpl::PepperDidReceiveMouseEvent( |
| 1133 | PepperPluginInstanceImpl* instance) { |
| 1134 | pepper_last_mouse_event_target_ = instance; |
| 1135 | } |
| 1136 | |
| 1137 | void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance, |
| 1138 | bool focused) { |
| 1139 | if (focused) |
| 1140 | focused_pepper_plugin_ = instance; |
| 1141 | else if (focused_pepper_plugin_ == instance) |
| 1142 | focused_pepper_plugin_ = NULL; |
| 1143 | |
| 1144 | UpdateTextInputType(); |
| 1145 | UpdateSelectionBounds(); |
| 1146 | } |
| 1147 | |
| 1148 | void RenderViewImpl::PepperTextInputTypeChanged( |
| 1149 | PepperPluginInstanceImpl* instance) { |
| 1150 | if (instance != focused_pepper_plugin_) |
| 1151 | return; |
| 1152 | |
| 1153 | UpdateTextInputType(); |
| 1154 | if (renderer_accessibility_) |
| 1155 | renderer_accessibility_->FocusedNodeChanged(WebNode()); |
| 1156 | } |
| 1157 | |
| 1158 | void RenderViewImpl::PepperCaretPositionChanged( |
| 1159 | PepperPluginInstanceImpl* instance) { |
| 1160 | if (instance != focused_pepper_plugin_) |
| 1161 | return; |
| 1162 | UpdateSelectionBounds(); |
| 1163 | } |
| 1164 | |
| 1165 | void RenderViewImpl::PepperCancelComposition( |
| 1166 | PepperPluginInstanceImpl* instance) { |
| 1167 | if (instance != focused_pepper_plugin_) |
| 1168 | return; |
| 1169 | Send(new ViewHostMsg_ImeCancelComposition(routing_id()));; |
| 1170 | #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA) |
| 1171 | UpdateCompositionInfo(true); |
| 1172 | #endif |
| 1173 | } |
| 1174 | |
| 1175 | void RenderViewImpl::PepperSelectionChanged( |
| 1176 | PepperPluginInstanceImpl* instance) { |
| 1177 | if (instance != focused_pepper_plugin_) |
| 1178 | return; |
| 1179 | SyncSelectionIfRequired(); |
| 1180 | } |
| 1181 | |
| 1182 | RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer( |
| 1183 | PepperPluginInstanceImpl* plugin) { |
| 1184 | GURL active_url; |
| 1185 | if (webview() && webview()->mainFrame()) |
| 1186 | active_url = GURL(webview()->mainFrame()->document().url()); |
| 1187 | RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create( |
| 1188 | routing_id_, plugin, active_url, screen_info_); |
| 1189 | widget->show(WebKit::WebNavigationPolicyIgnore); |
| 1190 | return widget; |
| 1191 | } |
| 1192 | |
| 1193 | void RenderViewImpl::PepperPluginCreated(RendererPpapiHost* host) { |
| 1194 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 1195 | DidCreatePepperPlugin(host)); |
| 1196 | } |
| 1197 | |
| 1198 | bool RenderViewImpl::GetPepperCaretBounds(gfx::Rect* rect) { |
| 1199 | if (!focused_pepper_plugin_) |
| 1200 | return false; |
| 1201 | *rect = focused_pepper_plugin_->GetCaretBounds(); |
| 1202 | return true; |
| 1203 | } |
| 1204 | |
| 1205 | bool RenderViewImpl::IsPepperAcceptingCompositionEvents() const { |
| 1206 | if (!focused_pepper_plugin_) |
| 1207 | return false; |
| 1208 | return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents(); |
| 1209 | } |
| 1210 | |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 1211 | void RenderViewImpl::PluginCrashed(const base::FilePath& plugin_path, |
[email protected] | cf4d6e74 | 2013-01-10 14:06:42 | [diff] [blame] | 1212 | base::ProcessId plugin_pid) { |
| 1213 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path, plugin_pid)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1214 | } |
| 1215 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1216 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1217 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1218 | // If the renderer is visible, set initial visibility and focus state. |
| 1219 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1220 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1221 | delegate->SetContainerVisibility(true); |
| 1222 | if (webview() && webview()->isActive()) |
| 1223 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1224 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1225 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1226 | // Plugins start assuming the content has focus (so that they work in |
| 1227 | // environments where RenderView isn't hosting them), so we always have to |
| 1228 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 1229 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1230 | } |
| 1231 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1232 | void RenderViewImpl::UnregisterPluginDelegate( |
| 1233 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1234 | plugin_delegates_.erase(delegate); |
| 1235 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1236 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1237 | bool RenderViewImpl::GetPluginInfo(const GURL& url, |
| 1238 | const GURL& page_url, |
| 1239 | const std::string& mime_type, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 1240 | WebPluginInfo* plugin_info, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1241 | std::string* actual_mime_type) { |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 1242 | bool found = false; |
| 1243 | Send(new ViewHostMsg_GetPluginInfo( |
| 1244 | routing_id_, url, page_url, mime_type, &found, plugin_info, |
| 1245 | actual_mime_type)); |
| 1246 | return found; |
| 1247 | } |
| 1248 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 1249 | void RenderViewImpl::SimulateImeSetComposition( |
| 1250 | const string16& text, |
| 1251 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 1252 | int selection_start, |
| 1253 | int selection_end) { |
| 1254 | OnImeSetComposition(text, underlines, selection_start, selection_end); |
| 1255 | } |
| 1256 | |
| 1257 | void RenderViewImpl::SimulateImeConfirmComposition( |
| 1258 | const string16& text, |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 1259 | const gfx::Range& replacement_range) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 1260 | OnImeConfirmComposition(text, replacement_range, false); |
| 1261 | } |
| 1262 | |
| 1263 | #if defined(OS_WIN) |
| 1264 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1265 | if (focused) |
| 1266 | focused_plugin_id_ = plugin_id; |
| 1267 | else |
| 1268 | focused_plugin_id_ = -1; |
| 1269 | } |
| 1270 | #endif |
| 1271 | |
| 1272 | #if defined(OS_MACOSX) |
| 1273 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1274 | Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); |
| 1275 | } |
| 1276 | |
| 1277 | void RenderViewImpl::StartPluginIme() { |
| 1278 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
| 1279 | // This message can be sent during event-handling, and needs to be delivered |
| 1280 | // within that context. |
| 1281 | msg->set_unblock(true); |
| 1282 | Send(msg); |
| 1283 | } |
| 1284 | #endif // defined(OS_MACOSX) |
| 1285 | |
| 1286 | #endif // ENABLE_PLUGINS |
| 1287 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 1288 | void RenderViewImpl::TransferActiveWheelFlingAnimation( |
| 1289 | const WebKit::WebActiveWheelFlingParameters& params) { |
| 1290 | if (webview()) |
| 1291 | webview()->transferActiveWheelFlingAnimation(params); |
| 1292 | } |
| 1293 | |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 1294 | bool RenderViewImpl::HasIMETextFocus() { |
| 1295 | return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
| 1296 | } |
| 1297 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1298 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1299 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 1300 | if (main_frame) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1301 | GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1302 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1303 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 1304 | RenderViewObserver* observer; |
| 1305 | while ((observer = it.GetNext()) != NULL) |
| 1306 | if (observer->OnMessageReceived(message)) |
| 1307 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1308 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1309 | bool handled = true; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1310 | bool msg_is_ok = true; |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1311 | IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1312 | IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) |
| 1313 | IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) |
| 1314 | IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete) |
| 1315 | IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand) |
| 1316 | IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret) |
| 1317 | IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) |
| 1318 | IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
| 1319 | IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) |
| 1320 | IPC_MESSAGE_HANDLER(InputMsg_Replace, OnReplace) |
| 1321 | IPC_MESSAGE_HANDLER(InputMsg_ReplaceMisspelling, OnReplaceMisspelling) |
| 1322 | IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect, |
| 1323 | OnScrollFocusedEditableNodeIntoRect) |
| 1324 | IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll) |
| 1325 | IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange) |
| 1326 | IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent, |
| 1327 | OnSetEditCommandsForNextKeyEvent) |
| 1328 | IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) |
| 1329 | IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1330 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 1331 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1332 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1333 | IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1334 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets, |
| 1335 | OnSetEditableSelectionOffsets) |
| 1336 | IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText, |
| 1337 | OnSetCompositionFromExistingText) |
| 1338 | IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete, |
| 1339 | OnExtendSelectionAndDelete) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1340 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
| 1341 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 1342 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 1343 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1344 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 1345 | IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1346 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 1347 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1348 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1349 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 1350 | OnResetPageEncodingToDefault) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1351 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 1352 | IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 1353 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1354 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 1355 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 1356 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 1357 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| 1358 | IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) |
| 1359 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 1360 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 1361 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1362 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1363 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 1364 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 1365 | IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1366 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1367 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 1368 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1369 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 1370 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1371 | IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1372 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 1373 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1374 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 1375 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1376 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 1377 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 1378 | OnEnablePreferredSizeChangedMode) |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1379 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1380 | IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 1381 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 1382 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1383 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 1384 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 1385 | IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent, |
| 1386 | OnOrientationChangeEvent) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1387 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 1388 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 1389 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 1390 | OnCustomContextMenuAction) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 1391 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 1392 | OnGetAllSavableResourceLinksForCurrentPage) |
| 1393 | IPC_MESSAGE_HANDLER( |
| 1394 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 1395 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 1396 | IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 1397 | IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 1398 | // TODO(viettrungluu): Move to a separate message filter. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1399 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 1400 | OnSetHistoryLengthAndPrune) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 1401 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | c7654a23 | 2013-06-12 21:04:44 | [diff] [blame] | 1402 | #if defined(OS_ANDROID) |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 1403 | IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
[email protected] | da81627 | 2013-05-15 21:31:17 | [diff] [blame] | 1404 | #endif |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1405 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 1406 | IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1407 | #if defined(OS_ANDROID) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1408 | IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult, |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1409 | OnActivateNearestFindResult) |
| 1410 | IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects) |
| 1411 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1412 | IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView, |
| 1413 | OnUndoScrollFocusedEditableNodeIntoRect) |
[email protected] | 452b4a9 | 2013-03-28 21:24:38 | [diff] [blame] | 1414 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState, |
| 1415 | OnUpdateTopControlsState) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1416 | #elif defined(OS_MACOSX) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1417 | IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1418 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 1419 | OnPluginImeCompositionCompleted) |
| 1420 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 1421 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1422 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| 1423 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| 1424 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 1425 | IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB, |
| 1426 | OnReleaseDisambiguationPopupDIB) |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 1427 | IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, |
| 1428 | OnWindowSnapshotCompleted) |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1429 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1430 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1431 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1432 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1433 | |
| 1434 | if (!msg_is_ok) { |
| 1435 | // The message had a handler, but its deserialization failed. |
| 1436 | // Kill the renderer to avoid potential spoofing attacks. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1437 | CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1438 | } |
| 1439 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1440 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1441 | } |
| 1442 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1443 | void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 1444 | MaybeHandleDebugURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1445 | if (!webview()) |
| 1446 | return; |
| 1447 | |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 1448 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
| 1449 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1450 | bool is_reload = IsReload(params); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1451 | |
| 1452 | // If this is a stale back/forward (due to a recent navigation the browser |
| 1453 | // didn't know about), ignore it. |
| 1454 | if (IsBackForwardToStaleEntry(params, is_reload)) |
| 1455 | return; |
| 1456 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1457 | // Swap this renderer back in if necessary. |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1458 | if (is_swapped_out_) { |
| 1459 | // We marked the view as hidden when swapping the view out, so be sure to |
| 1460 | // reset the visibility state before navigating to the new URL. |
| 1461 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | 890b06ca | 2012-12-13 21:07:36 | [diff] [blame] | 1462 | |
| 1463 | // If this is an attempt to reload while we are swapped out, we should not |
| 1464 | // reload swappedout://, but the previous page, which is stored in |
| 1465 | // params.state. Setting is_reload to false will treat this like a back |
| 1466 | // navigation to accomplish that. |
| 1467 | is_reload = false; |
| 1468 | |
[email protected] | 0b05902 | 2013-07-03 22:50:09 | [diff] [blame] | 1469 | // We refresh timezone when a view is swapped in since timezone |
| 1470 | // can get out of sync when the system timezone is updated while |
| 1471 | // the view is swapped out. |
| 1472 | NotifyTimezoneChange(webview()->mainFrame()); |
| 1473 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1474 | SetSwappedOut(false); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1475 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1476 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1477 | if (params.should_clear_history_list) { |
| 1478 | CHECK_EQ(params.pending_history_list_offset, -1); |
| 1479 | CHECK_EQ(params.current_history_list_offset, -1); |
| 1480 | CHECK_EQ(params.current_history_list_length, 0); |
| 1481 | } |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1482 | history_list_offset_ = params.current_history_list_offset; |
| 1483 | history_list_length_ = params.current_history_list_length; |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1484 | if (history_list_length_ >= 0) |
| 1485 | history_page_ids_.resize(history_list_length_, -1); |
| 1486 | if (params.pending_history_list_offset >= 0 && |
| 1487 | params.pending_history_list_offset < history_list_length_) |
| 1488 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1489 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1490 | GetContentClient()->SetActiveURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1491 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1492 | WebFrame* frame = webview()->mainFrame(); |
| 1493 | if (!params.frame_to_navigate.empty()) { |
| 1494 | frame = webview()->findFrameByName( |
| 1495 | WebString::fromUTF8(params.frame_to_navigate)); |
| 1496 | CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; |
| 1497 | } |
| 1498 | |
| 1499 | if (is_reload && frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1500 | // We cannot reload if we do not have any history state. This happens, for |
| 1501 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1502 | // a hack since it means that reload after a crashed tab does not cause an |
| 1503 | // end-to-end cache validation. |
| 1504 | is_reload = false; |
| 1505 | } |
| 1506 | |
[email protected] | 3d2fd59 | 2012-11-30 02:05:50 | [diff] [blame] | 1507 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params)); |
[email protected] | 48a5c77 | 2011-04-18 23:50:50 | [diff] [blame] | 1508 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1509 | // If we are reloading, then WebKit will use the history state of the current |
| 1510 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1511 | // have history state, then we need to navigate to it, which corresponds to a |
| 1512 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1513 | if (is_reload) { |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1514 | bool reload_original_url = |
| 1515 | (params.navigation_type == |
| 1516 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1517 | bool ignore_cache = (params.navigation_type == |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 1518 | ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1519 | |
| 1520 | if (reload_original_url) |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1521 | frame->reloadWithOverrideURL(params.url, true); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1522 | else |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1523 | frame->reload(ignore_cache); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1524 | } else if (params.page_state.IsValid()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1525 | // 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] | 1526 | DCHECK_NE(params.page_id, -1); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1527 | WebHistoryItem item = PageStateToHistoryItem(params.page_state); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1528 | if (!item.isNull()) { |
| 1529 | // Ensure we didn't save the swapped out URL in UpdateState, since the |
| 1530 | // browser should never be telling us to navigate to swappedout://. |
| 1531 | CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL)); |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1532 | frame->loadHistoryItem(item); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1533 | } |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1534 | } else if (!params.base_url_for_data_url.is_empty()) { |
| 1535 | // A loadData request with a specified base URL. |
| 1536 | std::string mime_type, charset, data; |
| 1537 | if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1538 | frame->loadData( |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1539 | WebData(data.c_str(), data.length()), |
| 1540 | WebString::fromUTF8(mime_type), |
| 1541 | WebString::fromUTF8(charset), |
| 1542 | params.base_url_for_data_url, |
| 1543 | params.history_url_for_data_url, |
| 1544 | false); |
| 1545 | } else { |
| 1546 | CHECK(false) << |
| 1547 | "Invalid URL passed: " << params.url.possibly_invalid_spec(); |
| 1548 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1549 | } else { |
| 1550 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1551 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1552 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1553 | // A session history navigation should have been accompanied by state. |
[email protected] | cbc0cb7 | 2011-12-06 18:58:23 | [diff] [blame] | 1554 | CHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1555 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1556 | if (frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1557 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1558 | |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1559 | if (params.referrer.url.is_valid()) { |
| 1560 | WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
| 1561 | params.referrer.policy, |
| 1562 | params.url, |
| 1563 | WebString::fromUTF8(params.referrer.url.spec())); |
| 1564 | if (!referrer.isEmpty()) |
| 1565 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1566 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1567 | |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 1568 | if (!params.extra_headers.empty()) { |
| 1569 | for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), |
| 1570 | params.extra_headers.end(), "\n"); |
| 1571 | i.GetNext(); ) { |
| 1572 | request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 1573 | WebString::fromUTF8(i.values())); |
| 1574 | } |
| 1575 | } |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1576 | |
| 1577 | if (params.is_post) { |
| 1578 | request.setHTTPMethod(WebString::fromUTF8("POST")); |
| 1579 | |
| 1580 | // Set post data. |
| 1581 | WebHTTPBody http_body; |
| 1582 | http_body.initialize(); |
| 1583 | http_body.appendData(WebData( |
| 1584 | reinterpret_cast<const char*>( |
| 1585 | ¶ms.browser_initiated_post_data.front()), |
| 1586 | params.browser_initiated_post_data.size())); |
| 1587 | request.setHTTPBody(http_body); |
| 1588 | } |
| 1589 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1590 | frame->loadRequest(request); |
[email protected] | 198a95d6 | 2013-04-11 00:44:21 | [diff] [blame] | 1591 | |
| 1592 | // If this is a cross-process navigation, the browser process will send |
| 1593 | // along the proper navigation start value. |
| 1594 | if (!params.browser_navigation_start.is_null() && |
| 1595 | frame->provisionalDataSource()) { |
| 1596 | // browser_navigation_start is likely before this process existed, so we |
| 1597 | // can't use InterProcessTimeTicksConverter. Instead, the best we can do |
| 1598 | // is just ensure we don't report a bogus value in the future. |
| 1599 | base::TimeTicks navigation_start = std::min( |
| 1600 | base::TimeTicks::Now(), params.browser_navigation_start); |
| 1601 | double navigation_start_seconds = |
| 1602 | (navigation_start - base::TimeTicks()).InSecondsF(); |
| 1603 | frame->provisionalDataSource()->setNavigationStartTime( |
| 1604 | navigation_start_seconds); |
| 1605 | } |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1606 | } |
| 1607 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1608 | // In case LoadRequest failed before DidCreateDataSource was called. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1609 | pending_navigation_params_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1610 | } |
| 1611 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1612 | bool RenderViewImpl::IsBackForwardToStaleEntry( |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1613 | const ViewMsg_Navigate_Params& params, |
| 1614 | bool is_reload) { |
| 1615 | // Make sure this isn't a back/forward to an entry we have already cropped |
| 1616 | // or replaced from our history, before the browser knew about it. If so, |
| 1617 | // 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] | 1618 | bool is_back_forward = !is_reload && params.page_state.IsValid(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1619 | |
| 1620 | // Note: if the history_list_length_ is 0 for a back/forward, we must be |
| 1621 | // restoring from a previous session. We'll update our state in OnNavigate. |
| 1622 | if (!is_back_forward || history_list_length_ <= 0) |
| 1623 | return false; |
| 1624 | |
| 1625 | DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_); |
| 1626 | |
| 1627 | // Check for whether the forward history has been cropped due to a recent |
| 1628 | // navigation the browser didn't know about. |
| 1629 | if (params.pending_history_list_offset >= history_list_length_) |
| 1630 | return true; |
| 1631 | |
| 1632 | // Check for whether this entry has been replaced with a new one. |
| 1633 | int expected_page_id = |
| 1634 | history_page_ids_[params.pending_history_list_offset]; |
[email protected] | 9978b8f0 | 2011-08-13 16:17:44 | [diff] [blame] | 1635 | if (expected_page_id > 0 && params.page_id != expected_page_id) { |
| 1636 | if (params.page_id < expected_page_id) |
| 1637 | return true; |
| 1638 | |
| 1639 | // Otherwise we've removed an earlier entry and should have shifted all |
| 1640 | // entries left. For now, it's ok to lazily update the list. |
| 1641 | // TODO(creis): Notify all live renderers when we remove entries from |
| 1642 | // the front of the list, so that we don't hit this case. |
| 1643 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
| 1644 | } |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1645 | |
| 1646 | return false; |
| 1647 | } |
| 1648 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1649 | // Stop loading the current page |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1650 | void RenderViewImpl::OnStop() { |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 1651 | if (webview()) { |
| 1652 | WebFrame* main_frame = webview()->mainFrame(); |
| 1653 | // Stop the alt error page fetcher. If we let it continue it may complete |
| 1654 | // and cause RenderViewHostManager to swap to this RenderView, even though |
| 1655 | // it may no longer be active. |
| 1656 | StopAltErrorPageFetcher(main_frame->provisionalDataSource()); |
| 1657 | StopAltErrorPageFetcher(main_frame->dataSource()); |
| 1658 | main_frame->stopLoading(); |
| 1659 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1660 | } |
| 1661 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1662 | // Reload current focused frame. |
| 1663 | // 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] | 1664 | void RenderViewImpl::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1665 | if (webview() && webview()->focusedFrame()) { |
| 1666 | // We always obey the cache (ignore_cache=false) here. |
| 1667 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1668 | // a cache-ignoring reload of the frame. |
| 1669 | webview()->focusedFrame()->reload(false); |
| 1670 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1671 | } |
| 1672 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1673 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1674 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1675 | } |
| 1676 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1677 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1678 | // Check if there is a targeturl waiting to be sent. |
| 1679 | if (target_url_status_ == TARGET_PENDING) { |
| 1680 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1681 | pending_target_url_)); |
| 1682 | } |
| 1683 | |
| 1684 | target_url_status_ = TARGET_NONE; |
| 1685 | } |
| 1686 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1687 | void RenderViewImpl::OnCopy() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1688 | if (!webview()) |
| 1689 | return; |
| 1690 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1691 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1692 | WebNode current_node = context_menu_node_.isNull() ? |
| 1693 | GetFocusedNode() : context_menu_node_; |
[email protected] | f6b1856b | 2011-06-29 22:02:53 | [diff] [blame] | 1694 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"), |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1695 | current_node); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1696 | } |
| 1697 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1698 | void RenderViewImpl::OnCut() { |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1699 | if (!webview()) |
| 1700 | return; |
| 1701 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [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("Cut"), |
| 1704 | GetFocusedNode()); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1705 | } |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1706 | |
| 1707 | void RenderViewImpl::OnDelete() { |
| 1708 | if (!webview()) |
| 1709 | return; |
| 1710 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1711 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"), |
| 1712 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
| 1716 | const std::string& value) { |
| 1717 | if (!webview() || !webview()->focusedFrame()) |
| 1718 | return; |
| 1719 | |
| 1720 | webview()->focusedFrame()->executeCommand( |
| 1721 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
| 1722 | } |
| 1723 | |
| 1724 | void RenderViewImpl::OnMoveCaret(const gfx::Point& point) { |
| 1725 | if (!webview()) |
| 1726 | return; |
| 1727 | |
| 1728 | Send(new ViewHostMsg_MoveCaret_ACK(routing_id_)); |
| 1729 | |
| 1730 | webview()->focusedFrame()->moveCaretSelectionTowardsWindowPoint(point); |
| 1731 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1732 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1733 | void RenderViewImpl::OnPaste() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1734 | if (!webview()) |
| 1735 | return; |
| 1736 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1737 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1738 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"), |
| 1739 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1740 | } |
| 1741 | |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1742 | void RenderViewImpl::OnPasteAndMatchStyle() { |
| 1743 | if (!webview()) |
| 1744 | return; |
| 1745 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1746 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1747 | webview()->focusedFrame()->executeCommand( |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1748 | WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode()); |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1749 | } |
| 1750 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1751 | void RenderViewImpl::OnRedo() { |
| 1752 | if (!webview()) |
| 1753 | return; |
| 1754 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1755 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"), |
| 1756 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1757 | } |
| 1758 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1759 | void RenderViewImpl::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1760 | if (!webview()) |
| 1761 | return; |
| 1762 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1763 | WebFrame* frame = webview()->focusedFrame(); |
| 1764 | if (!frame->hasSelection()) |
| 1765 | frame->selectWordAroundCaret(); |
[email protected] | 2365c64 | 2013-02-12 19:16:47 | [diff] [blame] | 1766 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1767 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1768 | } |
| 1769 | |
[email protected] | 2365c64 | 2013-02-12 19:16:47 | [diff] [blame] | 1770 | void RenderViewImpl::OnReplaceMisspelling(const string16& text) { |
| 1771 | if (!webview()) |
| 1772 | return; |
| 1773 | |
| 1774 | WebFrame* frame = webview()->focusedFrame(); |
| 1775 | if (!frame->hasSelection()) |
| 1776 | return; |
| 1777 | |
| 1778 | frame->replaceMisspelledRange(text); |
| 1779 | } |
| 1780 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1781 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1782 | const gfx::Rect& rect) { |
| 1783 | WebKit::WebNode node = GetFocusedNode(); |
| 1784 | if (!node.isNull()) { |
| 1785 | if (IsEditableNode(node)) { |
| 1786 | webview()->saveScrollAndScaleState(); |
| 1787 | webview()->scrollFocusedNodeIntoRect(rect); |
| 1788 | } |
| 1789 | } |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1790 | } |
| 1791 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1792 | void RenderViewImpl::OnSelectAll() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1793 | if (!webview()) |
| 1794 | return; |
| 1795 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1796 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1797 | webview()->focusedFrame()->executeCommand( |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1798 | WebString::fromUTF8("SelectAll"), GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1799 | } |
| 1800 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1801 | void RenderViewImpl::OnSelectRange(const gfx::Point& start, |
| 1802 | const gfx::Point& end) { |
| 1803 | if (!webview()) |
| 1804 | return; |
| 1805 | |
| 1806 | Send(new ViewHostMsg_SelectRange_ACK(routing_id_)); |
| 1807 | |
| 1808 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1809 | webview()->focusedFrame()->selectRange(start, end); |
| 1810 | } |
| 1811 | |
| 1812 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
| 1813 | const EditCommands& edit_commands) { |
| 1814 | edit_commands_ = edit_commands; |
| 1815 | } |
| 1816 | |
| 1817 | void RenderViewImpl::OnUndo() { |
| 1818 | if (!webview()) |
| 1819 | return; |
| 1820 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1821 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"), |
| 1822 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1823 | } |
| 1824 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1825 | void RenderViewImpl::OnUnselect() { |
| 1826 | if (!webview()) |
| 1827 | return; |
| 1828 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1829 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1830 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
| 1831 | GetFocusedNode()); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1832 | } |
| 1833 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1834 | #if defined(OS_MACOSX) |
| 1835 | void RenderViewImpl::OnCopyToFindPboard() { |
| 1836 | if (!webview()) |
| 1837 | return; |
| 1838 | |
| 1839 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1840 | // than the |OnCopy()| case. |
| 1841 | WebFrame* frame = webview()->focusedFrame(); |
| 1842 | if (frame->hasSelection()) { |
| 1843 | string16 selection = frame->selectionAsText(); |
| 1844 | RenderThread::Get()->Send( |
| 1845 | new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); |
| 1846 | } |
| 1847 | } |
| 1848 | #endif |
| 1849 | |
| 1850 | void RenderViewImpl::OnSetName(const std::string& name) { |
| 1851 | if (!webview()) |
| 1852 | return; |
| 1853 | |
| 1854 | webview()->mainFrame()->setName(WebString::fromUTF8(name)); |
| 1855 | } |
| 1856 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1857 | void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) { |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1858 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1859 | if (!ShouldHandleImeEvent()) |
| 1860 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1861 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1862 | webview()->setEditableSelectionOffsets(start, end); |
| 1863 | } |
| 1864 | |
| 1865 | void RenderViewImpl::OnSetCompositionFromExistingText( |
| 1866 | int start, int end, |
| 1867 | const std::vector<WebKit::WebCompositionUnderline>& underlines) { |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1868 | if (!ShouldHandleImeEvent()) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1869 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1870 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1871 | webview()->setCompositionFromExistingText(start, end, underlines); |
| 1872 | } |
| 1873 | |
| 1874 | void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) { |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1875 | if (!ShouldHandleImeEvent()) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1876 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1877 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1878 | webview()->extendSelectionAndDelete(before, after); |
| 1879 | } |
| 1880 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1881 | void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length, |
| 1882 | int32 minimum_page_id) { |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1883 | DCHECK_GE(history_length, 0); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1884 | DCHECK(history_list_offset_ == history_list_length_ - 1); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1885 | DCHECK_GE(minimum_page_id, -1); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1886 | |
| 1887 | // Generate the new list. |
| 1888 | std::vector<int32> new_history_page_ids(history_length, -1); |
| 1889 | for (size_t i = 0; i < history_page_ids_.size(); ++i) { |
| 1890 | if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id) |
| 1891 | continue; |
| 1892 | new_history_page_ids.push_back(history_page_ids_[i]); |
| 1893 | } |
| 1894 | new_history_page_ids.swap(history_page_ids_); |
| 1895 | |
| 1896 | // Update indexes. |
| 1897 | history_list_length_ = history_page_ids_.size(); |
| 1898 | history_list_offset_ = history_list_length_ - 1; |
| 1899 | } |
| 1900 | |
| 1901 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1902 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1903 | if (!webview()) |
| 1904 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1905 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1906 | } |
| 1907 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1908 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1909 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1910 | if (!webview()) |
| 1911 | return; |
| 1912 | if (in_live_resize) |
| 1913 | webview()->willStartLiveResize(); |
| 1914 | else |
| 1915 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1916 | } |
| 1917 | #endif |
| 1918 | |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1919 | #if defined(OS_ANDROID) |
| 1920 | void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() { |
| 1921 | const WebNode node = GetFocusedNode(); |
| 1922 | if (!node.isNull() && IsEditableNode(node)) |
| 1923 | webview()->restoreScrollAndScaleState(); |
| 1924 | } |
| 1925 | #endif |
| 1926 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1927 | /////////////////////////////////////////////////////////////////////////////// |
| 1928 | |
| 1929 | // Tell the embedding application that the URL of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1930 | void RenderViewImpl::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1931 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1932 | DCHECK(ds); |
| 1933 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1934 | const WebURLRequest& request = ds->request(); |
| 1935 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1936 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1937 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1938 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 1939 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1940 | InternalDocumentStateData* internal_data = |
| 1941 | InternalDocumentStateData::FromDocumentState(document_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1942 | |
| 1943 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1944 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1945 | params.is_post = false; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1946 | params.post_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1947 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1948 | params.frame_id = frame->identifier(); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 1949 | params.socket_address.set_host(response.remoteIPAddress().utf8()); |
| 1950 | params.socket_address.set_port(response.remotePort()); |
[email protected] | e07ddafe | 2013-03-05 21:03:36 | [diff] [blame] | 1951 | WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response); |
| 1952 | if (extra_data) { |
| 1953 | params.was_fetched_via_proxy = extra_data->was_fetched_via_proxy(); |
| 1954 | } |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1955 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1956 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1957 | |
| 1958 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 1959 | params.url = GetLoadingUrl(frame); |
[email protected] | 809be03 | 2013-03-19 01:56:56 | [diff] [blame] | 1960 | DCHECK(!is_swapped_out_ || params.url == GURL(kSwappedOutURL)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1961 | |
[email protected] | 5f9b871 | 2011-11-23 08:55:57 | [diff] [blame] | 1962 | if (frame->document().baseURL() != params.url) |
| 1963 | params.base_url = frame->document().baseURL(); |
| 1964 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1965 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1966 | params.should_update_history = !ds->hasUnreachableURL() && |
[email protected] | b7df1b7 | 2011-02-10 00:08:04 | [diff] [blame] | 1967 | !response.isMultipartPayload() && (response.httpStatusCode() != 404); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1968 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1969 | params.searchable_form_url = internal_data->searchable_form_url(); |
| 1970 | params.searchable_form_encoding = internal_data->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1971 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1972 | params.gesture = navigation_gesture_; |
| 1973 | navigation_gesture_ = NavigationGestureUnknown; |
| 1974 | |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1975 | // Make navigation state a part of the FrameNavigate message so that commited |
| 1976 | // entry had it at all times. |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1977 | WebHistoryItem item = frame->currentHistoryItem(); |
| 1978 | if (item.isNull()) { |
| 1979 | item.initialize(); |
| 1980 | item.setURLString(request.url().spec().utf16()); |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1981 | } |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1982 | params.page_state = HistoryItemToPageState(item); |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1983 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1984 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1985 | // Top-level navigation. |
| 1986 | |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 1987 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1988 | // will also call us back which will cause us to send a message to |
| 1989 | // update WebContentsImpl. |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 1990 | webview()->zoomLimitsChanged(ZoomFactorToZoomLevel(kMinimumZoomFactor), |
| 1991 | ZoomFactorToZoomLevel(kMaximumZoomFactor)); |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 1992 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1993 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1994 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1995 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1996 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1997 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1998 | // Reset the zoom levels for plugins. |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 1999 | webview()->setZoomLevel(0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2000 | } else { |
| 2001 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 2002 | webview()->setZoomLevel(host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2003 | } |
| 2004 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 2005 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2006 | // This zoom level was merely recorded transiently for this load. We can |
| 2007 | // erase it now. If at some point we reload this page, the browser will |
| 2008 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 2009 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2010 | } |
| 2011 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2012 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 2013 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2014 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 2015 | params.transition = navigation_state->transition_type(); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2016 | if (!PageTransitionIsMainFrame(params.transition)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2017 | // If the main frame does a load, it should not be reported as a subframe |
| 2018 | // navigation. This can occur in the following case: |
| 2019 | // 1. You're on a site with frames. |
| 2020 | // 2. You do a subframe navigation. This is stored with transition type |
| 2021 | // MANUAL_SUBFRAME. |
| 2022 | // 3. You navigate to some non-frame site, say, google.com. |
| 2023 | // 4. You navigate back to the page from step 2. Since it was initially |
| 2024 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 2025 | // We don't want that, because any navigation that changes the toplevel |
| 2026 | // frame should be tracked as a toplevel navigation (this allows us to |
| 2027 | // update the URL bar, etc). |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2028 | params.transition = PAGE_TRANSITION_LINK; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2029 | } |
| 2030 | |
[email protected] | a00a2e3 | 2013-07-31 05:08:33 | [diff] [blame] | 2031 | // If the page contained a client redirect (meta refresh, document.loc...), |
| 2032 | // set the referrer and transition appropriately. |
| 2033 | if (ds->isClientRedirect()) { |
| 2034 | params.referrer = Referrer(params.redirects[0], |
| 2035 | GetReferrerPolicyFromRequest(frame, ds->request())); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2036 | params.transition = static_cast<PageTransition>( |
| 2037 | params.transition | PAGE_TRANSITION_CLIENT_REDIRECT); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2038 | } else { |
| 2039 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 2040 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 2041 | params.referrer = GetReferrerFromRequest(frame, original_request); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2042 | } |
| 2043 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 2044 | string16 method = request.httpMethod(); |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 2045 | if (EqualsASCII(method, "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2046 | params.is_post = true; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 2047 | params.post_id = ExtractPostId(item); |
| 2048 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2049 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2050 | // Send the user agent override back. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2051 | params.is_overriding_user_agent = internal_data->is_overriding_user_agent(); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2052 | |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 2053 | // Track the URL of the original request. |
| 2054 | params.original_request_url = original_request.url(); |
| 2055 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 2056 | params.history_list_was_cleared = |
| 2057 | navigation_state->history_list_was_cleared(); |
| 2058 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 2059 | // Save some histogram data so we can compute the average memory used per |
| 2060 | // page load of the glyphs. |
| 2061 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
[email protected] | 6bd867b | 2013-07-24 22:10:20 | [diff] [blame] | 2062 | WebKit::WebGlyphCache::pageCount()); |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 2063 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 2064 | // This message needs to be sent before any of allowScripts(), |
| 2065 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 2066 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 2067 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2068 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 2069 | } else { |
| 2070 | // Subframe navigation: the type depends on whether this navigation |
| 2071 | // generated a new session history entry. When they do generate a session |
| 2072 | // history entry, it means the user initiated the navigation and we should |
| 2073 | // mark it as such. This test checks if this is the first time UpdateURL |
| 2074 | // has been called since WillNavigateToURL was called to initiate the load. |
| 2075 | if (page_id_ > last_page_id_sent_to_browser_) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2076 | params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2077 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2078 | params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2079 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 2080 | DCHECK(!navigation_state->history_list_was_cleared()); |
| 2081 | params.history_list_was_cleared = false; |
| 2082 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2083 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 2084 | } |
| 2085 | |
| 2086 | last_page_id_sent_to_browser_ = |
| 2087 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 2088 | |
| 2089 | // 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] | 2090 | // we don't want the transition type to persist. Just clear it. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2091 | navigation_state->set_transition_type(PAGE_TRANSITION_LINK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2095 | void RenderViewImpl::UpdateTitle(WebFrame* frame, |
| 2096 | const string16& title, |
| 2097 | WebTextDirection title_direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 2098 | // Ignore all but top level navigations. |
| 2099 | if (frame->parent()) |
| 2100 | return; |
| 2101 | |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 2102 | base::debug::TraceLog::GetInstance()->UpdateProcessLabel( |
| 2103 | routing_id_, UTF16ToUTF8(title)); |
| 2104 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2105 | string16 shortened_title = title.substr(0, kMaxTitleChars); |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 2106 | Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title, |
| 2107 | title_direction)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2108 | } |
| 2109 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2110 | void RenderViewImpl::UpdateEncoding(WebFrame* frame, |
| 2111 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2112 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2113 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2114 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 2115 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2116 | last_encoding_name_ = encoding_name; |
| 2117 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 2118 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 2122 | // Sends the last committed session history state to the browser so it will be |
| 2123 | // saved before we navigate to a new page. This must be called *before* the |
| 2124 | // page ID has been updated so we know what it was. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2125 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2126 | // If we have a valid page ID at this point, then it corresponds to the page |
| 2127 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 2128 | // there is no past session history to record. |
| 2129 | if (page_id_ == -1) |
| 2130 | return; |
| 2131 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2132 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2133 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 2134 | SendUpdateState(item); |
| 2135 | } |
| 2136 | |
| 2137 | void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2138 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2139 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2140 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2141 | // Don't send state updates for kSwappedOutURL. |
| 2142 | if (item.urlString() == WebString::fromUTF8(kSwappedOutURL)) |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 2143 | return; |
| 2144 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2145 | Send(new ViewHostMsg_UpdateState( |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 2146 | routing_id_, page_id_, HistoryItemToPageState(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2147 | } |
| 2148 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2149 | void RenderViewImpl::OpenURL(WebFrame* frame, |
| 2150 | const GURL& url, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2151 | const Referrer& referrer, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2152 | WebNavigationPolicy policy) { |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 2153 | ViewHostMsg_OpenURL_Params params; |
| 2154 | params.url = url; |
| 2155 | params.referrer = referrer; |
| 2156 | params.disposition = NavigationPolicyToDisposition(policy); |
| 2157 | params.frame_id = frame->identifier(); |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 2158 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2159 | if (ds) { |
[email protected] | 866fa2cc | 2013-07-22 22:19:52 | [diff] [blame] | 2160 | params.should_replace_current_entry = ds->replacesCurrentHistoryItem(); |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 2161 | } else { |
[email protected] | 866fa2cc | 2013-07-22 22:19:52 | [diff] [blame] | 2162 | params.should_replace_current_entry = false; |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 2163 | } |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 2164 | params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame] | 2165 | if (GetContentClient()->renderer()->AllowPopup()) |
| 2166 | params.user_gesture = true; |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 2167 | |
| 2168 | if (policy == WebKit::WebNavigationPolicyNewBackgroundTab || |
| 2169 | policy == WebKit::WebNavigationPolicyNewForegroundTab || |
| 2170 | policy == WebKit::WebNavigationPolicyNewWindow || |
| 2171 | policy == WebKit::WebNavigationPolicyNewPopup) { |
| 2172 | WebUserGestureIndicator::consumeUserGesture(); |
| 2173 | } |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 2174 | |
| 2175 | Send(new ViewHostMsg_OpenURL(routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2176 | } |
| 2177 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2178 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2179 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2180 | void RenderViewImpl::LoadNavigationErrorPage( |
| 2181 | WebFrame* frame, |
| 2182 | const WebURLRequest& failed_request, |
| 2183 | const WebURLError& error, |
| 2184 | const std::string& html, |
| 2185 | bool replace) { |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2186 | std::string alt_html; |
| 2187 | const std::string* error_html; |
| 2188 | |
| 2189 | if (!html.empty()) { |
| 2190 | error_html = &html; |
| 2191 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2192 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 2193 | frame, failed_request, error, &alt_html, NULL); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2194 | error_html = &alt_html; |
| 2195 | } |
| 2196 | |
| 2197 | frame->loadHTMLString(*error_html, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2198 | GURL(kUnreachableWebDataURL), |
[email protected] | 21d61e5 | 2011-03-18 19:08:25 | [diff] [blame] | 2199 | error.unreachableURL, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 2200 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2201 | } |
| 2202 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2203 | bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2204 | const string16& message, |
| 2205 | const string16& default_value, |
| 2206 | const GURL& frame_url, |
| 2207 | string16* result) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2208 | bool success = false; |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2209 | string16 result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2210 | if (!result) |
| 2211 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2212 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2213 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
[email protected] | 688e2ee | 2013-09-12 20:48:14 | [diff] [blame] | 2214 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2215 | return success; |
| 2216 | } |
| 2217 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2218 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2219 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 2220 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 2221 | // it is particularly important that we do not call willEnterModalLoop as |
| 2222 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2223 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2224 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2225 | |
| 2226 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 2227 | return Send(message); |
| 2228 | } |
| 2229 | |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 2230 | void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) { |
| 2231 | int id = next_snapshot_id_++; |
| 2232 | pending_snapshots_.insert(std::make_pair(id, callback)); |
| 2233 | Send(new ViewHostMsg_GetWindowSnapshot(routing_id_, id)); |
| 2234 | } |
| 2235 | |
| 2236 | void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, |
| 2237 | const gfx::Size& size, const std::vector<unsigned char>& png) { |
| 2238 | PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id); |
| 2239 | DCHECK(it != pending_snapshots_.end()); |
| 2240 | it->second.Run(size, png); |
| 2241 | pending_snapshots_.erase(it); |
| 2242 | } |
| 2243 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2244 | // WebKit::WebViewClient ------------------------------------------------------ |
| 2245 | |
[email protected] | 916dfb6 | 2012-03-05 03:39:37 | [diff] [blame] | 2246 | WebView* RenderViewImpl::createView( |
| 2247 | WebFrame* creator, |
| 2248 | const WebURLRequest& request, |
| 2249 | const WebWindowFeatures& features, |
| 2250 | const WebString& frame_name, |
| 2251 | WebNavigationPolicy policy) { |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2252 | ViewHostMsg_CreateWindow_Params params; |
| 2253 | params.opener_id = routing_id_; |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2254 | params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame] | 2255 | if (GetContentClient()->renderer()->AllowPopup()) |
| 2256 | params.user_gesture = true; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2257 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 2258 | params.session_storage_namespace_id = session_storage_namespace_id_; |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 2259 | if (frame_name != "_blank") |
| 2260 | params.frame_name = frame_name; |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 2261 | params.opener_frame_id = creator->identifier(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2262 | params.opener_url = creator->document().url(); |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2263 | params.opener_top_level_frame_url = creator->top()->document().url(); |
[email protected] | 7f48b71 | 2013-01-25 01:48:30 | [diff] [blame] | 2264 | GURL security_url(creator->document().securityOrigin().toString().utf8()); |
| 2265 | if (!security_url.is_valid()) |
| 2266 | security_url = GURL(); |
| 2267 | params.opener_security_origin = security_url; |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2268 | params.opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
| 2269 | params.disposition = NavigationPolicyToDisposition(policy); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 2270 | if (!request.isNull()) { |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 2271 | params.target_url = request.url(); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 2272 | params.referrer = GetReferrerFromRequest(creator, request); |
| 2273 | } |
[email protected] | 453c1b2 | 2013-07-23 09:31:48 | [diff] [blame] | 2274 | params.features = features; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2275 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2276 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2277 | int32 main_frame_routing_id = MSG_ROUTING_NONE; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2278 | int32 surface_id = 0; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 2279 | int64 cloned_session_storage_namespace_id; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2280 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 2281 | RenderThread::Get()->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2282 | new ViewHostMsg_CreateWindow(params, |
| 2283 | &routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2284 | &main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2285 | &surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2286 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2287 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2288 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2289 | |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2290 | WebUserGestureIndicator::consumeUserGesture(); |
[email protected] | c5926242 | 2012-11-30 21:20:52 | [diff] [blame] | 2291 | |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 2292 | WebPreferences transferred_preferences = webkit_preferences_; |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 2293 | |
| 2294 | // Unless accelerated compositing has been explicitly disabled from the |
| 2295 | // command line (e.g. via the blacklist or about:flags) re-enable it for |
| 2296 | // new views that get spawned by this view. This gets around the issue that |
| 2297 | // background extension pages disable accelerated compositing via web prefs |
| 2298 | // but can themselves spawn a visible render view which should be allowed |
| 2299 | // use gpu acceleration. |
| 2300 | if (!webkit_preferences_.accelerated_compositing_enabled) { |
| 2301 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 2302 | if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing)) |
| 2303 | transferred_preferences.accelerated_compositing_enabled = true; |
| 2304 | } |
| 2305 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2306 | RenderViewImpl* view = RenderViewImpl::Create( |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2307 | routing_id_, |
| 2308 | renderer_preferences_, |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 2309 | transferred_preferences, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2310 | routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2311 | main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2312 | surface_id, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2313 | cloned_session_storage_namespace_id, |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 2314 | string16(), // WebCore will take care of setting the correct name. |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 2315 | true, // is_renderer_created |
| 2316 | false, // swapped_out |
| 2317 | false, // hidden |
| 2318 | 1, // next_page_id |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 2319 | screen_info_, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 2320 | accessibility_mode_, |
| 2321 | allow_partial_swap_); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2322 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2323 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2324 | // Record whether the creator frame is trying to suppress the opener field. |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2325 | view->opener_suppressed_ = params.opener_suppressed; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2326 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2327 | // Copy over the alternate error page URL so we can have alt error pages in |
| 2328 | // the new render view (we don't need the browser to send the URL back down). |
| 2329 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 2330 | |
| 2331 | return view->webview(); |
| 2332 | } |
| 2333 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2334 | WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 2335 | RenderWidget* widget = |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 2336 | RenderWidget::Create(routing_id_, popup_type, screen_info_); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2337 | return widget->webwidget(); |
| 2338 | } |
| 2339 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2340 | WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu( |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2341 | const WebPopupMenuInfo& popup_menu_info, |
| 2342 | WebExternalPopupMenuClient* popup_menu_client) { |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 2343 | // An IPC message is sent to the browser to build and display the actual |
| 2344 | // popup. The user could have time to click a different select by the time |
| 2345 | // the popup is shown. In that case external_popup_menu_ is non NULL. |
| 2346 | // By returning NULL in that case, we instruct WebKit to cancel that new |
| 2347 | // popup. So from the user perspective, only the first one will show, and |
| 2348 | // will have to close the first one before another one can be shown. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 2349 | if (external_popup_menu_) |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 2350 | return NULL; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2351 | external_popup_menu_.reset( |
| 2352 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
| 2353 | return external_popup_menu_.get(); |
| 2354 | } |
| 2355 | |
[email protected] | 2336748 | 2013-06-27 21:06:54 | [diff] [blame] | 2356 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() { |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 2357 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 2358 | return new WebStorageNamespaceImpl(session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 2359 | } |
| 2360 | |
[email protected] | fd8eb74 | 2013-08-22 00:42:00 | [diff] [blame] | 2361 | bool RenderViewImpl::shouldReportDetailedMessageForSource( |
| 2362 | const WebString& source) { |
| 2363 | return GetContentClient()->renderer()->ShouldReportDetailedMessageForSource( |
| 2364 | source); |
| 2365 | } |
| 2366 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2367 | void RenderViewImpl::didAddMessageToConsole( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2368 | const WebConsoleMessage& message, const WebString& source_name, |
[email protected] | fd8eb74 | 2013-08-22 00:42:00 | [diff] [blame] | 2369 | unsigned source_line, const WebString& stack_trace) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2370 | logging::LogSeverity log_severity = logging::LOG_VERBOSE; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 2371 | switch (message.level) { |
[email protected] | 80ac894 | 2013-01-30 22:53:22 | [diff] [blame] | 2372 | case WebConsoleMessage::LevelDebug: |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2373 | log_severity = logging::LOG_VERBOSE; |
| 2374 | break; |
| 2375 | case WebConsoleMessage::LevelLog: |
| 2376 | log_severity = logging::LOG_INFO; |
| 2377 | break; |
| 2378 | case WebConsoleMessage::LevelWarning: |
| 2379 | log_severity = logging::LOG_WARNING; |
| 2380 | break; |
| 2381 | case WebConsoleMessage::LevelError: |
| 2382 | log_severity = logging::LOG_ERROR; |
| 2383 | break; |
| 2384 | default: |
| 2385 | NOTREACHED(); |
| 2386 | } |
| 2387 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 2388 | if (shouldReportDetailedMessageForSource(source_name)) { |
| 2389 | FOR_EACH_OBSERVER( |
| 2390 | RenderViewObserver, |
| 2391 | observers_, |
| 2392 | DetailedConsoleMessageAdded(message.text, |
| 2393 | source_name, |
| 2394 | stack_trace, |
| 2395 | source_line, |
| 2396 | static_cast<int32>(log_severity))); |
| 2397 | } |
| 2398 | |
[email protected] | 07fb8d5 | 2013-08-07 17:03:51 | [diff] [blame] | 2399 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
| 2400 | static_cast<int32>(log_severity), |
| 2401 | message.text, |
| 2402 | static_cast<int32>(source_line), |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 2403 | source_name)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2404 | } |
| 2405 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2406 | void RenderViewImpl::printPage(WebFrame* frame) { |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 2407 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2408 | PrintPage(frame, handling_input_event_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2409 | } |
| 2410 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2411 | WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2412 | return notification_provider_; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 2413 | } |
| 2414 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2415 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 2416 | const WebString& path, |
| 2417 | WebFileChooserCompletion* chooser_completion) { |
| 2418 | int id = enumeration_completion_id_++; |
| 2419 | enumeration_completions_[id] = chooser_completion; |
| 2420 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 2421 | routing_id_, |
| 2422 | id, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 2423 | base::FilePath::FromUTF16Unsafe(path))); |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 2424 | } |
| 2425 | |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 2426 | void RenderViewImpl::initializeHelperPluginWebFrame( |
| 2427 | WebKit::WebHelperPlugin* plugin) { |
[email protected] | 2f61bdd | 2013-07-02 18:38:47 | [diff] [blame] | 2428 | plugin->initializeFrame(main_render_frame_.get()); |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 2429 | } |
| 2430 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2431 | void RenderViewImpl::didStartLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2432 | if (is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 2433 | DVLOG(1) << "didStartLoading called while loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2434 | return; |
| 2435 | } |
| 2436 | |
| 2437 | is_loading_ = true; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2438 | |
| 2439 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 2440 | |
| 2441 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2442 | } |
| 2443 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2444 | void RenderViewImpl::didStopLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2445 | if (!is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 2446 | DVLOG(1) << "DidStopLoading called while not loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2447 | return; |
| 2448 | } |
| 2449 | |
| 2450 | is_loading_ = false; |
| 2451 | |
| 2452 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 2453 | // when done loading. This currently isn't an issue as the favicon is only |
| 2454 | // displayed when done loading. Ideally we would send notification when |
| 2455 | // finished parsing the head, but webkit doesn't support that yet. |
| 2456 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2457 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 2458 | |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2459 | if (load_progress_tracker_ != NULL) |
| 2460 | load_progress_tracker_->DidStopLoading(); |
| 2461 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 2462 | DidStopLoadingIcons(); |
| 2463 | |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 2464 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2465 | } |
| 2466 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2467 | void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, |
| 2468 | double load_progress) { |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2469 | if (load_progress_tracker_ != NULL) |
| 2470 | load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); |
| 2471 | } |
| 2472 | |
[email protected] | 550b0c9 | 2013-02-04 05:09:15 | [diff] [blame] | 2473 | void RenderViewImpl::didCancelCompositionOnSelectionChange() { |
| 2474 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 2475 | } |
| 2476 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2477 | void RenderViewImpl::didChangeSelection(bool is_empty_selection) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 2478 | if (!handling_input_event_ && !handling_select_range_) |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 2479 | return; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 2480 | |
[email protected] | fca5202 | 2012-04-03 17:00:50 | [diff] [blame] | 2481 | if (is_empty_selection) |
| 2482 | selection_text_.clear(); |
| 2483 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 2484 | SyncSelectionIfRequired(); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2485 | UpdateTextInputType(); |
| 2486 | #if defined(OS_ANDROID) |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 2487 | UpdateTextInputState(false, true); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2488 | #endif |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2489 | } |
| 2490 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2491 | void RenderViewImpl::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 2492 | const std::string& name = UTF16ToUTF8(command_name); |
| 2493 | if (StartsWithASCII(name, "Move", true) || |
| 2494 | StartsWithASCII(name, "Insert", true) || |
| 2495 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2496 | return; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2497 | RenderThreadImpl::current()->RecordUserMetrics(name); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2498 | } |
| 2499 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2500 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2501 | if (edit_commands_.empty()) |
| 2502 | return false; |
| 2503 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2504 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2505 | if (!frame) |
| 2506 | return false; |
| 2507 | |
| 2508 | EditCommands::iterator it = edit_commands_.begin(); |
| 2509 | EditCommands::iterator end = edit_commands_.end(); |
| 2510 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2511 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2512 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 2513 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 2514 | // key (but it's the exception). Once one edit command is not executed, it |
| 2515 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2516 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 2517 | WebString::fromUTF8(it->value), |
| 2518 | GetFocusedNode())) |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2519 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2520 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2521 | } |
| 2522 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2523 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2524 | } |
| 2525 | |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2526 | WebKit::WebColorChooser* RenderViewImpl::createColorChooser( |
| 2527 | WebKit::WebColorChooserClient* client, |
| 2528 | const WebKit::WebColor& initial_color) { |
| 2529 | RendererWebColorChooserImpl* color_chooser = |
| 2530 | new RendererWebColorChooserImpl(this, client); |
| 2531 | color_chooser->Open(static_cast<SkColor>(initial_color)); |
| 2532 | return color_chooser; |
| 2533 | } |
| 2534 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2535 | bool RenderViewImpl::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 2536 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2537 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 2538 | // Do not open the file dialog in a hidden RenderView. |
| 2539 | if (is_hidden()) |
| 2540 | return false; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2541 | FileChooserParams ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2542 | if (params.directory) |
[email protected] | 6bedbef | 2013-07-31 06:33:49 | [diff] [blame] | 2543 | ipc_params.mode = FileChooserParams::UploadFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2544 | else if (params.multiSelect) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2545 | ipc_params.mode = FileChooserParams::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame] | 2546 | else if (params.saveAs) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2547 | ipc_params.mode = FileChooserParams::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2548 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2549 | ipc_params.mode = FileChooserParams::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2550 | ipc_params.title = params.title; |
| 2551 | ipc_params.default_file_name = |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 2552 | base::FilePath::FromUTF16Unsafe(params.initialValue); |
[email protected] | f9a4c41a | 2012-05-30 00:05:32 | [diff] [blame] | 2553 | ipc_params.accept_types.reserve(params.acceptTypes.size()); |
| 2554 | for (size_t i = 0; i < params.acceptTypes.size(); ++i) |
| 2555 | ipc_params.accept_types.push_back(params.acceptTypes[i]); |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 2556 | #if defined(OS_ANDROID) |
[email protected] | b7b4beb | 2013-07-09 14:06:50 | [diff] [blame] | 2557 | ipc_params.capture = params.useMediaCapture; |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 2558 | #endif |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2559 | |
| 2560 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2561 | } |
| 2562 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2563 | void RenderViewImpl::runModalAlertDialog(WebFrame* frame, |
| 2564 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2565 | RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2566 | message, |
| 2567 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2568 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2569 | NULL); |
| 2570 | } |
| 2571 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2572 | bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame, |
| 2573 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2574 | return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2575 | message, |
| 2576 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2577 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2578 | NULL); |
| 2579 | } |
| 2580 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2581 | bool RenderViewImpl::runModalPromptDialog(WebFrame* frame, |
| 2582 | const WebString& message, |
| 2583 | const WebString& default_value, |
| 2584 | WebString* actual_value) { |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2585 | string16 result; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2586 | bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2587 | message, |
| 2588 | default_value, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2589 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2590 | &result); |
| 2591 | if (ok) |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2592 | actual_value->assign(result); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2593 | return ok; |
| 2594 | } |
| 2595 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2596 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2597 | WebFrame* frame, const WebString& message) { |
[email protected] | ab533826b | 2013-05-10 23:54:56 | [diff] [blame] | 2598 | bool is_reload = false; |
| 2599 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2600 | if (ds) |
| 2601 | is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload); |
| 2602 | return runModalBeforeUnloadDialog(frame, is_reload, message); |
| 2603 | } |
| 2604 | |
| 2605 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
| 2606 | WebFrame* frame, bool is_reload, const WebString& message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2607 | // If we are swapping out, we have already run the beforeunload handler. |
| 2608 | // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 2609 | // at all, to avoid running it twice. |
| 2610 | if (is_swapped_out_) |
| 2611 | return true; |
| 2612 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2613 | bool success = false; |
| 2614 | // This is an ignored return value, but is included so we can accept the same |
| 2615 | // response as RunJavaScriptMessage. |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2616 | string16 ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2617 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2618 | routing_id_, frame->document().url(), message, is_reload, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2619 | &success, &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2620 | return success; |
| 2621 | } |
| 2622 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2623 | void RenderViewImpl::showContextMenu( |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2624 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | 3175fea | 2013-05-16 10:57:48 | [diff] [blame] | 2625 | ContextMenuParams params = ContextMenuParamsBuilder::Build(data); |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 2626 | params.source_type = context_menu_source_type_; |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 2627 | if (context_menu_source_type_ == ui::MENU_SOURCE_TOUCH_EDIT_MENU) { |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 2628 | params.x = touch_editing_context_menu_location_.x(); |
| 2629 | params.y = touch_editing_context_menu_location_.y(); |
| 2630 | } |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2631 | |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2632 | // Plugins, e.g. PDF, don't currently update the render view when their |
| 2633 | // selected text changes, but the context menu params do contain the updated |
| 2634 | // selection. If that's the case, update the render view's state just prior |
| 2635 | // to showing the context menu. |
| 2636 | // TODO(asvitkine): http://crbug.com/152432 |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 2637 | if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_, |
| 2638 | selection_text_offset_, |
| 2639 | selection_range_, |
| 2640 | params)) { |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2641 | selection_text_ = params.selection_text; |
| 2642 | // TODO(asvitkine): Text offset and range is not available in this case. |
| 2643 | selection_text_offset_ = 0; |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2644 | selection_range_ = gfx::Range(0, selection_text_.length()); |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2645 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 2646 | selection_text_, |
| 2647 | selection_text_offset_, |
| 2648 | selection_range_)); |
| 2649 | } |
| 2650 | |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2651 | // frame is NULL if invoked by BlockedPlugin. |
| 2652 | if (frame) |
| 2653 | params.frame_id = frame->identifier(); |
| 2654 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2655 | // Serializing a GURL longer than kMaxURLChars will fail, so don't do |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2656 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2657 | // in the context menu. |
| 2658 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2659 | // data encoded images. We should have a way to save them. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2660 | if (params.src_url.spec().size() > kMaxURLChars) |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2661 | params.src_url = GURL(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 2662 | context_menu_node_ = data.node; |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2663 | |
| 2664 | #if defined(OS_ANDROID) |
| 2665 | gfx::Rect start_rect; |
| 2666 | gfx::Rect end_rect; |
| 2667 | GetSelectionBounds(&start_rect, &end_rect); |
[email protected] | 326a234 | 2013-02-15 15:47:51 | [diff] [blame] | 2668 | params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom()); |
| 2669 | params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom()); |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2670 | #endif |
| 2671 | |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2672 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 2673 | |
| 2674 | FOR_EACH_OBSERVER( |
| 2675 | RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2676 | } |
| 2677 | |
[email protected] | 8b67f78f | 2013-08-13 12:04:30 | [diff] [blame] | 2678 | void RenderViewImpl::clearContextMenu() { |
| 2679 | context_menu_node_.reset(); |
| 2680 | } |
| 2681 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2682 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2683 | } |
| 2684 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2685 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 2686 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2687 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2688 | if (latest_url == target_url_) |
| 2689 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2690 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2691 | // Tell the browser to display a destination link. |
| 2692 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2693 | target_url_status_ == TARGET_PENDING) { |
| 2694 | // If we have a request in-flight, save the URL to be sent when we |
| 2695 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2696 | // any existing pending sends. |
| 2697 | pending_target_url_ = latest_url; |
| 2698 | target_url_status_ = TARGET_PENDING; |
| 2699 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2700 | // URLs larger than |kMaxURLChars| cannot be sent through IPC - |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2701 | // see |ParamTraits<GURL>|. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2702 | if (latest_url.possibly_invalid_spec().size() > kMaxURLChars) |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2703 | latest_url = GURL(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2704 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2705 | target_url_ = latest_url; |
| 2706 | target_url_status_ = TARGET_INFLIGHT; |
| 2707 | } |
| 2708 | } |
| 2709 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 2710 | gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect( |
| 2711 | const gfx::RectF& rect) const { |
| 2712 | gfx::RectF window_rect = rect; |
| 2713 | window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor()); |
| 2714 | return window_rect; |
| 2715 | } |
| 2716 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2717 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
[email protected] | a183fb8 | 2012-12-14 04:46:22 | [diff] [blame] | 2718 | // No need to update state if no page has committed yet. |
| 2719 | if (page_id_ == -1) |
| 2720 | return; |
| 2721 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2722 | int delay; |
| 2723 | if (send_content_state_immediately_) |
| 2724 | delay = 0; |
| 2725 | else if (is_hidden()) |
| 2726 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2727 | else |
| 2728 | delay = kDelaySecondsForContentStateSync; |
| 2729 | |
| 2730 | if (nav_state_sync_timer_.IsRunning()) { |
| 2731 | // The timer is already running. If the delay of the timer maches the amount |
| 2732 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2733 | // gets started with the right delay. |
| 2734 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2735 | return; |
| 2736 | nav_state_sync_timer_.Stop(); |
| 2737 | } |
| 2738 | |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 2739 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2740 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2741 | } |
| 2742 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2743 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2744 | mouse_over_url_ = GURL(url); |
| 2745 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2746 | } |
| 2747 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2748 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2749 | focus_url_ = GURL(url); |
| 2750 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2751 | } |
| 2752 | |
[email protected] | 0407e42 | 2012-05-18 19:51:25 | [diff] [blame] | 2753 | void RenderViewImpl::startDragging(WebFrame* frame, |
| 2754 | const WebDragData& data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2755 | WebDragOperationsMask mask, |
| 2756 | const WebImage& image, |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2757 | const WebPoint& webImageOffset) { |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 2758 | DropData drop_data(DropDataBuilder::Build(data)); |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2759 | drop_data.referrer_policy = frame->document().referrerPolicy(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2760 | gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2761 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2762 | drop_data, |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2763 | mask, |
[email protected] | 97612707 | 2012-05-10 20:08:11 | [diff] [blame] | 2764 | image.getSkBitmap(), |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 2765 | imageOffset, |
| 2766 | possible_drag_event_info_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2767 | } |
| 2768 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2769 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2770 | return renderer_preferences_.can_accept_load_drops; |
| 2771 | } |
| 2772 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2773 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2774 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2775 | } |
| 2776 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2777 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2778 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2779 | } |
| 2780 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2781 | void RenderViewImpl::focusedNodeChanged(const WebNode& node) { |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 2782 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 2783 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 2784 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node)); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2785 | } |
| 2786 | |
[email protected] | 572a6ca | 2012-10-11 19:38:01 | [diff] [blame] | 2787 | void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
| 2788 | Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
| 2789 | } |
| 2790 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 2791 | void RenderViewImpl::didUpdateLayout() { |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame^] | 2792 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout()); |
| 2793 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 2794 | // We don't always want to set up a timer, only if we've been put in that |
| 2795 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 2796 | // message. |
| 2797 | if (!send_preferred_size_changes_ || !webview()) |
| 2798 | return; |
| 2799 | |
| 2800 | if (check_preferred_size_timer_.IsRunning()) |
| 2801 | return; |
| 2802 | check_preferred_size_timer_.Start(FROM_HERE, |
| 2803 | TimeDelta::FromMilliseconds(0), this, |
| 2804 | &RenderViewImpl::CheckPreferredSize); |
| 2805 | } |
| 2806 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2807 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2808 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2809 | } |
| 2810 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2811 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2812 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2813 | } |
| 2814 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2815 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2816 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2817 | } |
| 2818 | |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 2819 | void RenderViewImpl::postAccessibilityEvent( |
| 2820 | const WebAXObject& obj, WebKit::WebAXEvent event) { |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2821 | if (renderer_accessibility_) { |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 2822 | renderer_accessibility_->HandleWebAccessibilityEvent(obj, event); |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2823 | } |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2824 | } |
| 2825 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2826 | void RenderViewImpl::didUpdateInspectorSetting(const WebString& key, |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2827 | const WebString& value) { |
| 2828 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2829 | key.utf8(), |
| 2830 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2831 | } |
| 2832 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2833 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2834 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2835 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2836 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2837 | // we won't have to test for user gesture anymore and we can |
| 2838 | // move that code back to render_widget.cc |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2839 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 2840 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 2841 | Send(new ViewHostMsg_Focus(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2842 | } |
| 2843 | } |
| 2844 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2845 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2846 | // TODO(jcivelli): see TODO above in didFocus(). |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2847 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 2848 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 2849 | Send(new ViewHostMsg_Blur(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2850 | } |
| 2851 | } |
| 2852 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2853 | // 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] | 2854 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2855 | // point to dispatch the ShowView message. |
| 2856 | // |
| 2857 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 2858 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2859 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2860 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2861 | if (did_show_) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2862 | // When supports_multiple_windows is disabled, popups are reusing |
| 2863 | // the same view. In some scenarios, this makes WebKit to call show() twice. |
[email protected] | c9edabd | 2013-05-23 13:56:24 | [diff] [blame] | 2864 | if (webkit_preferences_.supports_multiple_windows) |
| 2865 | NOTREACHED() << "received extraneous Show call"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2866 | return; |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2867 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2868 | did_show_ = true; |
| 2869 | |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2870 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2871 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2872 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2873 | if (!opened_by_user_gesture_) { |
| 2874 | // We exempt background tabs for compat with older versions of Chrome. |
| 2875 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2876 | // we probably don't need this check. |
| 2877 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2878 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2879 | } |
| 2880 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2881 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2882 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2883 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2884 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2885 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2886 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2887 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2888 | } |
| 2889 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2890 | void RenderViewImpl::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2891 | DCHECK(did_show_) << "should already have shown the view"; |
| 2892 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2893 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2894 | // showModalDialog to function properly. |
| 2895 | // |
| 2896 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2897 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2898 | // handed manner. |
| 2899 | // |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2900 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2901 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2902 | |
[email protected] | 08a1c810 | 2012-05-11 23:14:26 | [diff] [blame] | 2903 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal( |
| 2904 | routing_id_, opener_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2905 | } |
| 2906 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2907 | bool RenderViewImpl::enterFullScreen() { |
| 2908 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 2909 | return true; |
| 2910 | } |
| 2911 | |
| 2912 | void RenderViewImpl::exitFullScreen() { |
| 2913 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 2914 | } |
| 2915 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 2916 | bool RenderViewImpl::requestPointerLock() { |
| 2917 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2918 | } |
| 2919 | |
| 2920 | void RenderViewImpl::requestPointerUnlock() { |
| 2921 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2922 | } |
| 2923 | |
| 2924 | bool RenderViewImpl::isPointerLocked() { |
| 2925 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2926 | webwidget_mouse_lock_target_.get()); |
| 2927 | } |
| 2928 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2929 | void RenderViewImpl::didActivateCompositor(int input_handler_identifier) { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 2930 | #if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003 |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 2931 | InputHandlerManager* input_handler_manager = |
| 2932 | RenderThreadImpl::current()->input_handler_manager(); |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 2933 | if (input_handler_manager) { |
| 2934 | input_handler_manager->AddInputHandler( |
| 2935 | routing_id_, |
| 2936 | compositor_->GetInputHandler(), |
| 2937 | AsWeakPtr()); |
| 2938 | } |
[email protected] | 70cff2750 | 2013-01-17 09:16:49 | [diff] [blame] | 2939 | #endif |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2940 | |
| 2941 | RenderWidget::didActivateCompositor(input_handler_identifier); |
| 2942 | } |
| 2943 | |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2944 | void RenderViewImpl::didHandleGestureEvent( |
| 2945 | const WebGestureEvent& event, |
| 2946 | bool event_cancelled) { |
| 2947 | RenderWidget::didHandleGestureEvent(event, event_cancelled); |
| 2948 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2949 | DidHandleGestureEvent(event)); |
| 2950 | } |
| 2951 | |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 2952 | void RenderViewImpl::initializeLayerTreeView() { |
| 2953 | RenderWidget::initializeLayerTreeView(); |
| 2954 | RenderWidgetCompositor* rwc = compositor(); |
| 2955 | if (!rwc || !webview() || !webview()->devToolsAgent()) |
| 2956 | return; |
| 2957 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 2958 | } |
| 2959 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2960 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2961 | |
[email protected] | 97b150db | 2012-08-16 18:26:02 | [diff] [blame] | 2962 | WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
| 2963 | WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) { |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 2964 | FOR_EACH_OBSERVER( |
| 2965 | RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client)); |
[email protected] | 7198402c | 2011-04-11 12:15:17 | [diff] [blame] | 2966 | |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2967 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | 75abf38 | 2013-07-09 08:14:19 | [diff] [blame] | 2968 | #if defined(ENABLE_WEBRTC) |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 2969 | if (!InitializeMediaStreamClient()) |
| 2970 | return NULL; |
| 2971 | |
[email protected] | 75abf38 | 2013-07-09 08:14:19 | [diff] [blame] | 2972 | #if !defined(GOOGLE_TV) |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 2973 | if (media_stream_client_->IsMediaStream(url)) { |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 2974 | #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
| 2975 | bool found_neon = |
| 2976 | (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; |
| 2977 | UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon); |
| 2978 | #endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 2979 | return new WebMediaPlayerMS( |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 2980 | frame, client, AsWeakPtr(), media_stream_client_, new RenderMediaLog()); |
[email protected] | d05e216 | 2012-11-16 22:21:46 | [diff] [blame] | 2981 | } |
[email protected] | 75abf38 | 2013-07-09 08:14:19 | [diff] [blame] | 2982 | #endif // !defined(GOOGLE_TV) |
| 2983 | #endif // defined(ENABLE_WEBRTC) |
[email protected] | d05e216 | 2012-11-16 22:21:46 | [diff] [blame] | 2984 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2985 | #if defined(OS_ANDROID) |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2986 | GpuChannelHost* gpu_channel_host = |
| 2987 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2988 | CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2989 | if (!gpu_channel_host) { |
| 2990 | LOG(ERROR) << "Failed to establish GPU channel for media player"; |
| 2991 | return NULL; |
| 2992 | } |
| 2993 | |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 2994 | scoped_refptr<cc::ContextProvider> context_provider = |
| 2995 | RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); |
[email protected] | 3aaba57 | 2013-08-10 15:10:38 | [diff] [blame] | 2996 | scoped_ptr<StreamTextureFactory> stream_texture_factory; |
| 2997 | if (UsingSynchronousRendererCompositor()) { |
[email protected] | 3a59bb9 | 2013-08-22 18:54:08 | [diff] [blame] | 2998 | SynchronousCompositorFactory* factory = |
| 2999 | SynchronousCompositorFactory::GetInstance(); |
| 3000 | stream_texture_factory = factory->CreateStreamTextureFactory(routing_id_); |
[email protected] | 3aaba57 | 2013-08-10 15:10:38 | [diff] [blame] | 3001 | } else { |
[email protected] | 76e9cc4 | 2013-09-07 01:02:09 | [diff] [blame] | 3002 | if (!context_provider.get()) { |
| 3003 | LOG(ERROR) << "Failed to get context3d for media player"; |
| 3004 | return NULL; |
| 3005 | } |
| 3006 | |
[email protected] | 3aaba57 | 2013-08-10 15:10:38 | [diff] [blame] | 3007 | stream_texture_factory.reset(new StreamTextureFactoryImpl( |
| 3008 | context_provider->Context3d(), gpu_channel_host, routing_id_)); |
| 3009 | } |
| 3010 | |
[email protected] | 76e9cc4 | 2013-09-07 01:02:09 | [diff] [blame] | 3011 | if (!media_player_proxy_) { |
| 3012 | media_player_proxy_ = new WebMediaPlayerProxyAndroid( |
| 3013 | this, media_player_manager_.get()); |
| 3014 | } |
| 3015 | |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 3016 | scoped_ptr<WebMediaPlayerAndroid> web_media_player_android( |
| 3017 | new WebMediaPlayerAndroid( |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 3018 | frame, |
| 3019 | client, |
[email protected] | 9aff54d | 2013-06-18 18:38:50 | [diff] [blame] | 3020 | AsWeakPtr(), |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 3021 | media_player_manager_.get(), |
| 3022 | media_player_proxy_, |
[email protected] | 3aaba57 | 2013-08-10 15:10:38 | [diff] [blame] | 3023 | stream_texture_factory.release(), |
[email protected] | 4aec865 | 2013-08-23 05:32:47 | [diff] [blame] | 3024 | RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(), |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 3025 | new RenderMediaLog())); |
| 3026 | #if defined(ENABLE_WEBRTC) && defined(GOOGLE_TV) |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 3027 | if (media_stream_client_->IsMediaStream(url)) { |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 3028 | RTCVideoDecoderFactoryTv* factory = RenderThreadImpl::current() |
| 3029 | ->GetMediaStreamDependencyFactory()->decoder_factory_tv(); |
[email protected] | 75abf38 | 2013-07-09 08:14:19 | [diff] [blame] | 3030 | // |media_stream_client| and |factory| outlives |web_media_player_android|. |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 3031 | if (!factory->AcquireDemuxer() || |
| 3032 | !web_media_player_android->InjectMediaStream( |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 3033 | media_stream_client_, |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 3034 | factory, |
| 3035 | base::Bind( |
| 3036 | base::IgnoreResult(&RTCVideoDecoderFactoryTv::ReleaseDemuxer), |
| 3037 | base::Unretained(factory)))) { |
| 3038 | LOG(ERROR) << "Failed to inject media stream."; |
| 3039 | return NULL; |
| 3040 | } |
| 3041 | } |
| 3042 | #endif // defined(ENABLE_WEBRTC) && defined(GOOGLE_TV) |
| 3043 | return web_media_player_android.release(); |
| 3044 | #endif // defined(OS_ANDROID) |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 3045 | |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 3046 | scoped_refptr<media::AudioRendererSink> sink; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3047 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
[email protected] | 17c4ce62f | 2013-05-03 19:54:02 | [diff] [blame] | 3048 | sink = RenderThreadImpl::current()->GetAudioRendererMixerManager()-> |
| 3049 | CreateInput(routing_id_); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 3050 | DVLOG(1) << "Using AudioRendererMixerManager-provided sink: " << sink.get(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3051 | } |
| 3052 | |
[email protected] | 1cad880 | 2013-08-13 16:54:32 | [diff] [blame] | 3053 | scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories = |
[email protected] | 86e3a70 | 2013-07-24 12:22:53 | [diff] [blame] | 3054 | RenderThreadImpl::current()->GetGpuFactories( |
| 3055 | RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy()); |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 3056 | |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 3057 | WebMediaPlayerParams params( |
[email protected] | c1330c8 | 2013-06-06 02:23:25 | [diff] [blame] | 3058 | RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(), |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 3059 | base::Bind(&ContentRendererClient::DeferMediaLoad, |
| 3060 | base::Unretained(GetContentClient()->renderer()), |
| 3061 | static_cast<RenderView*>(this)), |
| 3062 | sink, |
| 3063 | gpu_factories, |
| 3064 | new RenderMediaLog()); |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 3065 | return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3066 | } |
| 3067 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3068 | WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { |
[email protected] | 8ff18107 | 2010-11-29 17:09:38 | [diff] [blame] | 3069 | return &cookie_jar_; |
| 3070 | } |
| 3071 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 3072 | void RenderViewImpl::didAccessInitialDocument(WebFrame* frame) { |
| 3073 | // Notify the browser process that it is no longer safe to show the pending |
| 3074 | // URL of the main frame, since a URL spoof is now possible. |
| 3075 | if (!frame->parent() && page_id_ == -1) |
| 3076 | Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_)); |
| 3077 | } |
| 3078 | |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 3079 | void RenderViewImpl::didDisownOpener(WebKit::WebFrame* frame) { |
[email protected] | 29ece2e | 2013-04-03 04:53:52 | [diff] [blame] | 3080 | // We only need to notify the browser if the active, top-level frame clears |
| 3081 | // its opener. We can ignore cases where a swapped out frame clears its |
| 3082 | // opener after hearing about it from the browser, and the browser does not |
| 3083 | // (yet) care about subframe openers. |
| 3084 | if (is_swapped_out_ || frame->parent()) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 3085 | return; |
| 3086 | |
| 3087 | // Notify WebContents and all its swapped out RenderViews. |
| 3088 | Send(new ViewHostMsg_DidDisownOpener(routing_id_)); |
| 3089 | } |
| 3090 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3091 | void RenderViewImpl::frameDetached(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3092 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 3093 | } |
| 3094 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3095 | void RenderViewImpl::willClose(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3096 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3097 | } |
| 3098 | |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 3099 | void RenderViewImpl::Repaint(const gfx::Size& size) { |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 3100 | OnRepaint(size); |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 3101 | } |
| 3102 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 3103 | void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name, |
| 3104 | const std::string& value) { |
| 3105 | EditCommands edit_commands; |
| 3106 | edit_commands.push_back(EditCommand(name, value)); |
| 3107 | OnSetEditCommandsForNextKeyEvent(edit_commands); |
| 3108 | } |
| 3109 | |
| 3110 | void RenderViewImpl::ClearEditCommands() { |
| 3111 | edit_commands_.clear(); |
| 3112 | } |
| 3113 | |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 3114 | SSLStatus RenderViewImpl::GetSSLStatusOfFrame(WebKit::WebFrame* frame) const { |
[email protected] | 83c0abca | 2013-07-23 20:09:42 | [diff] [blame] | 3115 | std::string security_info; |
| 3116 | if (frame && frame->dataSource()) |
| 3117 | security_info = frame->dataSource()->response().securityInfo(); |
| 3118 | |
| 3119 | SSLStatus ssl_status; |
| 3120 | DeserializeSecurityInfo(security_info, |
| 3121 | &ssl_status.cert_id, |
| 3122 | &ssl_status.cert_status, |
| 3123 | &ssl_status.security_bits, |
| 3124 | &ssl_status.connection_status); |
| 3125 | return ssl_status; |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 3126 | } |
| 3127 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3128 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3129 | WebFrame* frame, WebDataSource::ExtraData* extraData, |
| 3130 | const WebURLRequest& request, WebNavigationType type, |
| 3131 | WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 099df81cf | 2012-11-14 17:44:04 | [diff] [blame] | 3132 | if (request.url() != GURL(kSwappedOutURL) && |
| 3133 | GetContentClient()->renderer()->HandleNavigation(frame, request, type, |
| 3134 | default_policy, |
| 3135 | is_redirect)) { |
| 3136 | return WebKit::WebNavigationPolicyIgnore; |
| 3137 | } |
| 3138 | |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 3139 | Referrer referrer(GetReferrerFromRequest(frame, request)); |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3140 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3141 | if (is_swapped_out_) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3142 | if (request.url() != GURL(kSwappedOutURL)) { |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3143 | // Targeted links may try to navigate a swapped out frame. Allow the |
| 3144 | // browser process to navigate the tab instead. Note that it is also |
| 3145 | // possible for non-targeted navigations (from this view) to arrive |
| 3146 | // here just after we are swapped out. It's ok to send them to the |
| 3147 | // browser, as long as they're for the top level frame. |
| 3148 | // TODO(creis): Ensure this supports targeted form submissions when |
| 3149 | // fixing http://crbug.com/101395. |
| 3150 | if (frame->parent() == NULL) { |
| 3151 | OpenURL(frame, request.url(), referrer, default_policy); |
| 3152 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 3153 | } |
| 3154 | |
| 3155 | // We should otherwise ignore in-process iframe navigations, if they |
| 3156 | // arrive just after we are swapped out. |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 3157 | return WebKit::WebNavigationPolicyIgnore; |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3158 | } |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 3159 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3160 | // Allow kSwappedOutURL to complete. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3161 | return default_policy; |
| 3162 | } |
| 3163 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3164 | // Webkit is asking whether to navigate to a new URL. |
| 3165 | // This is fine normally, except if we're showing UI from one security |
| 3166 | // context and they're trying to navigate to a different context. |
| 3167 | const GURL& url = request.url(); |
| 3168 | |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 3169 | // A content initiated navigation may have originated from a link-click, |
| 3170 | // script, drag-n-drop operation, etc. |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3171 | bool is_content_initiated = static_cast<DocumentState*>(extraData)-> |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3172 | navigation_state()->is_content_initiated(); |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 3173 | |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3174 | // Experimental: |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 3175 | // If --enable-strict-site-isolation or --site-per-process is enabled, send |
| 3176 | // all top-level navigations to the browser to let it swap processes when |
| 3177 | // crossing site boundaries. This is currently expected to break some script |
| 3178 | // calls and navigations, such as form submissions. |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3179 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 3180 | bool force_swap_due_to_flag = |
| 3181 | command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
| 3182 | command_line.HasSwitch(switches::kSitePerProcess); |
| 3183 | if (force_swap_due_to_flag && |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3184 | !frame->parent() && (is_content_initiated || is_redirect)) { |
| 3185 | WebString origin_str = frame->document().securityOrigin().toString(); |
| 3186 | GURL frame_url(origin_str.utf8().data()); |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 3187 | // TODO(cevans): revisit whether this site check is still necessary once |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3188 | // crbug.com/101395 is fixed. |
[email protected] | ed32c21 | 2013-05-14 20:49:29 | [diff] [blame] | 3189 | bool same_domain_or_host = |
| 3190 | net::registry_controlled_domains::SameDomainOrHost( |
| 3191 | frame_url, |
| 3192 | url, |
| 3193 | net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 3194 | if (!same_domain_or_host || frame_url.scheme() != url.scheme()) { |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3195 | OpenURL(frame, url, referrer, default_policy); |
| 3196 | return WebKit::WebNavigationPolicyIgnore; |
| 3197 | } |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3198 | } |
| 3199 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3200 | // 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] | 3201 | if (is_content_initiated) { |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 3202 | bool is_form_post = ((type == WebKit::WebNavigationTypeFormSubmitted) || |
| 3203 | (type == WebKit::WebNavigationTypeFormResubmitted)) && |
| 3204 | EqualsASCII(request.httpMethod(), "POST"); |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3205 | bool browser_handles_request = |
| 3206 | renderer_preferences_.browser_handles_non_local_top_level_requests && |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 3207 | IsNonLocalTopLevelNavigation(url, frame, type, is_form_post); |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3208 | if (!browser_handles_request) { |
| 3209 | browser_handles_request = |
| 3210 | renderer_preferences_.browser_handles_all_top_level_requests && |
| 3211 | IsTopLevelNavigation(frame); |
| 3212 | } |
| 3213 | |
| 3214 | if (browser_handles_request) { |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 3215 | // Reset these counters as the RenderView could be reused for the next |
| 3216 | // navigation. |
| 3217 | page_id_ = -1; |
| 3218 | last_page_id_sent_to_browser_ = -1; |
| 3219 | OpenURL(frame, url, referrer, default_policy); |
| 3220 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 3221 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3222 | } |
| 3223 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3224 | // Use the frame's original request's URL rather than the document's URL for |
| 3225 | // subsequent checks. For a popup, the document's URL may become the opener |
| 3226 | // window's URL if the opener has called document.write(). |
| 3227 | // See http://crbug.com/93517. |
| 3228 | GURL old_url(frame->dataSource()->request().url()); |
| 3229 | |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3230 | // 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] | 3231 | // 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] | 3232 | // top-level navigations (not iframes). But we sometimes navigate to |
| 3233 | // about:blank to clear a tab, and we want to still allow that. |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3234 | // |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3235 | // Note: this is known to break POST submissions when crossing process |
| 3236 | // boundaries until http://crbug.com/101395 is fixed. This is better for |
| 3237 | // security than loading a WebUI, extension or app page in the wrong process. |
| 3238 | // POST requests don't work because this mechanism does not preserve form |
| 3239 | // POST data. We will need to send the request's httpBody data up to the |
| 3240 | // browser process, and issue a special POST navigation in WebKit (via |
[email protected] | 8f4da8c | 2011-02-09 19:49:57 | [diff] [blame] | 3241 | // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl |
| 3242 | // for examples of how to send the httpBody data. |
[email protected] | 2762a1b | 2011-12-09 15:25:22 | [diff] [blame] | 3243 | if (!frame->parent() && is_content_initiated && |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3244 | !url.SchemeIs(chrome::kAboutScheme)) { |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3245 | bool send_referrer = false; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3246 | |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 3247 | // All navigations to or from WebUI URLs or within WebUI-enabled |
| 3248 | // RenderProcesses must be handled by the browser process so that the |
| 3249 | // correct bindings and data sources can be registered. |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3250 | // Similarly, navigations to view-source URLs or within ViewSource mode |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 3251 | // must be handled by the browser process (except for reloads - those are |
| 3252 | // safe to leave within the renderer). |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3253 | // Lastly, access to file:// URLs from non-file:// URL pages must be |
| 3254 | // handled by the browser so that ordinary renderer processes don't get |
| 3255 | // blessed with file permissions. |
| 3256 | int cumulative_bindings = RenderProcess::current()->GetEnabledBindings(); |
| 3257 | bool is_initial_navigation = page_id_ == -1; |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 3258 | bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) || |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3259 | (cumulative_bindings & BINDINGS_POLICY_WEB_UI) || |
[email protected] | dbdda540 | 2013-05-30 22:13:48 | [diff] [blame] | 3260 | url.SchemeIs(kViewSourceScheme) || |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 3261 | (frame->isViewSourceModeEnabled() && |
| 3262 | type != WebKit::WebNavigationTypeReload); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3263 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3264 | if (!should_fork && url.SchemeIs(chrome::kFileScheme)) { |
| 3265 | // Fork non-file to file opens. Check the opener URL if this is the |
| 3266 | // initial navigation in a newly opened window. |
| 3267 | GURL source_url(old_url); |
| 3268 | if (is_initial_navigation && source_url.is_empty() && frame->opener()) |
| 3269 | source_url = frame->opener()->top()->document().url(); |
| 3270 | DCHECK(!source_url.is_empty()); |
| 3271 | should_fork = !source_url.SchemeIs(chrome::kFileScheme); |
| 3272 | } |
| 3273 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3274 | if (!should_fork) { |
| 3275 | // Give the embedder a chance. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 3276 | should_fork = GetContentClient()->renderer()->ShouldFork( |
| 3277 | frame, url, request.httpMethod().utf8(), is_initial_navigation, |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 3278 | is_redirect, &send_referrer); |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | if (should_fork) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3282 | OpenURL( |
| 3283 | frame, url, send_referrer ? referrer : Referrer(), default_policy); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3284 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 3285 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 3289 | // its own process. This is done by sites like Gmail that try to open links |
| 3290 | // in new windows without script connections back to the original page. We |
| 3291 | // treat such cases as browser navigations (in which we will create a new |
| 3292 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 3293 | // |
| 3294 | // We use the following heuristic to decide whether to fork a new page in its |
| 3295 | // own process: |
| 3296 | // The parent page must open a new tab to about:blank, set the new tab's |
| 3297 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 3298 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 3299 | // |
| 3300 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 3301 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3302 | bool is_fork = |
| 3303 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 3304 | old_url == GURL(kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3305 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3306 | historyBackListCount() < 1 && |
| 3307 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3308 | // The parent page must have set the child's window.opener to null before |
| 3309 | // redirecting to the desired URL. |
| 3310 | frame->opener() == NULL && |
| 3311 | // Must be a top-level frame. |
| 3312 | frame->parent() == NULL && |
| 3313 | // Must not have issued the request from this page. |
| 3314 | is_content_initiated && |
| 3315 | // Must be targeted at the current tab. |
| 3316 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 3317 | // Must be a JavaScript navigation, which appears as "other". |
| 3318 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 3319 | |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 3320 | if (is_fork) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3321 | // Open the URL via the browser, not via WebKit. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3322 | OpenURL(frame, url, Referrer(), default_policy); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3323 | return WebKit::WebNavigationPolicyIgnore; |
| 3324 | } |
| 3325 | |
| 3326 | return default_policy; |
| 3327 | } |
| 3328 | |
[email protected] | f4f40a05 | 2013-04-19 15:28:11 | [diff] [blame] | 3329 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
| 3330 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 89bc54c6 | 2013-04-24 01:51:33 | [diff] [blame] | 3331 | WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3332 | return decidePolicyForNavigation(frame, |
| 3333 | frame->provisionalDataSource()->extraData(), |
[email protected] | 89bc54c6 | 2013-04-24 01:51:33 | [diff] [blame] | 3334 | request, type, default_policy, is_redirect); |
[email protected] | f4f40a05 | 2013-04-19 15:28:11 | [diff] [blame] | 3335 | } |
| 3336 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3337 | void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame, |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 3338 | const WebKit::WebFormElement& form) { |
[email protected] | 0660a8c | 2013-08-16 01:09:12 | [diff] [blame] | 3339 | FOR_EACH_OBSERVER( |
| 3340 | RenderViewObserver, observers_, WillSendSubmitEvent(frame, form)); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 3341 | } |
| 3342 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3343 | void RenderViewImpl::willSubmitForm(WebFrame* frame, |
| 3344 | const WebFormElement& form) { |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 3345 | FOR_EACH_OBSERVER( |
| 3346 | RenderViewObserver, observers_, WillSubmitForm(frame, form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3347 | } |
| 3348 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3349 | void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3350 | bool content_initiated = !pending_navigation_params_.get(); |
| 3351 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3352 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3353 | if (!document_state) { |
| 3354 | document_state = new DocumentState; |
| 3355 | ds->setExtraData(document_state); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3356 | if (!content_initiated) |
| 3357 | PopulateDocumentStateFromPending(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3358 | } |
| 3359 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3360 | // Carry over the user agent override flag, if it exists. |
| 3361 | if (content_initiated && webview() && webview()->mainFrame() && |
| 3362 | webview()->mainFrame()->dataSource()) { |
| 3363 | DocumentState* old_document_state = |
| 3364 | DocumentState::FromDataSource(webview()->mainFrame()->dataSource()); |
| 3365 | if (old_document_state) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3366 | InternalDocumentStateData* internal_data = |
| 3367 | InternalDocumentStateData::FromDocumentState(document_state); |
| 3368 | InternalDocumentStateData* old_internal_data = |
| 3369 | InternalDocumentStateData::FromDocumentState(old_document_state); |
| 3370 | internal_data->set_is_overriding_user_agent( |
| 3371 | old_internal_data->is_overriding_user_agent()); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3372 | } |
| 3373 | } |
| 3374 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3375 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 3376 | // non-null NavigationState. |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3377 | if (content_initiated) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3378 | document_state->set_navigation_state( |
| 3379 | NavigationState::CreateContentInitiated()); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3380 | } else { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3381 | document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 3382 | pending_navigation_params_.reset(); |
| 3383 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3384 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3385 | // DocumentState::referred_by_prefetcher_ is true if we are |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3386 | // navigating from a page that used prefetching using a link on that |
| 3387 | // page. We are early enough in the request process here that we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3388 | // can still see the DocumentState of the previous page and set |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3389 | // this value appropriately. |
| 3390 | // TODO(gavinp): catch the important case of navigation in a new |
| 3391 | // renderer process. |
| 3392 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 3393 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3394 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3395 | const GURL referrer( |
| 3396 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 3397 | if (!referrer.is_empty() && |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3398 | DocumentState::FromDataSource( |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3399 | old_frame->dataSource())->was_prefetcher()) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 3400 | for (; old_frame; old_frame = old_frame->traverseNext(false)) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3401 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 3402 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3403 | document_state->set_was_referred_by_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3404 | break; |
| 3405 | } |
| 3406 | } |
| 3407 | } |
| 3408 | } |
| 3409 | } |
| 3410 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3411 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3412 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3413 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3414 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3415 | document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3416 | break; |
| 3417 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3418 | document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3419 | break; |
| 3420 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3421 | document_state->set_load_type( |
| 3422 | DocumentState::LINK_LOAD_CACHE_STALE_OK); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3423 | break; |
| 3424 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3425 | document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3426 | break; |
| 3427 | } |
| 3428 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3429 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 3430 | FOR_EACH_OBSERVER( |
| 3431 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3432 | } |
| 3433 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3434 | void RenderViewImpl::PopulateDocumentStateFromPending( |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3435 | DocumentState* document_state) { |
| 3436 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3437 | document_state->set_request_time(params.request_time); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3438 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3439 | InternalDocumentStateData* internal_data = |
| 3440 | InternalDocumentStateData::FromDocumentState(document_state); |
| 3441 | |
[email protected] | 44b0581 | 2013-08-19 07:59:35 | [diff] [blame] | 3442 | if (!params.url.SchemeIs(kJavaScriptScheme) && |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3443 | params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { |
| 3444 | // We're doing a load of a page that was restored from the last session. By |
| 3445 | // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which |
| 3446 | // can result in stale data for pages that are set to expire. We explicitly |
| 3447 | // override that by setting the policy here so that as necessary we load |
| 3448 | // from the network. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3449 | internal_data->set_cache_policy_override( |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3450 | WebURLRequest::UseProtocolCachePolicy); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | if (IsReload(params)) |
| 3454 | document_state->set_load_type(DocumentState::RELOAD); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 3455 | else if (params.page_state.IsValid()) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3456 | document_state->set_load_type(DocumentState::HISTORY_LOAD); |
| 3457 | else |
| 3458 | document_state->set_load_type(DocumentState::NORMAL_LOAD); |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3459 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3460 | internal_data->set_referrer_policy(params.referrer.policy); |
| 3461 | internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent); |
| 3462 | internal_data->set_must_reset_scroll_and_scale_state( |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3463 | params.navigation_type == |
| 3464 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 3465 | document_state->set_can_load_local_resources(params.can_load_local_resources); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3466 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3467 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3468 | NavigationState* RenderViewImpl::CreateNavigationStateFromPending() { |
| 3469 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
| 3470 | NavigationState* navigation_state = NULL; |
| 3471 | |
| 3472 | // A navigation resulting from loading a javascript URL should not be treated |
| 3473 | // as a browser initiated event. Instead, we want it to look as if the page |
| 3474 | // initiated any load resulting from JS execution. |
[email protected] | 44b0581 | 2013-08-19 07:59:35 | [diff] [blame] | 3475 | if (!params.url.SchemeIs(kJavaScriptScheme)) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3476 | navigation_state = NavigationState::CreateBrowserInitiated( |
| 3477 | params.page_id, |
| 3478 | params.pending_history_list_offset, |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 3479 | params.should_clear_history_list, |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3480 | params.transition); |
| 3481 | navigation_state->set_transferred_request_child_id( |
| 3482 | params.transferred_request_child_id); |
| 3483 | navigation_state->set_transferred_request_request_id( |
| 3484 | params.transferred_request_request_id); |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 3485 | navigation_state->set_allow_download(params.allow_download); |
[email protected] | f050fde | 2013-03-21 00:40:45 | [diff] [blame] | 3486 | navigation_state->set_extra_headers(params.extra_headers); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3487 | } else { |
| 3488 | navigation_state = NavigationState::CreateContentInitiated(); |
| 3489 | } |
| 3490 | return navigation_state; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3491 | } |
| 3492 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3493 | void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) { |
| 3494 | bool enable_viewport = |
[email protected] | 06ea34a | 2012-05-07 18:52:10 | [diff] [blame] | 3495 | command_line.HasSwitch(switches::kEnableViewport); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3496 | bool enable_fixed_layout = |
| 3497 | command_line.HasSwitch(switches::kEnableFixedLayout); |
| 3498 | |
| 3499 | webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3500 | |
[email protected] | 47e932da | 2013-03-07 00:11:24 | [diff] [blame] | 3501 | // If viewport tag is enabled, then the WebKit side will take care |
| 3502 | // of setting the fixed layout size and page scale limits. |
| 3503 | if (enable_viewport) |
| 3504 | return; |
| 3505 | |
[email protected] | a02a0c9 | 2013-08-12 20:18:58 | [diff] [blame] | 3506 | // When navigating to a new page, reset the page scale factor to be 1.0. |
| 3507 | webview()->setInitialPageScaleOverride(1.f); |
| 3508 | |
[email protected] | 47e932da | 2013-03-07 00:11:24 | [diff] [blame] | 3509 | if (enable_fixed_layout) { |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3510 | std::string str = |
| 3511 | command_line.GetSwitchValueASCII(switches::kEnableFixedLayout); |
| 3512 | std::vector<std::string> tokens; |
| 3513 | base::SplitString(str, ',', &tokens); |
| 3514 | if (tokens.size() == 2) { |
| 3515 | int width, height; |
| 3516 | if (base::StringToInt(tokens[0], &width) && |
| 3517 | base::StringToInt(tokens[1], &height)) |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3518 | webview()->setFixedLayoutSize(WebSize(width, height)); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3519 | } |
| 3520 | } |
[email protected] | e4cd82e | 2013-04-10 15:20:38 | [diff] [blame] | 3521 | float maxPageScaleFactor = |
| 3522 | command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ; |
| 3523 | webview()->setPageScaleFactorLimits(1, maxPageScaleFactor); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3524 | } |
| 3525 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3526 | void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3527 | WebDataSource* ds = frame->provisionalDataSource(); |
[email protected] | 09c48ef5 | 2013-01-09 12:25:07 | [diff] [blame] | 3528 | |
| 3529 | // In fast/loader/stop-provisional-loads.html, we abort the load before this |
| 3530 | // callback is invoked. |
| 3531 | if (!ds) |
| 3532 | return; |
| 3533 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3534 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3535 | |
[email protected] | 890b06ca | 2012-12-13 21:07:36 | [diff] [blame] | 3536 | // We should only navigate to swappedout:// when is_swapped_out_ is true. |
| 3537 | CHECK((ds->request().url() != GURL(kSwappedOutURL)) || |
| 3538 | is_swapped_out_) << "Heard swappedout:// when not swapped out."; |
| 3539 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3540 | // Update the request time if WebKit has better knowledge of it. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3541 | if (document_state->request_time().is_null()) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3542 | double event_time = ds->triggeringEventTime(); |
| 3543 | if (event_time != 0.0) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3544 | document_state->set_request_time(Time::FromDoubleT(event_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3545 | } |
| 3546 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3547 | // Start time is only set after request time. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3548 | document_state->set_start_load_time(Time::Now()); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3549 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3550 | bool is_top_most = !frame->parent(); |
| 3551 | if (is_top_most) { |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 3552 | navigation_gesture_ = WebUserGestureIndicator::isProcessingUserGesture() ? |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 3553 | NavigationGestureUser : NavigationGestureAuto; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3554 | } else if (frame->parent()->isLoading()) { |
| 3555 | // 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] | 3556 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3557 | document_state->navigation_state()->set_transition_type( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3558 | PAGE_TRANSITION_AUTO_SUBFRAME); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3559 | } |
| 3560 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3561 | FOR_EACH_OBSERVER( |
| 3562 | RenderViewObserver, observers_, DidStartProvisionalLoad(frame)); |
| 3563 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3564 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | d37c33e | 2012-10-12 13:35:13 | [diff] [blame] | 3565 | routing_id_, frame->identifier(), |
| 3566 | frame->parent() ? frame->parent()->identifier() : -1, |
[email protected] | 434bc9b | 2012-11-27 21:22:14 | [diff] [blame] | 3567 | is_top_most, ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3568 | } |
| 3569 | |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3570 | void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad( |
| 3571 | WebFrame* frame) { |
| 3572 | if (frame->parent()) |
| 3573 | return; |
| 3574 | // Received a redirect on the main frame. |
| 3575 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 3576 | if (!data_source) { |
| 3577 | // Should only be invoked when we have a data source. |
| 3578 | NOTREACHED(); |
| 3579 | return; |
| 3580 | } |
| 3581 | std::vector<GURL> redirects; |
| 3582 | GetRedirectChain(data_source, &redirects); |
| 3583 | if (redirects.size() >= 2) { |
| 3584 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
[email protected] | 434bc9b | 2012-11-27 21:22:14 | [diff] [blame] | 3585 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3586 | } |
| 3587 | } |
| 3588 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3589 | void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame, |
| 3590 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3591 | // Notify the browser that we failed a provisional load with an error. |
| 3592 | // |
| 3593 | // Note: It is important this notification occur before DidStopLoading so the |
| 3594 | // SSL manager can react to the provisional load failure before being |
| 3595 | // notified the load stopped. |
| 3596 | // |
| 3597 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3598 | DCHECK(ds); |
| 3599 | |
| 3600 | const WebURLRequest& failed_request = ds->request(); |
| 3601 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3602 | FOR_EACH_OBSERVER( |
| 3603 | RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error)); |
| 3604 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3605 | bool show_repost_interstitial = |
| 3606 | (error.reason == net::ERR_CACHE_MISS && |
| 3607 | EqualsASCII(failed_request.httpMethod(), "POST")); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3608 | |
| 3609 | ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 3610 | params.frame_id = frame->identifier(); |
| 3611 | params.is_main_frame = !frame->parent(); |
| 3612 | params.error_code = error.reason; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3613 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 3614 | frame, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3615 | failed_request, |
| 3616 | error, |
| 3617 | NULL, |
| 3618 | ¶ms.error_description); |
| 3619 | params.url = error.unreachableURL; |
| 3620 | params.showing_repost_interstitial = show_repost_interstitial; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3621 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3622 | routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3623 | |
| 3624 | // Don't display an error page if this is simply a cancelled load. Aside |
| 3625 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 3626 | if (error.reason == net::ERR_ABORTED) |
| 3627 | return; |
| 3628 | |
[email protected] | f677288e | 2013-09-18 02:11:00 | [diff] [blame] | 3629 | // Don't display "client blocked" error page if browser has asked us not to. |
| 3630 | if (error.reason == net::ERR_BLOCKED_BY_CLIENT && |
| 3631 | renderer_preferences_.disable_client_blocked_error_page) { |
| 3632 | return; |
| 3633 | } |
| 3634 | |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 3635 | if (RenderThreadImpl::current()->layout_test_mode()) |
[email protected] | ac7f5a0 | 2013-03-16 16:14:41 | [diff] [blame] | 3636 | return; |
| 3637 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3638 | // Make sure we never show errors in view source mode. |
| 3639 | frame->enableViewSourceMode(false); |
| 3640 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3641 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3642 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3643 | |
| 3644 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 3645 | // 'replace' load. This is necessary to avoid messing up session history. |
| 3646 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 3647 | // as session history is concerned. |
| 3648 | // |
| 3649 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 3650 | // the page id. |
| 3651 | // |
| 3652 | bool replace = |
| 3653 | navigation_state->pending_page_id() != -1 || |
[email protected] | 026aac2 | 2013-07-10 02:09:11 | [diff] [blame] | 3654 | PageTransitionCoreTypeIs(navigation_state->transition_type(), |
| 3655 | PAGE_TRANSITION_AUTO_SUBFRAME); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3656 | |
| 3657 | // If we failed on a browser initiated request, then make sure that our error |
| 3658 | // page load is regarded as the same browser initiated request. |
| 3659 | if (!navigation_state->is_content_initiated()) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3660 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 3661 | pending_navigation_params_->page_id = |
| 3662 | navigation_state->pending_page_id(); |
| 3663 | pending_navigation_params_->pending_history_list_offset = |
| 3664 | navigation_state->pending_history_list_offset(); |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 3665 | pending_navigation_params_->should_clear_history_list = |
| 3666 | navigation_state->history_list_was_cleared(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3667 | pending_navigation_params_->transition = |
| 3668 | navigation_state->transition_type(); |
| 3669 | pending_navigation_params_->request_time = |
| 3670 | document_state->request_time(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | // Provide the user with a more helpful error page? |
| 3674 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 3675 | return; |
| 3676 | |
| 3677 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3678 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3679 | } |
| 3680 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3681 | void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame, |
| 3682 | bool is_new_navigation) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3683 | DocumentState* document_state = |
| 3684 | DocumentState::FromDataSource(frame->dataSource()); |
| 3685 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3686 | InternalDocumentStateData* internal_data = |
| 3687 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3688 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3689 | if (document_state->commit_load_time().is_null()) |
| 3690 | document_state->set_commit_load_time(Time::Now()); |
| 3691 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3692 | if (internal_data->must_reset_scroll_and_scale_state()) { |
[email protected] | 06c7ba02 | 2012-12-17 19:24:12 | [diff] [blame] | 3693 | webview()->resetScrollAndScaleState(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3694 | internal_data->set_must_reset_scroll_and_scale_state(false); |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3695 | } |
[email protected] | 4b9c9e29 | 2013-07-18 19:13:28 | [diff] [blame] | 3696 | internal_data->set_use_error_page(false); |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3697 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3698 | if (is_new_navigation) { |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 3699 | // When we perform a new navigation, we need to update the last committed |
| 3700 | // session history entry with state for the page we are leaving. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3701 | UpdateSessionHistory(frame); |
| 3702 | |
| 3703 | // We bump our Page ID to correspond with the new session history entry. |
| 3704 | page_id_ = next_page_id_++; |
| 3705 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3706 | // Don't update history_page_ids_ (etc) for kSwappedOutURL, since |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 3707 | // 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] | 3708 | // never come back to kSwappedOutURL. Note that we have to call |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3709 | // UpdateSessionHistory and update page_id_ even in this case, so that |
| 3710 | // the current entry gets a state update and so that we don't send a |
| 3711 | // state update to the wrong entry when we swap back in. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3712 | if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3713 | // Advance our offset in session history, applying the length limit. |
| 3714 | // There is now no forward history. |
| 3715 | history_list_offset_++; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3716 | if (history_list_offset_ >= kMaxSessionHistoryEntries) |
| 3717 | history_list_offset_ = kMaxSessionHistoryEntries - 1; |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3718 | history_list_length_ = history_list_offset_ + 1; |
| 3719 | history_page_ids_.resize(history_list_length_, -1); |
| 3720 | history_page_ids_[history_list_offset_] = page_id_; |
| 3721 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3722 | } else { |
| 3723 | // Inspect the navigation_state on this frame to see if the navigation |
| 3724 | // corresponds to a session history navigation... Note: |frame| may or |
| 3725 | // may not be the toplevel frame, but for the case of capturing session |
| 3726 | // history, the first committed frame suffices. We keep track of whether |
| 3727 | // we've seen this commit before so that only capture session history once |
| 3728 | // per navigation. |
| 3729 | // |
| 3730 | // Note that we need to check if the page ID changed. In the case of a |
| 3731 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 3732 | // previous URL and the current page ID, which would be wrong. |
| 3733 | if (navigation_state->pending_page_id() != -1 && |
| 3734 | navigation_state->pending_page_id() != page_id_ && |
| 3735 | !navigation_state->request_committed()) { |
| 3736 | // This is a successful session history navigation! |
| 3737 | UpdateSessionHistory(frame); |
| 3738 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3739 | |
| 3740 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 3741 | |
| 3742 | // If the history list is valid, our list of page IDs should be correct. |
| 3743 | DCHECK(history_list_length_ <= 0 || |
| 3744 | history_list_offset_ < 0 || |
| 3745 | history_list_offset_ >= history_list_length_ || |
| 3746 | history_page_ids_[history_list_offset_] == page_id_); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3747 | } |
| 3748 | } |
| 3749 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3750 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3751 | DidCommitProvisionalLoad(frame, is_new_navigation)); |
| 3752 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3753 | // Remember that we've already processed this request, so we don't update |
| 3754 | // the session history again. We do this regardless of whether this is |
| 3755 | // a session history navigation, because if we attempted a session history |
| 3756 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3757 | // new navigation. |
| 3758 | navigation_state->set_request_committed(true); |
| 3759 | |
| 3760 | UpdateURL(frame); |
| 3761 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3762 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3763 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 3764 | |
| 3765 | if (!frame->parent()) { // Only for top frames. |
| 3766 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 3767 | if (render_thread_impl) { // Can be NULL in tests. |
| 3768 | render_thread_impl->histogram_customizer()-> |
| 3769 | RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(), |
| 3770 | g_view_map.Get().size()); |
| 3771 | } |
| 3772 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3773 | } |
| 3774 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3775 | void RenderViewImpl::didClearWindowObject(WebFrame* frame) { |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 3776 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3777 | DidClearWindowObject(frame)); |
| 3778 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3779 | if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 3780 | if (!dom_automation_controller_) |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3781 | dom_automation_controller_.reset(new DomAutomationController()); |
| 3782 | dom_automation_controller_->set_message_sender( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3783 | static_cast<RenderView*>(this)); |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3784 | dom_automation_controller_->set_routing_id(routing_id()); |
| 3785 | dom_automation_controller_->BindToJavascript(frame, |
| 3786 | "domAutomationController"); |
| 3787 | } |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 3788 | |
| 3789 | if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) { |
| 3790 | if (!stats_collection_controller_.get()) |
| 3791 | stats_collection_controller_.reset(new StatsCollectionController()); |
| 3792 | stats_collection_controller_->set_message_sender( |
| 3793 | static_cast<RenderView*>(this)); |
| 3794 | stats_collection_controller_->BindToJavascript(frame, |
| 3795 | "statsCollectionController"); |
| 3796 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3797 | } |
| 3798 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3799 | void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) { |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3800 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3801 | DidCreateDocumentElement(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3802 | } |
| 3803 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3804 | void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title, |
| 3805 | WebTextDirection direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 3806 | UpdateTitle(frame, title, direction); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3807 | |
| 3808 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3809 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3810 | } |
| 3811 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 3812 | void RenderViewImpl::didChangeIcon(WebFrame* frame, |
| 3813 | WebIconURL::Type icon_type) { |
| 3814 | if (frame->parent()) |
| 3815 | return; |
| 3816 | |
| 3817 | if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon) |
| 3818 | return; |
| 3819 | |
| 3820 | WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
| 3821 | std::vector<FaviconURL> urls; |
| 3822 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 3823 | urls.push_back(FaviconURL(icon_urls[i].iconURL(), |
| 3824 | ToFaviconType(icon_urls[i].iconType()))); |
| 3825 | } |
| 3826 | SendUpdateFaviconURL(urls); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3827 | } |
| 3828 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3829 | void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3830 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3831 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3832 | document_state->set_finish_document_load_time(Time::Now()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3833 | |
[email protected] | 622474d | 2010-11-04 09:21:08 | [diff] [blame] | 3834 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3835 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3836 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3837 | DidFinishDocumentLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3838 | |
| 3839 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3840 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3841 | } |
| 3842 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3843 | void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 3844 | if (webview()->mainFrame() == frame) { |
| 3845 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 3846 | page_id_)); |
| 3847 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3848 | } |
| 3849 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3850 | void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) { |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3851 | WebDataSource* ds = frame->dataSource(); |
| 3852 | DCHECK(ds); |
| 3853 | |
| 3854 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3855 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3856 | |
| 3857 | const WebURLRequest& failed_request = ds->request(); |
| 3858 | string16 error_description; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3859 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 3860 | frame, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3861 | failed_request, |
| 3862 | error, |
| 3863 | NULL, |
| 3864 | &error_description); |
| 3865 | Send(new ViewHostMsg_DidFailLoadWithError(routing_id_, |
| 3866 | frame->identifier(), |
| 3867 | failed_request.url(), |
| 3868 | !frame->parent(), |
| 3869 | error.reason, |
| 3870 | error_description)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3871 | } |
| 3872 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3873 | void RenderViewImpl::didFinishLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3874 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3875 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 1ac2ff1 | 2013-07-16 20:53:53 | [diff] [blame] | 3876 | if (document_state->finish_load_time().is_null()) { |
| 3877 | if (!frame->parent()) { |
| 3878 | TRACE_EVENT_INSTANT0("WebCore", "LoadFinished", |
| 3879 | TRACE_EVENT_SCOPE_PROCESS); |
| 3880 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3881 | document_state->set_finish_load_time(Time::Now()); |
[email protected] | 1ac2ff1 | 2013-07-16 20:53:53 | [diff] [blame] | 3882 | } |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3883 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3884 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); |
[email protected] | fdd94a0 | 2010-11-05 08:07:17 | [diff] [blame] | 3885 | |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3886 | Send(new ViewHostMsg_DidFinishLoad(routing_id_, |
| 3887 | frame->identifier(), |
| 3888 | ds->request().url(), |
| 3889 | !frame->parent())); |
[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::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3893 | WebFrame* frame, bool is_new_navigation) { |
| 3894 | // If this was a reference fragment navigation that we initiated, then we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3895 | // 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] | 3896 | // update the ExtraData on the datasource so that others who read the |
| 3897 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3898 | // initiate this navigation, then we need to take care to reset any pre- |
| 3899 | // existing navigation state to a content-initiated navigation state. |
| 3900 | // DidCreateDataSource conveniently takes care of this for us. |
| 3901 | didCreateDataSource(frame, frame->dataSource()); |
| 3902 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3903 | DocumentState* document_state = |
| 3904 | DocumentState::FromDataSource(frame->dataSource()); |
| 3905 | NavigationState* new_state = document_state->navigation_state(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3906 | new_state->set_was_within_same_page(true); |
| 3907 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3908 | didCommitProvisionalLoad(frame, is_new_navigation); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3909 | } |
| 3910 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3911 | void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3912 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3913 | } |
| 3914 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3915 | void RenderViewImpl::willSendRequest(WebFrame* frame, |
| 3916 | unsigned identifier, |
| 3917 | WebURLRequest& request, |
| 3918 | const WebURLResponse& redirect_response) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3919 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3920 | } |
| 3921 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3922 | void RenderViewImpl::didReceiveResponse( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3923 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3924 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3925 | } |
| 3926 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3927 | void RenderViewImpl::didFinishResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3928 | WebFrame* frame, unsigned identifier) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3929 | InternalDocumentStateData* internal_data = |
| 3930 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 3931 | if (!internal_data->use_error_page()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3932 | return; |
| 3933 | |
[email protected] | 7bfc153f | 2011-09-23 22:00:20 | [diff] [blame] | 3934 | // Do not show error page when DevTools is attached. |
| 3935 | if (devtools_agent_->IsAttached()) |
| 3936 | return; |
| 3937 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3938 | // Display error page, if appropriate. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3939 | int http_status_code = internal_data->http_status_code(); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3940 | if (http_status_code == 404) { |
| 3941 | // On 404s, try a remote search page as a fallback. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3942 | const GURL& document_url = frame->document().url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3943 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3944 | const GURL& error_page_url = |
| 3945 | GetAlternateErrorPageURL(document_url, HTTP_404); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3946 | if (error_page_url.is_valid()) { |
| 3947 | WebURLError original_error; |
[email protected] | 2e9706c | 2011-06-09 16:49:47 | [diff] [blame] | 3948 | original_error.domain = "http"; |
| 3949 | original_error.reason = 404; |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3950 | original_error.unreachableURL = document_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3951 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3952 | internal_data->set_alt_error_page_fetcher( |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3953 | new AltErrorPageResourceFetcher( |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 3954 | error_page_url, frame, frame->dataSource()->request(), |
| 3955 | original_error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 3956 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 3957 | base::Unretained(this)))); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3958 | return; |
| 3959 | } |
| 3960 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3961 | |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 3962 | std::string error_domain; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3963 | if (GetContentClient()->renderer()->HasErrorPage( |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 3964 | http_status_code, &error_domain)) { |
| 3965 | WebURLError error; |
| 3966 | error.unreachableURL = frame->document().url(); |
| 3967 | error.domain = WebString::fromUTF8(error_domain); |
| 3968 | error.reason = http_status_code; |
| 3969 | |
| 3970 | LoadNavigationErrorPage( |
| 3971 | frame, frame->dataSource()->request(), error, std::string(), true); |
| 3972 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3973 | } |
| 3974 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3975 | void RenderViewImpl::didLoadResourceFromMemoryCache( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3976 | WebFrame* frame, const WebURLRequest& request, |
| 3977 | const WebURLResponse& response) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3978 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3979 | } |
| 3980 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3981 | void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3982 | NOTREACHED(); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3983 | } |
| 3984 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3985 | void RenderViewImpl::didRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 3986 | WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3987 | NOTREACHED(); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3988 | } |
| 3989 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3990 | void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3991 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3992 | } |
| 3993 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3994 | void RenderViewImpl::didCreateScriptContext(WebFrame* frame, |
| 3995 | v8::Handle<v8::Context> context, |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 3996 | int extension_group, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3997 | int world_id) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3998 | NOTREACHED(); |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 3999 | } |
| 4000 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4001 | void RenderViewImpl::willReleaseScriptContext(WebFrame* frame, |
| 4002 | v8::Handle<v8::Context> context, |
| 4003 | int world_id) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4004 | NOTREACHED(); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 4005 | } |
| 4006 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4007 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 4008 | // We don't always want to send the change messages over IPC, only if we've |
| 4009 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 4010 | // message. |
| 4011 | if (!send_preferred_size_changes_ || !webview()) |
| 4012 | return; |
| 4013 | |
[email protected] | e76b797 | 2013-06-06 02:58:48 | [diff] [blame] | 4014 | gfx::Size size = webview()->contentsPreferredMinimumSize(); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 4015 | |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 4016 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 4017 | // so we need to adjust. |
| 4018 | double zoom_factor = ZoomLevelToZoomFactor(webview()->zoomLevel()); |
| 4019 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 4020 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 4021 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 4022 | if (size == preferred_size_) |
| 4023 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 4024 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 4025 | preferred_size_ = size; |
| 4026 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 4027 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4028 | } |
| 4029 | |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 4030 | BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 4031 | if (!browser_plugin_manager_.get()) |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 4032 | browser_plugin_manager_ = BrowserPluginManager::Create(this); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 4033 | return browser_plugin_manager_.get(); |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 4034 | } |
| 4035 | |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 4036 | bool RenderViewImpl::InitializeMediaStreamClient() { |
| 4037 | if (media_stream_client_) |
| 4038 | return true; |
| 4039 | |
[email protected] | 7082fb94 | 2012-05-16 23:44:59 | [diff] [blame] | 4040 | if (!RenderThreadImpl::current()) // Will be NULL during unit tests. |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 4041 | return false; |
[email protected] | 0838156 | 2012-05-15 20:55:40 | [diff] [blame] | 4042 | |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 4043 | #if defined(OS_ANDROID) |
[email protected] | ce585bf | 2013-03-14 16:25:16 | [diff] [blame] | 4044 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC)) |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 4045 | return false; |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 4046 | #endif |
| 4047 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 4048 | #if defined(ENABLE_WEBRTC) |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4049 | if (!media_stream_dispatcher_) |
| 4050 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 4051 | |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 4052 | MediaStreamImpl* media_stream_impl = new MediaStreamImpl( |
| 4053 | this, |
| 4054 | media_stream_dispatcher_, |
| 4055 | RenderThreadImpl::current()->GetMediaStreamDependencyFactory()); |
| 4056 | media_stream_client_ = media_stream_impl; |
| 4057 | web_user_media_client_ = media_stream_impl; |
| 4058 | return true; |
| 4059 | #else |
| 4060 | return false; |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 4061 | #endif |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4062 | } |
| 4063 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4064 | void RenderViewImpl::didChangeContentsSize(WebFrame* frame, |
| 4065 | const WebSize& size) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4066 | if (webview()->mainFrame() != frame) |
| 4067 | return; |
| 4068 | WebView* frameView = frame->view(); |
| 4069 | if (!frameView) |
| 4070 | return; |
| 4071 | |
| 4072 | bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); |
| 4073 | bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); |
| 4074 | |
| 4075 | if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || |
| 4076 | has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { |
| 4077 | Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( |
| 4078 | routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); |
| 4079 | |
| 4080 | cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; |
| 4081 | cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; |
| 4082 | } |
| 4083 | } |
| 4084 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4085 | void RenderViewImpl::UpdateScrollState(WebFrame* frame) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4086 | WebSize offset = frame->scrollOffset(); |
| 4087 | WebSize minimum_offset = frame->minimumScrollOffset(); |
| 4088 | WebSize maximum_offset = frame->maximumScrollOffset(); |
| 4089 | |
| 4090 | bool is_pinned_to_left = offset.width <= minimum_offset.width; |
| 4091 | bool is_pinned_to_right = offset.width >= maximum_offset.width; |
| 4092 | |
| 4093 | if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || |
| 4094 | is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { |
| 4095 | Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( |
| 4096 | routing_id_, is_pinned_to_left, is_pinned_to_right)); |
| 4097 | |
| 4098 | cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; |
| 4099 | cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; |
| 4100 | } |
[email protected] | 4e72174 | 2013-02-04 21:39:30 | [diff] [blame] | 4101 | |
| 4102 | Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4103 | } |
| 4104 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4105 | void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) { |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 4106 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4107 | |
| 4108 | if (webview()->mainFrame() == frame) |
| 4109 | UpdateScrollState(frame); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 4110 | |
| 4111 | FOR_EACH_OBSERVER( |
| 4112 | RenderViewObserver, observers_, DidChangeScrollOffset(frame)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4113 | } |
| 4114 | |
[email protected] | a9344092d | 2013-02-27 00:56:45 | [diff] [blame] | 4115 | void RenderViewImpl::willInsertBody(WebKit::WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4116 | NOTREACHED(); |
[email protected] | a9344092d | 2013-02-27 00:56:45 | [diff] [blame] | 4117 | } |
| 4118 | |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4119 | void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) { |
| 4120 | if (frame != webview()->mainFrame()) |
| 4121 | return; |
| 4122 | |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 4123 | InternalDocumentStateData* data = |
| 4124 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 4125 | data->set_did_first_visually_non_empty_layout(true); |
| 4126 | |
| 4127 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4128 | // Update body background color if necessary. |
| 4129 | SkColor bg_color = webwidget_->backgroundColor(); |
| 4130 | |
| 4131 | // If not initialized, default to white. Note that 0 is different from black |
| 4132 | // as black still has alpha 0xFF. |
| 4133 | if (!bg_color) |
| 4134 | bg_color = SK_ColorWHITE; |
| 4135 | |
| 4136 | if (bg_color != body_background_color_) { |
| 4137 | body_background_color_ = bg_color; |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4138 | Send(new ViewHostMsg_DidChangeBodyBackgroundColor( |
| 4139 | GetRoutingID(), bg_color)); |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4140 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4141 | #endif |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 4142 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4143 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4144 | void RenderViewImpl::SendFindReply(int request_id, |
| 4145 | int match_count, |
| 4146 | int ordinal, |
| 4147 | const WebRect& selection_rect, |
| 4148 | bool final_status_update) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4149 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 4150 | request_id, |
| 4151 | match_count, |
| 4152 | selection_rect, |
| 4153 | ordinal, |
| 4154 | final_status_update)); |
| 4155 | } |
| 4156 | |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 4157 | // static |
| 4158 | bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams( |
| 4159 | const string16& selection_text, |
| 4160 | size_t selection_text_offset, |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 4161 | const gfx::Range& selection_range, |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 4162 | const ContextMenuParams& params) { |
| 4163 | string16 trimmed_selection_text; |
| 4164 | if (!selection_text.empty() && !selection_range.is_empty()) { |
| 4165 | const int start = selection_range.GetMin() - selection_text_offset; |
| 4166 | const size_t length = selection_range.length(); |
| 4167 | if (start >= 0 && start + length <= selection_text.length()) { |
| 4168 | TrimWhitespace(selection_text.substr(start, length), TRIM_ALL, |
| 4169 | &trimmed_selection_text); |
| 4170 | } |
| 4171 | } |
| 4172 | string16 trimmed_params_text; |
| 4173 | TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text); |
| 4174 | return trimmed_params_text != trimmed_selection_text; |
| 4175 | } |
| 4176 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4177 | void RenderViewImpl::reportFindInPageMatchCount(int request_id, |
| 4178 | int count, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4179 | bool final_update) { |
[email protected] | 1f35b45e | 2013-08-29 17:36:46 | [diff] [blame] | 4180 | // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame |
| 4181 | main_render_frame_->reportFindInPageMatchCount( |
| 4182 | request_id, count, final_update); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 4183 | } |
| 4184 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4185 | void RenderViewImpl::reportFindInPageSelection(int request_id, |
| 4186 | int active_match_ordinal, |
| 4187 | const WebRect& selection_rect) { |
[email protected] | 1f35b45e | 2013-08-29 17:36:46 | [diff] [blame] | 4188 | // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame |
| 4189 | main_render_frame_->reportFindInPageSelection( |
| 4190 | request_id, active_match_ordinal, selection_rect); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [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] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4353 | #if defined(ENABLE_PLUGINS) |
| 4354 | bool pepper_plugin_was_registered = false; |
| 4355 | scoped_refptr<PluginModule> pepper_module(PluginModule::Create( |
| 4356 | this, info, &pepper_plugin_was_registered)); |
| 4357 | if (pepper_plugin_was_registered) { |
| 4358 | if (pepper_module.get()) |
| 4359 | return new PepperWebPluginImpl(pepper_module.get(), params, AsWeakPtr()); |
| 4360 | } |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4361 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 4362 | return new WebPluginImpl(frame, params, info.path, AsWeakPtr()); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4363 | #else |
| 4364 | return NULL; |
| 4365 | #endif |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4366 | } |
| 4367 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4368 | void RenderViewImpl::EvaluateScript(const string16& frame_xpath, |
| 4369 | const string16& jscript, |
| 4370 | int id, |
| 4371 | bool notify_result) { |
[email protected] | e1907b43 | 2013-09-04 16:11:14 | [diff] [blame] | 4372 | v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4373 | v8::Handle<v8::Value> result; |
| 4374 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4375 | if (web_frame) |
| 4376 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); |
| 4377 | if (notify_result) { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4378 | base::ListValue list; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4379 | if (!result.IsEmpty() && web_frame) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4380 | v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 4381 | v8::Context::Scope context_scope(context); |
| 4382 | V8ValueConverterImpl converter; |
[email protected] | 3de391e8 | 2012-05-16 17:50:51 | [diff] [blame] | 4383 | converter.SetDateAllowed(true); |
[email protected] | e0658bc | 2012-09-17 04:05:24 | [diff] [blame] | 4384 | converter.SetRegExpAllowed(true); |
| 4385 | base::Value* result_value = converter.FromV8Value(result, context); |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4386 | list.Set(0, result_value ? result_value : base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4387 | } else { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4388 | list.Set(0, base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4389 | } |
| 4390 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
| 4391 | } |
| 4392 | } |
| 4393 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4394 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4395 | return (!send_preferred_size_changes_ || |
| 4396 | (disable_scrollbars_size_limit_.width() <= width || |
| 4397 | disable_scrollbars_size_limit_.height() <= height)); |
| 4398 | } |
| 4399 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4400 | int RenderViewImpl::GetEnabledBindings() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4401 | return enabled_bindings_; |
| 4402 | } |
| 4403 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4404 | bool RenderViewImpl::GetContentStateImmediately() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4405 | return send_content_state_immediately_; |
| 4406 | } |
| 4407 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4408 | float RenderViewImpl::GetFilteredTimePerFrame() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4409 | return filtered_time_per_frame(); |
| 4410 | } |
| 4411 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4412 | int RenderViewImpl::ShowContextMenu(ContextMenuClient* client, |
| 4413 | const ContextMenuParams& params) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4414 | DCHECK(client); // A null client means "internal" when we issue callbacks. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4415 | ContextMenuParams our_params(params); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4416 | our_params.custom_context.request_id = pending_context_menus_.Add(client); |
| 4417 | Send(new ViewHostMsg_ContextMenu(routing_id_, our_params)); |
| 4418 | return our_params.custom_context.request_id; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4419 | } |
| 4420 | |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 4421 | void RenderViewImpl::CancelContextMenu(int request_id) { |
| 4422 | DCHECK(pending_context_menus_.Lookup(request_id)); |
| 4423 | pending_context_menus_.Remove(request_id); |
| 4424 | } |
| 4425 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4426 | WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4427 | return visibilityState(); |
| 4428 | } |
| 4429 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4430 | void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame, |
| 4431 | const WebKit::WebString& message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4432 | return runModalAlertDialog(frame, message); |
| 4433 | } |
| 4434 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4435 | void RenderViewImpl::LoadURLExternally( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4436 | WebKit::WebFrame* frame, |
| 4437 | const WebKit::WebURLRequest& request, |
| 4438 | WebKit::WebNavigationPolicy policy) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4439 | main_render_frame_->loadURLExternally(frame, request, policy); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4440 | } |
| 4441 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4442 | void RenderViewImpl::DidStartLoading() { |
| 4443 | didStartLoading(); |
| 4444 | } |
| 4445 | |
| 4446 | void RenderViewImpl::DidStopLoading() { |
| 4447 | didStopLoading(); |
| 4448 | } |
| 4449 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4450 | void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4451 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4452 | reinterpret_cast<int64>(player), |
| 4453 | player->hasVideo(), |
| 4454 | player->hasAudio(), |
| 4455 | true)); |
| 4456 | } |
| 4457 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4458 | void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4459 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4460 | reinterpret_cast<int64>(player), |
| 4461 | player->hasVideo(), |
| 4462 | player->hasAudio(), |
| 4463 | false)); |
| 4464 | } |
| 4465 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4466 | void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4467 | DidPause(player); |
| 4468 | } |
| 4469 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4470 | void RenderViewImpl::SyncNavigationState() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4471 | if (!webview()) |
| 4472 | return; |
| 4473 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4474 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 4475 | SendUpdateState(item); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4476 | } |
| 4477 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4478 | void RenderViewImpl::SyncSelectionIfRequired() { |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4479 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4480 | if (!frame) |
| 4481 | return; |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4482 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4483 | string16 text; |
| 4484 | size_t offset; |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 4485 | gfx::Range range; |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4486 | #if defined(ENABLE_PLUGINS) |
| 4487 | if (focused_pepper_plugin_) { |
| 4488 | focused_pepper_plugin_->GetSurroundingText(&text, &range); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4489 | offset = 0; // Pepper API does not support offset reporting. |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4490 | // TODO(kinaba): cut as needed. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4491 | } else |
| 4492 | #endif |
| 4493 | { |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4494 | size_t location, length; |
| 4495 | if (!webview()->caretOrSelectionRange(&location, &length)) |
| 4496 | return; |
| 4497 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 4498 | range = gfx::Range(location, location + length); |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4499 | |
[email protected] | 6123214 | 2013-06-20 16:43:32 | [diff] [blame] | 4500 | if (webview()->textInputInfo().type != WebKit::WebTextInputTypeNone) { |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4501 | // If current focused element is editable, we will send 100 more chars |
| 4502 | // before and after selection. It is for input method surrounding text |
| 4503 | // feature. |
| 4504 | if (location > kExtraCharsBeforeAndAfterSelection) |
| 4505 | offset = location - kExtraCharsBeforeAndAfterSelection; |
| 4506 | else |
| 4507 | offset = 0; |
| 4508 | length = location + length - offset + kExtraCharsBeforeAndAfterSelection; |
| 4509 | WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); |
| 4510 | if (!webrange.isNull()) |
| 4511 | text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); |
| 4512 | } else { |
| 4513 | offset = location; |
| 4514 | text = frame->selectionAsText(); |
| 4515 | // http://crbug.com/101435 |
| 4516 | // In some case, frame->selectionAsText() returned text's length is not |
| 4517 | // equal to the length returned from webview()->caretOrSelectionRange(). |
| 4518 | // So we have to set the range according to text.length(). |
| 4519 | range.set_end(range.start() + text.length()); |
| 4520 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4521 | } |
| 4522 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4523 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 4524 | // the selection hasn't actually changed. We don't want to report these |
| 4525 | // because it will cause us to continually claim the X clipboard. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4526 | if (selection_text_offset_ != offset || |
| 4527 | selection_range_ != range || |
| 4528 | selection_text_ != text) { |
| 4529 | selection_text_ = text; |
| 4530 | selection_text_offset_ = offset; |
| 4531 | selection_range_ = range; |
| 4532 | Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range)); |
| 4533 | } |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 4534 | UpdateSelectionBounds(); |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4535 | } |
| 4536 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4537 | GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, |
| 4538 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4539 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4540 | // If the URL that failed was secure, then the embedding web page was not |
| 4541 | // expecting a network attacker to be able to manipulate its contents. As |
| 4542 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 4543 | // attacker to manipulate the contents of the response if we tried to use |
| 4544 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4545 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | // Grab the base URL from the browser process. |
| 4549 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4550 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4551 | |
| 4552 | // Strip query params from the failed URL. |
| 4553 | GURL::Replacements remove_params; |
| 4554 | remove_params.ClearUsername(); |
| 4555 | remove_params.ClearPassword(); |
| 4556 | remove_params.ClearQuery(); |
| 4557 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4558 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 4559 | std::string spec_to_send = url_to_send.spec(); |
| 4560 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 4561 | if (failed_url.has_query()) |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4562 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4563 | |
| 4564 | // Construct the query params to send to link doctor. |
| 4565 | std::string params(alternate_error_page_url_.query()); |
| 4566 | params.append("&url="); |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 4567 | params.append(net::EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4568 | params.append("&sourceid=chrome"); |
| 4569 | params.append("&error="); |
| 4570 | switch (error_type) { |
| 4571 | case DNS_ERROR: |
| 4572 | params.append("dnserror"); |
| 4573 | break; |
| 4574 | |
| 4575 | case HTTP_404: |
| 4576 | params.append("http404"); |
| 4577 | break; |
| 4578 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4579 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 4580 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4581 | break; |
| 4582 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4583 | default: |
| 4584 | NOTREACHED() << "unknown ErrorPageType"; |
| 4585 | } |
| 4586 | |
| 4587 | // OK, build the final url to return. |
| 4588 | GURL::Replacements link_doctor_params; |
| 4589 | link_doctor_params.SetQueryStr(params); |
| 4590 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 4591 | return url; |
| 4592 | } |
| 4593 | |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 4594 | GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const { |
| 4595 | WebDataSource* ds = frame->dataSource(); |
| 4596 | if (ds->hasUnreachableURL()) |
| 4597 | return ds->unreachableURL(); |
| 4598 | |
| 4599 | const WebURLRequest& request = ds->request(); |
| 4600 | return request.url(); |
| 4601 | } |
| 4602 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4603 | WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4604 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4605 | } |
| 4606 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4607 | void RenderViewImpl::OnFind(int request_id, |
| 4608 | const string16& search_text, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4609 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4610 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4611 | |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4612 | // Check if the plugin still exists in the document. |
| 4613 | if (main_frame->document().isPluginDocument() && |
| 4614 | GetWebPluginFromPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4615 | if (options.findNext) { |
| 4616 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4617 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4618 | } else { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4619 | if (!GetWebPluginFromPluginDocument()->startFind( |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 4620 | search_text, options.matchCase, request_id)) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 4621 | // Send "no results". |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4622 | SendFindReply(request_id, 0, 0, gfx::Rect(), true); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4623 | } |
| 4624 | } |
| 4625 | return; |
| 4626 | } |
| 4627 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4628 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4629 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4630 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 4631 | |
| 4632 | bool multi_frame = (frame_after_main != main_frame); |
| 4633 | |
| 4634 | // If we have multiple frames, we don't want to wrap the search within the |
| 4635 | // frame, so we check here if we only have main_frame in the chain. |
| 4636 | bool wrap_within_frame = !multi_frame; |
| 4637 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 4638 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4639 | bool result = false; |
| 4640 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4641 | // If something is selected when we start searching it means we cannot just |
| 4642 | // increment the current match ordinal; we need to re-generate it. |
| 4643 | WebRange current_selection = focused_frame->selectionRange(); |
| 4644 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4645 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4646 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4647 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4648 | |
| 4649 | if (!result) { |
| 4650 | // don't leave text selected as you move to the next frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4651 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
| 4652 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4653 | |
| 4654 | // Find the next frame, but skip the invisible ones. |
| 4655 | do { |
| 4656 | // What is the next frame to search? (we might be going backwards). Note |
| 4657 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4658 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4659 | search_frame->traverseNext(true) : |
| 4660 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4661 | } while (!search_frame->hasVisibleContent() && |
| 4662 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4663 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 4664 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4665 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
| 4666 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4667 | |
| 4668 | // If we have multiple frames and we have wrapped back around to the |
| 4669 | // focused frame, we need to search it once more allowing wrap within |
| 4670 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 4671 | // reported matches, but no frames after the focused_frame contain a |
| 4672 | // match for the search word(s). |
| 4673 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4674 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4675 | request_id, search_text, options, true, // Force wrapping. |
| 4676 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4677 | } |
| 4678 | } |
| 4679 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4680 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4681 | } while (!result && search_frame != focused_frame); |
| 4682 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4683 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4684 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4685 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4686 | } else { |
| 4687 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 4688 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 4689 | // yet what is active. |
| 4690 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 4691 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4692 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4693 | // If we find no matches then this will be our last status update. |
| 4694 | // Otherwise the scoping effort will send more results. |
| 4695 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4696 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4697 | SendFindReply(request_id, match_count, ordinal, selection_rect, |
| 4698 | final_status_update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4699 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4700 | // Scoping effort begins, starting with the mainframe. |
| 4701 | search_frame = main_frame; |
| 4702 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4703 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4704 | |
| 4705 | do { |
| 4706 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4707 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4708 | |
| 4709 | // We don't start another scoping effort unless at least one match has |
| 4710 | // been found. |
| 4711 | if (result) { |
| 4712 | // Start new scoping request. If the scoping function determines that it |
| 4713 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4714 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4715 | search_text, |
| 4716 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4717 | true); // reset the tickmarks |
| 4718 | } |
| 4719 | |
| 4720 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 4721 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4722 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4723 | } while (search_frame != main_frame); |
| 4724 | } |
| 4725 | } |
| 4726 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4727 | void RenderViewImpl::OnStopFinding(StopFindAction action) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4728 | WebView* view = webview(); |
| 4729 | if (!view) |
| 4730 | return; |
| 4731 | |
| 4732 | WebDocument doc = view->mainFrame()->document(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4733 | if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4734 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4735 | return; |
| 4736 | } |
| 4737 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4738 | bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4739 | if (clear_selection) { |
| 4740 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
| 4741 | GetFocusedNode()); |
| 4742 | } |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4743 | |
| 4744 | WebFrame* frame = view->mainFrame(); |
| 4745 | while (frame) { |
| 4746 | frame->stopFinding(clear_selection); |
| 4747 | frame = frame->traverseNext(false); |
| 4748 | } |
| 4749 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4750 | if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4751 | WebFrame* focused_frame = view->focusedFrame(); |
| 4752 | if (focused_frame) { |
| 4753 | WebDocument doc = focused_frame->document(); |
| 4754 | if (!doc.isNull()) { |
| 4755 | WebNode node = doc.focusedNode(); |
| 4756 | if (!node.isNull()) |
| 4757 | node.simulateClick(); |
| 4758 | } |
| 4759 | } |
| 4760 | } |
| 4761 | } |
| 4762 | |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4763 | #if defined(OS_ANDROID) |
| 4764 | void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| 4765 | float x, float y) { |
| 4766 | if (!webview()) |
| 4767 | return; |
| 4768 | |
| 4769 | WebFrame* main_frame = webview()->mainFrame(); |
| 4770 | WebRect selection_rect; |
| 4771 | int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), |
| 4772 | &selection_rect); |
| 4773 | if (ordinal == -1) { |
| 4774 | // Something went wrong, so send a no-op reply (force the main_frame to |
| 4775 | // report the current match count) in case the host is waiting for a |
| 4776 | // response due to rate-limiting). |
| 4777 | main_frame->increaseMatchCount(0, request_id); |
| 4778 | return; |
| 4779 | } |
| 4780 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4781 | SendFindReply(request_id, |
| 4782 | -1 /* number_of_matches */, |
| 4783 | ordinal, |
| 4784 | selection_rect, |
| 4785 | true /* final_update */); |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | void RenderViewImpl::OnFindMatchRects(int current_version) { |
| 4789 | if (!webview()) |
| 4790 | return; |
| 4791 | |
| 4792 | WebFrame* main_frame = webview()->mainFrame(); |
| 4793 | std::vector<gfx::RectF> match_rects; |
| 4794 | |
| 4795 | int rects_version = main_frame->findMatchMarkersVersion(); |
| 4796 | if (current_version != rects_version) { |
| 4797 | WebVector<WebFloatRect> web_match_rects; |
| 4798 | main_frame->findMatchRects(web_match_rects); |
| 4799 | match_rects.reserve(web_match_rects.size()); |
| 4800 | for (size_t i = 0; i < web_match_rects.size(); ++i) |
| 4801 | match_rects.push_back(gfx::RectF(web_match_rects[i])); |
| 4802 | } |
| 4803 | |
| 4804 | gfx::RectF active_rect = main_frame->activeFindMatchRect(); |
| 4805 | Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_, |
| 4806 | rects_version, |
| 4807 | match_rects, |
| 4808 | active_rect)); |
| 4809 | } |
| 4810 | #endif |
| 4811 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4812 | void RenderViewImpl::OnZoom(PageZoom zoom) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4813 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4814 | return; |
| 4815 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 4816 | webview()->hidePopups(); |
[email protected] | 854ab546 | 2011-11-22 20:48:10 | [diff] [blame] | 4817 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4818 | double old_zoom_level = webview()->zoomLevel(); |
| 4819 | double zoom_level; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4820 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4821 | zoom_level = 0; |
| 4822 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 4823 | // Previous zoom level is a whole number, so just increment/decrement. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4824 | zoom_level = old_zoom_level + zoom; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4825 | } else { |
| 4826 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 4827 | // not a whole number, or a plugin changed it to a custom value. We want |
| 4828 | // to go to the next whole number so that the user can always get back to |
| 4829 | // 100% with the keyboard/menu. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4830 | if ((old_zoom_level > 1 && zoom > 0) || |
| 4831 | (old_zoom_level < 1 && zoom < 0)) { |
| 4832 | zoom_level = static_cast<int>(old_zoom_level + zoom); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4833 | } else { |
| 4834 | // We're going towards 100%, so first go to the next whole number. |
| 4835 | zoom_level = static_cast<int>(old_zoom_level); |
| 4836 | } |
| 4837 | } |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 4838 | webview()->setZoomLevel(zoom_level); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4839 | zoomLevelChanged(); |
| 4840 | } |
| 4841 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4842 | void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x, |
| 4843 | int zoom_center_y) { |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4844 | ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y, |
| 4845 | kScalingIncrementForGesture); |
| 4846 | } |
| 4847 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4848 | void RenderViewImpl::ZoomFactorHelper(PageZoom zoom, |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4849 | int zoom_center_x, |
| 4850 | int zoom_center_y, |
| 4851 | float scaling_increment) { |
| 4852 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4853 | return; |
| 4854 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 4855 | double old_page_scale_factor = webview()->pageScaleFactor(); |
| 4856 | double page_scale_factor; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4857 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 4858 | page_scale_factor = 1.0; |
| 4859 | } else { |
| 4860 | page_scale_factor = old_page_scale_factor + |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4861 | (zoom > 0 ? scaling_increment : -scaling_increment); |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 4862 | } |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4863 | if (page_scale_factor > 0) { |
[email protected] | 8519136 | 2011-11-08 18:53:09 | [diff] [blame] | 4864 | webview()->setPageScaleFactor(page_scale_factor, |
| 4865 | WebPoint(zoom_center_x, zoom_center_y)); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4866 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4867 | } |
| 4868 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4869 | void RenderViewImpl::OnSetZoomLevel(double zoom_level) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 4870 | webview()->hidePopups(); |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 4871 | webview()->setZoomLevel(zoom_level); |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 4872 | zoomLevelChanged(); |
| 4873 | } |
| 4874 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4875 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 4876 | double zoom_level) { |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 4877 | #if !defined(OS_ANDROID) |
| 4878 | // On Android, page zoom isn't used, and in case of WebView, text zoom is used |
| 4879 | // for legacy WebView text scaling emulation. Thus, the code that resets |
| 4880 | // the zoom level from this map will be effectively resetting text zoom level. |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4881 | host_zoom_levels_[url] = zoom_level; |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 4882 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4883 | } |
| 4884 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4885 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4886 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4887 | } |
| 4888 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4889 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4890 | WebString no_encoding; |
| 4891 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4892 | } |
| 4893 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4894 | WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4895 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4896 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4897 | |
| 4898 | // xpath string can represent a frame deep down the tree (across multiple |
| 4899 | // frame DOMs). |
| 4900 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 4901 | // should break into 2 xpaths |
| 4902 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4903 | std::vector<string16> xpaths; |
| 4904 | base::SplitString(xpath, '\n', &xpaths); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4905 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4906 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4907 | for (std::vector<string16>::const_iterator i = xpaths.begin(); |
| 4908 | frame && i != xpaths.end(); ++i) { |
| 4909 | frame = frame->findChildByExpression(*i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4910 | } |
| 4911 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4912 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4913 | } |
| 4914 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4915 | void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, |
| 4916 | const string16& jscript, |
| 4917 | int id, |
| 4918 | bool notify_result) { |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 4919 | TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest", |
| 4920 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4921 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4922 | } |
| 4923 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4924 | void RenderViewImpl::OnPostMessageEvent( |
| 4925 | const ViewMsg_PostMessage_Params& params) { |
[email protected] | bf4a231 | 2013-04-23 00:32:11 | [diff] [blame] | 4926 | // TODO(nasko): Support sending to subframes. |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 4927 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4928 | |
| 4929 | // Find the source frame if it exists. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4930 | WebFrame* source_frame = NULL; |
| 4931 | if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 4932 | RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
| 4933 | if (source_view) |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 4934 | source_frame = source_view->webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4935 | } |
| 4936 | |
| 4937 | // Create an event with the message. The final parameter to initMessageEvent |
| 4938 | // is the last event ID, which is not used with postMessage. |
| 4939 | WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
| 4940 | WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 4941 | msg_event.initMessageEvent("message", |
| 4942 | // |canBubble| and |cancellable| are always false |
| 4943 | false, false, |
| 4944 | WebSerializedScriptValue::fromString(params.data), |
| 4945 | params.source_origin, source_frame, ""); |
| 4946 | |
| 4947 | // We must pass in the target_origin to do the security check on this side, |
| 4948 | // since it may have changed since the original postMessage call was made. |
| 4949 | WebSecurityOrigin target_origin; |
| 4950 | if (!params.target_origin.empty()) { |
| 4951 | target_origin = |
| 4952 | WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 4953 | } |
| 4954 | frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 4955 | } |
| 4956 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4957 | void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath, |
| 4958 | const std::string& css) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4959 | WebFrame* frame = GetChildFrame(frame_xpath); |
| 4960 | if (!frame) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 4961 | return; |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 4962 | |
[email protected] | 01cf589c | 2011-07-28 18:04:03 | [diff] [blame] | 4963 | frame->document().insertUserStyleSheet( |
| 4964 | WebString::fromUTF8(css), |
| 4965 | WebDocument::UserStyleAuthorLevel); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4966 | } |
| 4967 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4968 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 4969 | if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && |
| 4970 | !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { |
[email protected] | 91f0576 | 2013-08-21 02:55:09 | [diff] [blame] | 4971 | // WebUI uses <dialog> which is not yet enabled by default in Chrome. |
| 4972 | WebRuntimeFeatures::enableDialogElement(true); |
| 4973 | |
[email protected] | dcc72db | 2013-01-02 00:44:18 | [diff] [blame] | 4974 | RenderThread::Get()->RegisterExtension(WebUIExtension::Get()); |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 4975 | new WebUIExtensionData(this); |
| 4976 | } |
| 4977 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4978 | enabled_bindings_ |= enabled_bindings_flags; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 4979 | |
| 4980 | // Keep track of the total bindings accumulated in this process. |
| 4981 | RenderProcess::current()->AddBindings(enabled_bindings_flags); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4982 | } |
| 4983 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 4984 | void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4985 | const gfx::Point& client_point, |
| 4986 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4987 | WebDragOperationsMask ops, |
| 4988 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4989 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 4990 | DropDataToWebDragData(drop_data), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4991 | client_point, |
| 4992 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4993 | ops, |
| 4994 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4995 | |
| 4996 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 4997 | } |
| 4998 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4999 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 5000 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5001 | WebDragOperationsMask ops, |
| 5002 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5003 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 5004 | client_point, |
| 5005 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5006 | ops, |
| 5007 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5008 | |
| 5009 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 5010 | } |
| 5011 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5012 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5013 | webview()->dragTargetDragLeave(); |
| 5014 | } |
| 5015 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5016 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5017 | const gfx::Point& screen_point, |
| 5018 | int key_modifiers) { |
| 5019 | webview()->dragTargetDrop(client_point, screen_point, key_modifiers); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 5020 | |
| 5021 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5022 | } |
| 5023 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5024 | void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 5025 | const gfx::Point& screen_point, |
| 5026 | bool ended, |
| 5027 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5028 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5029 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 5030 | } else { |
| 5031 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5032 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5033 | } |
| 5034 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5035 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5036 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5037 | } |
| 5038 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5039 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 5040 | webkit_preferences_ = prefs; |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 5041 | ApplyWebPreferences(webkit_preferences_, webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5042 | } |
| 5043 | |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 5044 | void RenderViewImpl::OnUpdateTimezone() { |
| 5045 | if (webview()) |
| 5046 | NotifyTimezoneChange(webview()->mainFrame()); |
| 5047 | } |
| 5048 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5049 | void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5050 | alternate_error_page_url_ = url; |
| 5051 | } |
| 5052 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5053 | void RenderViewImpl::OnCustomContextMenuAction( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5054 | const CustomContextMenuContext& custom_context, |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5055 | unsigned action) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5056 | if (custom_context.request_id) { |
| 5057 | // External context menu request, look in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5058 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5059 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 5060 | if (client) |
| 5061 | client->OnMenuAction(custom_context.request_id, action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5062 | } else { |
| 5063 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5064 | webview()->performCustomContextMenuAction(action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5065 | } |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 5066 | } |
| 5067 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5068 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5069 | int id, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 5070 | const std::vector<base::FilePath>& paths) { |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5071 | if (!enumeration_completions_[id]) |
| 5072 | return; |
| 5073 | |
| 5074 | WebVector<WebString> ws_file_names(paths.size()); |
| 5075 | for (size_t i = 0; i < paths.size(); ++i) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5076 | ws_file_names[i] = paths[i].AsUTF16Unsafe(); |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5077 | |
| 5078 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 5079 | enumeration_completions_.erase(id); |
| 5080 | } |
| 5081 | |
[email protected] | fb11b6a4 | 2012-03-14 07:25:12 | [diff] [blame] | 5082 | void RenderViewImpl::OnFileChooserResponse( |
[email protected] | ddb034b | 2012-06-26 20:31:39 | [diff] [blame] | 5083 | const std::vector<ui::SelectedFileInfo>& files) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5084 | // This could happen if we navigated to a different page before the user |
| 5085 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5086 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5087 | return; |
| 5088 | |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5089 | // Convert Chrome's SelectedFileInfo list to WebKit's. |
| 5090 | WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files( |
| 5091 | files.size()); |
| 5092 | for (size_t i = 0; i < files.size(); ++i) { |
| 5093 | WebFileChooserCompletion::SelectedFileInfo selected_file; |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5094 | selected_file.path = files[i].local_path.AsUTF16Unsafe(); |
| 5095 | selected_file.displayName = |
| 5096 | base::FilePath(files[i].display_name).AsUTF16Unsafe(); |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5097 | selected_files[i] = selected_file; |
| 5098 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 5099 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5100 | if (file_chooser_completions_.front()->completion) |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5101 | file_chooser_completions_.front()->completion->didChooseFile( |
| 5102 | selected_files); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5103 | file_chooser_completions_.pop_front(); |
| 5104 | |
| 5105 | // If there are more pending file chooser requests, schedule one now. |
| 5106 | if (!file_chooser_completions_.empty()) { |
| 5107 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 5108 | file_chooser_completions_.front()->params)); |
| 5109 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5110 | } |
| 5111 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5112 | void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
| 5113 | const gfx::Size& max_size) { |
| 5114 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5115 | if (!webview()) |
| 5116 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 5117 | auto_resize_mode_ = true; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5118 | webview()->enableAutoResizeMode(min_size, max_size); |
| 5119 | } |
| 5120 | |
| 5121 | void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) { |
| 5122 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5123 | if (!webview()) |
| 5124 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 5125 | auto_resize_mode_ = false; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5126 | webview()->disableAutoResizeMode(); |
| 5127 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 5128 | if (!new_size.IsEmpty()) { |
| 5129 | Resize(new_size, |
| 5130 | physical_backing_size_, |
| 5131 | overdraw_bottom_height_, |
| 5132 | resizer_rect_, |
| 5133 | is_fullscreen_, |
| 5134 | NO_RESIZE_ACK); |
| 5135 | } |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5136 | } |
| 5137 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 5138 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5139 | if (send_preferred_size_changes_) |
| 5140 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5141 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 5142 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5143 | // Start off with an initial preferred size notification (in case |
| 5144 | // |didUpdateLayout| was already called). |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 5145 | didUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 5146 | } |
| 5147 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5148 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5149 | const gfx::Size& disable_scrollbar_size_limit) { |
| 5150 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 5151 | } |
| 5152 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5153 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5154 | const RendererPreferences& renderer_prefs) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5155 | double old_zoom_level = renderer_preferences_.default_zoom_level; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5156 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 5157 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5158 | |
| 5159 | #if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5160 | if (renderer_prefs.use_custom_colors) { |
| 5161 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 5162 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
| 5163 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5164 | #if defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5165 | ui::NativeTheme::instance()->SetScrollbarColors( |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 5166 | renderer_prefs.thumb_inactive_color, |
| 5167 | renderer_prefs.thumb_active_color, |
| 5168 | renderer_prefs.track_color); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5169 | #endif // defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5170 | |
| 5171 | if (webview()) { |
| 5172 | #if defined(TOOLKIT_GTK) |
| 5173 | webview()->setScrollbarColors( |
| 5174 | renderer_prefs.thumb_inactive_color, |
| 5175 | renderer_prefs.thumb_active_color, |
| 5176 | renderer_prefs.track_color); |
| 5177 | #endif // defined(TOOLKIT_GTK) |
| 5178 | webview()->setSelectionColors( |
| 5179 | renderer_prefs.active_selection_bg_color, |
| 5180 | renderer_prefs.active_selection_fg_color, |
| 5181 | renderer_prefs.inactive_selection_bg_color, |
| 5182 | renderer_prefs.inactive_selection_fg_color); |
| 5183 | webview()->themeChanged(); |
| 5184 | } |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5185 | } |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5186 | #endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5187 | |
[email protected] | 107c053 | 2013-02-06 02:34:09 | [diff] [blame] | 5188 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 5189 | RenderThreadImpl::current()->SetFlingCurveParameters( |
| 5190 | renderer_prefs.touchpad_fling_profile, |
| 5191 | renderer_prefs.touchscreen_fling_profile); |
| 5192 | |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5193 | // If the zoom level for this page matches the old zoom default, and this |
| 5194 | // is not a plugin, update the zoom level to match the new default. |
| 5195 | if (webview() && !webview()->mainFrame()->document().isPluginDocument() && |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 5196 | !ZoomValuesEqual(old_zoom_level, |
| 5197 | renderer_preferences_.default_zoom_level) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5198 | ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) { |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 5199 | webview()->setZoomLevel(renderer_preferences_.default_zoom_level); |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5200 | zoomLevelChanged(); |
| 5201 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5202 | } |
| 5203 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5204 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 5205 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 5206 | if (webview()) |
| 5207 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 5208 | } |
| 5209 | |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 5210 | void RenderViewImpl::OnOrientationChangeEvent(int orientation) { |
[email protected] | 652ad83 | 2013-08-16 11:47:04 | [diff] [blame] | 5211 | FOR_EACH_OBSERVER(RenderViewObserver, |
| 5212 | observers_, |
| 5213 | OrientationChangeEvent(orientation)); |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 5214 | webview()->mainFrame()->sendOrientationChangeEvent(orientation); |
| 5215 | } |
| 5216 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 5217 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 5218 | const WebPluginAction& action) { |
| 5219 | if (webview()) |
| 5220 | webview()->performPluginAction(action, location); |
| 5221 | } |
| 5222 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5223 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5224 | const GURL& page_url) { |
| 5225 | // Prepare list to storage all savable resource links. |
| 5226 | std::vector<GURL> resources_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5227 | std::vector<GURL> referrer_urls_list; |
| 5228 | std::vector<WebKit::WebReferrerPolicy> referrer_policies_list; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5229 | std::vector<GURL> frames_list; |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 5230 | SavableResourcesResult result(&resources_list, |
| 5231 | &referrer_urls_list, |
| 5232 | &referrer_policies_list, |
| 5233 | &frames_list); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5234 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5235 | // webkit/ doesn't know about Referrer. |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 5236 | if (!GetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5237 | webview(), |
| 5238 | page_url, |
| 5239 | &result, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5240 | const_cast<const char**>(GetSavableSchemes()))) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5241 | // If something is wrong when collecting all savable resource links, |
| 5242 | // send empty list to embedder(browser) to tell it failed. |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5243 | referrer_urls_list.clear(); |
| 5244 | referrer_policies_list.clear(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5245 | resources_list.clear(); |
| 5246 | frames_list.clear(); |
| 5247 | } |
| 5248 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5249 | std::vector<Referrer> referrers_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5250 | CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size()); |
| 5251 | for (unsigned i = 0; i < referrer_urls_list.size(); ++i) { |
| 5252 | referrers_list.push_back( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5253 | Referrer(referrer_urls_list[i], referrer_policies_list[i])); |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5254 | } |
| 5255 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5256 | // Send result of all savable resource links to embedder. |
| 5257 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 5258 | resources_list, |
| 5259 | referrers_list, |
| 5260 | frames_list)); |
| 5261 | } |
| 5262 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5263 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5264 | const std::vector<GURL>& links, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 5265 | const std::vector<base::FilePath>& local_paths, |
| 5266 | const base::FilePath& local_directory_name) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5267 | |
| 5268 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 5269 | WebVector<WebURL> weburl_links(links); |
| 5270 | |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5271 | // Convert std::vector of base::FilePath to WebVector<WebString> |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5272 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 5273 | for (size_t i = 0; i < local_paths.size(); i++) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5274 | webstring_paths[i] = local_paths[i].AsUTF16Unsafe(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5275 | |
| 5276 | WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links, |
| 5277 | webstring_paths, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5278 | local_directory_name.AsUTF16Unsafe()); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5279 | } |
| 5280 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5281 | void RenderViewImpl::OnShouldClose() { |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5282 | base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5283 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5284 | base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); |
| 5285 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, |
| 5286 | before_unload_start_time, |
| 5287 | before_unload_end_time)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5288 | } |
| 5289 | |
[email protected] | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 5290 | void RenderViewImpl::OnSwapOut() { |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5291 | // Only run unload if we're not swapped out yet, but send the ack either way. |
| 5292 | if (!is_swapped_out_) { |
| 5293 | // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 5294 | // different process. This involves running the unload handler and clearing |
| 5295 | // the page. Once WasSwappedOut is called, we also allow this process to |
| 5296 | // exit if there are no other active RenderViews in it. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5297 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5298 | // Send an UpdateState message before we get swapped out. |
| 5299 | SyncNavigationState(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5300 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5301 | // Synchronously run the unload handler before sending the ACK. |
| 5302 | webview()->dispatchUnloadEvent(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5303 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5304 | // Swap out and stop sending any IPC messages that are not ACKs. |
| 5305 | SetSwappedOut(true); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5306 | |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 5307 | // Now that we're swapped out and filtering IPC messages, stop loading to |
| 5308 | // ensure that no other in-progress navigation continues. We do this here |
| 5309 | // to avoid sending a DidStopLoading message to the browser process. |
| 5310 | OnStop(); |
| 5311 | |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 5312 | // 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] | 5313 | // run a second time, thanks to a check in FrameLoader::stopLoading. |
| 5314 | // 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] | 5315 | // beforeunload handler. For now, we just run it a second time silently. |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5316 | NavigateToSwappedOutURL(webview()->mainFrame()); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 5317 | |
| 5318 | // Let WebKit know that this view is hidden so it can drop resources and |
| 5319 | // stop compositing. |
| 5320 | webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5321 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5322 | |
[email protected] | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 5323 | Send(new ViewHostMsg_SwapOut_ACK(routing_id_)); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5324 | } |
| 5325 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5326 | void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5327 | // We use loadRequest instead of loadHTMLString because the former commits |
| 5328 | // synchronously. Otherwise a new navigation can interrupt the navigation |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5329 | // to kSwappedOutURL. If that happens to be to the page we had been |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5330 | // 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] | 5331 | CHECK(is_swapped_out_); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5332 | GURL swappedOutURL(kSwappedOutURL); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5333 | WebURLRequest request(swappedOutURL); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5334 | frame->loadRequest(request); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5335 | } |
| 5336 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5337 | void RenderViewImpl::OnClosePage() { |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 5338 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5339 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 5340 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 5341 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 5342 | // calling the FrameLoader's CloseURL method directly. This should be |
| 5343 | // revisited to avoid having two ways to close a page. Having a single way |
| 5344 | // to close that can run onunload is also useful for fixing |
| 5345 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5346 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5347 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5348 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5349 | } |
| 5350 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5351 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 5352 | #if defined(USE_AURA) |
| 5353 | // Aura doesn't care if we switch themes. |
| 5354 | #elif defined(OS_WIN) |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 5355 | ui::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 5356 | if (webview()) |
| 5357 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 5358 | #else // defined(OS_WIN) |
| 5359 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 5360 | NOTIMPLEMENTED(); |
| 5361 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5362 | } |
| 5363 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5364 | bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 5365 | const WebURLError& error, |
| 5366 | bool replace) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5367 | // We only show alternate error pages in the main frame. They are |
| 5368 | // intended to assist the user when navigating, so there is not much |
| 5369 | // value in showing them for failed subframes. Ideally, we would be |
| 5370 | // able to use the TYPED transition type for this, but that flag is |
| 5371 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5372 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5373 | return false; |
| 5374 | |
| 5375 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 5376 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5377 | int ec = error.reason; |
| 5378 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 5379 | ec != net::ERR_CONNECTION_FAILED && |
| 5380 | ec != net::ERR_CONNECTION_REFUSED && |
| 5381 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5382 | ec != net::ERR_CONNECTION_TIMED_OUT) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5383 | return false; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5384 | } |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5385 | |
| 5386 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5387 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5388 | if (!error_page_url.is_valid()) |
| 5389 | return false; |
| 5390 | |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5391 | WebDataSource* ds = frame->provisionalDataSource(); |
| 5392 | const WebURLRequest& failed_request = ds->request(); |
| 5393 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5394 | // Load an empty page first so there is an immediate response to the error, |
| 5395 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5396 | frame->loadHTMLString(std::string(), |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5397 | GURL(kUnreachableWebDataURL), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5398 | error.unreachableURL, |
| 5399 | replace); |
| 5400 | |
| 5401 | // Now, create a fetcher for the error page and associate it with the data |
| 5402 | // source we just created via the LoadHTMLString call. That way if another |
| 5403 | // navigation occurs, the fetcher will get destroyed. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 5404 | InternalDocumentStateData* internal_data = |
| 5405 | InternalDocumentStateData::FromDataSource(frame->provisionalDataSource()); |
| 5406 | internal_data->set_alt_error_page_fetcher( |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5407 | new AltErrorPageResourceFetcher( |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5408 | error_page_url, frame, failed_request, error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 5409 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 5410 | base::Unretained(this)))); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5411 | return true; |
| 5412 | } |
| 5413 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5414 | void RenderViewImpl::AltErrorPageFinished(WebFrame* frame, |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5415 | const WebURLRequest& original_request, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5416 | const WebURLError& original_error, |
| 5417 | const std::string& html) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5418 | // Here, we replace the blank page we loaded previously. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 5419 | // If we failed to download the alternate error page, LoadNavigationErrorPage |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5420 | // will simply display a default error page. |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5421 | LoadNavigationErrorPage(frame, original_request, original_error, html, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5422 | } |
| 5423 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5424 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5425 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5426 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5427 | } |
| 5428 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5429 | void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5430 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5431 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5432 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 5433 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5434 | ShouldDisplayScrollbars(params.new_size.width(), |
| 5435 | params.new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5436 | } |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 5437 | UpdateScrollState(webview()->mainFrame()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5438 | } |
| 5439 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5440 | RenderWidget::OnResize(params); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5441 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 5442 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5443 | void RenderViewImpl::WillInitiatePaint() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5444 | #if defined(ENABLE_PLUGINS) |
| 5445 | // Notify all of our instances that we started painting. This is used for |
| 5446 | // internal bookkeeping only, so we know that the set can not change under |
| 5447 | // us. |
| 5448 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 5449 | i != active_pepper_instances_.end(); ++i) |
| 5450 | (*i)->ViewWillInitiatePaint(); |
| 5451 | #endif |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5452 | } |
| 5453 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5454 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5455 | #if defined(ENABLE_PLUGINS) |
| 5456 | // Notify all instances that we painted. The same caveats apply as for |
| 5457 | // ViewFlushedPaint regarding instances closing themselves, so we take |
| 5458 | // similar precautions. |
| 5459 | PepperPluginSet plugins = active_pepper_instances_; |
| 5460 | for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) { |
| 5461 | if (active_pepper_instances_.find(*i) != active_pepper_instances_.end()) |
| 5462 | (*i)->ViewInitiatedPaint(); |
| 5463 | } |
| 5464 | #endif |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5465 | } |
| 5466 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5467 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5468 | #if defined(ENABLE_PLUGINS) |
| 5469 | // Notify all instances that we flushed. This will call into the plugin, and |
| 5470 | // we it may ask to close itself as a result. This will, in turn, modify our |
| 5471 | // set, possibly invalidating the iterator. So we iterate on a copy that |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5472 | // won't change out from under us. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5473 | PepperPluginSet plugins = active_pepper_instances_; |
| 5474 | for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) { |
| 5475 | // The copy above makes sure our iterator is never invalid if some plugins |
| 5476 | // are destroyed. But some plugin may decide to close all of its views in |
| 5477 | // response to a paint in one of them, so we need to make sure each one is |
| 5478 | // still "current" before using it. |
| 5479 | // |
| 5480 | // It's possible that a plugin was destroyed, but another one was created |
| 5481 | // with the same address. In this case, we'll call ViewFlushedPaint on that |
| 5482 | // new plugin. But that's OK for this particular case since we're just |
| 5483 | // notifying all of our instances that the view flushed, and the new one is |
| 5484 | // one of our instances. |
| 5485 | // |
| 5486 | // What about the case where a new one is created in a callback at a new |
| 5487 | // address and we don't issue the callback? We're still OK since this |
| 5488 | // callback is used for flush callbacks and we could not have possibly |
| 5489 | // started a new paint (ViewWillInitiatePaint) for the new plugin while |
| 5490 | // processing a previous paint for an existing one. |
| 5491 | if (active_pepper_instances_.find(*i) != active_pepper_instances_.end()) |
| 5492 | (*i)->ViewFlushedPaint(); |
| 5493 | } |
| 5494 | #endif |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 5495 | |
[email protected] | 5b1dec8c | 2012-02-07 04:35:38 | [diff] [blame] | 5496 | // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 5497 | // See crbug.com/112921. |
| 5498 | if (!webview()) |
| 5499 | return; |
| 5500 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5501 | WebFrame* main_frame = webview()->mainFrame(); |
| 5502 | |
| 5503 | // If we have a provisional frame we are between the start and commit stages |
| 5504 | // of loading and we don't want to save stats. |
| 5505 | if (!main_frame->provisionalDataSource()) { |
| 5506 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5507 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 5508 | InternalDocumentStateData* data = |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 5509 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 5510 | if (data->did_first_visually_non_empty_layout() && |
| 5511 | !data->did_first_visually_non_empty_paint()) { |
| 5512 | data->set_did_first_visually_non_empty_paint(true); |
| 5513 | Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_, |
| 5514 | page_id_)); |
| 5515 | } |
| 5516 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5517 | // TODO(jar): The following code should all be inside a method, probably in |
| 5518 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5519 | Time now = Time::Now(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5520 | if (document_state->first_paint_time().is_null()) { |
| 5521 | document_state->set_first_paint_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5522 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5523 | if (document_state->first_paint_after_load_time().is_null() && |
| 5524 | !document_state->finish_load_time().is_null()) { |
| 5525 | document_state->set_first_paint_after_load_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5526 | } |
| 5527 | } |
| 5528 | } |
| 5529 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 5530 | PepperPluginInstanceImpl* RenderViewImpl::GetBitmapForOptimizedPluginPaint( |
| 5531 | const gfx::Rect& paint_bounds, |
| 5532 | TransportDIB** dib, |
| 5533 | gfx::Rect* location, |
| 5534 | gfx::Rect* clip, |
| 5535 | float* scale_factor) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5536 | #if defined(ENABLE_PLUGINS) |
| 5537 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 5538 | i != active_pepper_instances_.end(); ++i) { |
| 5539 | PepperPluginInstanceImpl* instance = *i; |
| 5540 | // In Flash fullscreen , the plugin contents should be painted onto the |
| 5541 | // fullscreen widget instead of the web page. |
| 5542 | if (!instance->FlashIsFullscreenOrPending() && |
| 5543 | instance->GetBitmapForOptimizedPluginPaint(paint_bounds, dib, location, |
| 5544 | clip, scale_factor)) |
| 5545 | return *i; |
| 5546 | } |
| 5547 | #endif |
| 5548 | return NULL; |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5549 | } |
| 5550 | |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5551 | gfx::Vector2d RenderViewImpl::GetScrollOffset() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5552 | WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5553 | return gfx::Vector2d(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 5554 | } |
| 5555 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5556 | void RenderViewImpl::OnClearFocusedNode() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5557 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5558 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5559 | } |
| 5560 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5561 | void RenderViewImpl::OnSetBackground(const SkBitmap& background) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5562 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5563 | webview()->setIsTransparent(!background.empty()); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 5564 | if (compositor_) |
| 5565 | compositor_->setHasTransparentBackground(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5566 | |
| 5567 | SetBackground(background); |
| 5568 | } |
| 5569 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5570 | void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) { |
| 5571 | if (accessibility_mode_ == new_mode) |
| 5572 | return; |
| 5573 | accessibility_mode_ = new_mode; |
| 5574 | if (renderer_accessibility_) { |
| 5575 | delete renderer_accessibility_; |
| 5576 | renderer_accessibility_ = NULL; |
| 5577 | } |
| 5578 | if (accessibility_mode_ == AccessibilityModeComplete) |
| 5579 | renderer_accessibility_ = new RendererAccessibilityComplete(this); |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 5580 | #if !defined(OS_ANDROID) |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5581 | else if (accessibility_mode_ == AccessibilityModeEditableTextOnly) |
| 5582 | renderer_accessibility_ = new RendererAccessibilityFocusOnly(this); |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 5583 | #endif |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5584 | } |
| 5585 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5586 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5587 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5588 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 5589 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5590 | #if defined(ENABLE_PLUGINS) && defined(OS_MACOSX) |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 5591 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5592 | for (plugin_it = plugin_delegates_.begin(); |
| 5593 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5594 | (*plugin_it)->SetWindowFocus(active); |
| 5595 | } |
| 5596 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5597 | } |
| 5598 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5599 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5600 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5601 | #if defined(ENABLE_PLUGINS) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5602 | // Inform plugins that their container has changed visibility. |
| 5603 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5604 | for (plugin_it = plugin_delegates_.begin(); |
| 5605 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5606 | (*plugin_it)->SetContainerVisibility(visible); |
| 5607 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5608 | #endif |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5609 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5610 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5611 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 5612 | const gfx::Rect& view_frame) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5613 | #if defined(ENABLE_PLUGINS) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5614 | // Inform plugins that their window's frame has changed. |
| 5615 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5616 | for (plugin_it = plugin_delegates_.begin(); |
| 5617 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5618 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 5619 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5620 | #endif |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5621 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5622 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5623 | void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text, |
| 5624 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5625 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5626 | // applies to it or not, so inform all the delegates. |
| 5627 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5628 | for (plugin_it = plugin_delegates_.begin(); |
| 5629 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5630 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5631 | } |
| 5632 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5633 | #endif // OS_MACOSX |
| 5634 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5635 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5636 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5637 | WebView* doomed = webview(); |
| 5638 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 5639 | g_view_map.Get().erase(doomed); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 5640 | g_routing_id_view_map.Get().erase(routing_id_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5641 | } |
| 5642 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5643 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 5644 | ClearEditCommands(); |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5645 | } |
| 5646 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5647 | bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 5648 | context_menu_source_type_ = ui::MENU_SOURCE_MOUSE; |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5649 | possible_drag_event_info_.event_source = |
| 5650 | ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 5651 | possible_drag_event_info_.event_location = |
| 5652 | gfx::Point(event.globalX, event.globalY); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5653 | |
| 5654 | #if defined(ENABLE_PLUGINS) |
| 5655 | // This method is called for every mouse event that the render view receives. |
| 5656 | // And then the mouse event is forwarded to WebKit, which dispatches it to the |
| 5657 | // event target. Potentially a Pepper plugin will receive the event. |
| 5658 | // In order to tell whether a plugin gets the last mouse event and which it |
| 5659 | // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets |
| 5660 | // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 5661 | // |pepper_last_mouse_event_target_|. |
| 5662 | pepper_last_mouse_event_target_ = NULL; |
| 5663 | #endif |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 5664 | |
| 5665 | // If the mouse is locked, only the current owner of the mouse lock can |
| 5666 | // process mouse events. |
| 5667 | return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 5668 | } |
| 5669 | |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 5670 | bool RenderViewImpl::WillHandleKeyEvent(const WebKit::WebKeyboardEvent& event) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 5671 | context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD; |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 5672 | return false; |
| 5673 | } |
| 5674 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5675 | bool RenderViewImpl::WillHandleGestureEvent( |
| 5676 | const WebKit::WebGestureEvent& event) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 5677 | context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5678 | possible_drag_event_info_.event_source = |
| 5679 | ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH; |
| 5680 | possible_drag_event_info_.event_location = |
| 5681 | gfx::Point(event.globalX, event.globalY); |
| 5682 | return false; |
| 5683 | } |
| 5684 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 5685 | void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 5686 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5687 | } |
| 5688 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5689 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 5690 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 5691 | } |
| 5692 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 5693 | bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const { |
| 5694 | if (!webview()) |
| 5695 | return false; |
| 5696 | return webview()->hasTouchEventHandlersAt(point); |
| 5697 | } |
| 5698 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5699 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5700 | RenderWidget::OnWasHidden(); |
| 5701 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 5702 | #if defined(OS_ANDROID) |
[email protected] | bc42744 | 2013-07-13 02:53:08 | [diff] [blame] | 5703 | // Inform RendererMediaPlayerManager to release all media player resources. |
[email protected] | 1c36bea | 2013-07-01 13:43:01 | [diff] [blame] | 5704 | // unless some audio is playing. |
[email protected] | 263135d | 2012-11-15 13:01:56 | [diff] [blame] | 5705 | // If something is in progress the resource will not be freed, it will |
| 5706 | // only be freed once the tab is destroyed or if the user navigates away |
| 5707 | // via WebMediaPlayerAndroid::Destroy |
[email protected] | 1c36bea | 2013-07-01 13:43:01 | [diff] [blame] | 5708 | media_player_manager_->ReleaseMediaResources(); |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 5709 | |
| 5710 | #if defined(ENABLE_WEBRTC) |
| 5711 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 5712 | SuspendDevices(true); |
| 5713 | #endif |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 5714 | #endif |
| 5715 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 5716 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5717 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5718 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5719 | #if defined(ENABLE_PLUGINS) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5720 | // Inform PPAPI plugins that their page is no longer visible. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5721 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 5722 | i != active_pepper_instances_.end(); ++i) |
| 5723 | (*i)->PageVisibilityChanged(false); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5724 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5725 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5726 | // Inform NPAPI plugins that their container is no longer visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5727 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5728 | for (plugin_it = plugin_delegates_.begin(); |
| 5729 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5730 | (*plugin_it)->SetContainerVisibility(false); |
| 5731 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5732 | #endif // OS_MACOSX |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5733 | #endif // ENABLE_PLUGINS |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5734 | } |
| 5735 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 5736 | void RenderViewImpl::OnWasShown(bool needs_repainting) { |
| 5737 | RenderWidget::OnWasShown(needs_repainting); |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5738 | |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 5739 | #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 5740 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 5741 | SuspendDevices(false); |
| 5742 | #endif |
| 5743 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 5744 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5745 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5746 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5747 | #if defined(ENABLE_PLUGINS) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5748 | // Inform PPAPI plugins that their page is visible. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5749 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 5750 | i != active_pepper_instances_.end(); ++i) |
| 5751 | (*i)->PageVisibilityChanged(true); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5752 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5753 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5754 | // Inform NPAPI plugins that their container is now visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5755 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5756 | for (plugin_it = plugin_delegates_.begin(); |
| 5757 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5758 | (*plugin_it)->SetContainerVisibility(true); |
| 5759 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5760 | #endif // OS_MACOSX |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5761 | #endif // ENABLE_PLUGINS |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5762 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5763 | |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 5764 | GURL RenderViewImpl::GetURLForGraphicsContext3D() { |
| 5765 | DCHECK(webview()); |
| 5766 | if (webview()->mainFrame()) |
| 5767 | return GURL(webview()->mainFrame()->document().url()); |
| 5768 | else |
| 5769 | return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5770 | } |
| 5771 | |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 5772 | bool RenderViewImpl::ForceCompositingModeEnabled() { |
| 5773 | return webkit_preferences_.force_compositing_mode; |
| 5774 | } |
| 5775 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5776 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5777 | RenderWidget::OnSetFocus(enable); |
| 5778 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5779 | #if defined(ENABLE_PLUGINS) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5780 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5781 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5782 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5783 | for (plugin_it = plugin_delegates_.begin(); |
| 5784 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5785 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5786 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5787 | // activation state to change just like a call to setIsActive. |
| 5788 | if (enable) |
| 5789 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5790 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5791 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5792 | } |
| 5793 | } |
[email protected] | a01da568 | 2012-06-30 00:37:31 | [diff] [blame] | 5794 | // Notify all Pepper plugins. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5795 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 5796 | i != active_pepper_instances_.end(); ++i) |
| 5797 | (*i)->SetContentAreaFocus(enable); |
| 5798 | #endif |
[email protected] | 32103299 | 2012-11-08 01:01:27 | [diff] [blame] | 5799 | // Notify all BrowserPlugins of the RenderView's focus state. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 5800 | if (browser_plugin_manager_.get()) |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 5801 | browser_plugin_manager_->UpdateFocusState(); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5802 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5803 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5804 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5805 | const string16& text, |
| 5806 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 5807 | int selection_start, |
| 5808 | int selection_end) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5809 | #if defined(ENABLE_PLUGINS) |
| 5810 | if (focused_pepper_plugin_) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5811 | // When a PPAPI plugin has focus, we bypass WebKit. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5812 | if (!IsPepperAcceptingCompositionEvents()) { |
| 5813 | pepper_composition_text_ = text; |
| 5814 | } else { |
| 5815 | // TODO(kinaba) currently all composition events are sent directly to |
| 5816 | // plugins. Use DOM event mechanism after WebKit is made aware about |
| 5817 | // plugins that support composition. |
| 5818 | // The code below mimics the behavior of WebCore::Editor::setComposition. |
| 5819 | |
| 5820 | // Empty -> nonempty: composition started. |
| 5821 | if (pepper_composition_text_.empty() && !text.empty()) |
| 5822 | focused_pepper_plugin_->HandleCompositionStart(string16()); |
| 5823 | // Nonempty -> empty: composition canceled. |
| 5824 | if (!pepper_composition_text_.empty() && text.empty()) |
| 5825 | focused_pepper_plugin_->HandleCompositionEnd(string16()); |
| 5826 | pepper_composition_text_ = text; |
| 5827 | // Nonempty: composition is ongoing. |
| 5828 | if (!pepper_composition_text_.empty()) { |
| 5829 | focused_pepper_plugin_->HandleCompositionUpdate( |
| 5830 | pepper_composition_text_, underlines, selection_start, |
| 5831 | selection_end); |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5832 | } |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5833 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5834 | return; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5835 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5836 | |
| 5837 | #if defined(OS_WIN) |
| 5838 | // When a plug-in has focus, we create platform-specific IME data used by |
| 5839 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 5840 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 5841 | // instance ID is the same one as the specified ID.) |
| 5842 | if (focused_plugin_id_ >= 0) { |
| 5843 | std::vector<int> clauses; |
| 5844 | std::vector<int> target; |
| 5845 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 5846 | clauses.push_back(underlines[i].startOffset); |
| 5847 | clauses.push_back(underlines[i].endOffset); |
| 5848 | if (underlines[i].thick) { |
| 5849 | target.clear(); |
| 5850 | target.push_back(underlines[i].startOffset); |
| 5851 | target.push_back(underlines[i].endOffset); |
| 5852 | } |
| 5853 | } |
| 5854 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5855 | for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) { |
| 5856 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 5857 | focused_plugin_id_); |
| 5858 | } |
| 5859 | return; |
| 5860 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5861 | #endif // OS_WIN |
| 5862 | #endif // ENABLE_PLUGINS |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5863 | RenderWidget::OnImeSetComposition(text, |
| 5864 | underlines, |
| 5865 | selection_start, |
| 5866 | selection_end); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5867 | } |
| 5868 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 5869 | void RenderViewImpl::OnImeConfirmComposition( |
| 5870 | const string16& text, |
| 5871 | const gfx::Range& replacement_range, |
| 5872 | bool keep_selection) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5873 | #if defined(ENABLE_PLUGINS) |
| 5874 | if (focused_pepper_plugin_) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5875 | // When a PPAPI plugin has focus, we bypass WebKit. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5876 | // Here, text.empty() has a special meaning. It means to commit the last |
| 5877 | // update of composition text (see |
| 5878 | // RenderWidgetHost::ImeConfirmComposition()). |
| 5879 | const string16& last_text = text.empty() ? pepper_composition_text_ : text; |
| 5880 | |
| 5881 | // last_text is empty only when both text and pepper_composition_text_ is. |
| 5882 | // Ignore it. |
| 5883 | if (last_text.empty()) |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5884 | return; |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5885 | |
| 5886 | if (!IsPepperAcceptingCompositionEvents()) { |
[email protected] | 28fccb3 | 2013-08-29 22:25:46 | [diff] [blame] | 5887 | base::i18n::UTF16CharIterator iterator(&last_text); |
| 5888 | int32 i = 0; |
| 5889 | while (iterator.Advance()) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5890 | WebKit::WebKeyboardEvent char_event; |
| 5891 | char_event.type = WebKit::WebInputEvent::Char; |
| 5892 | char_event.timeStampSeconds = base::Time::Now().ToDoubleT(); |
| 5893 | char_event.modifiers = 0; |
| 5894 | char_event.windowsKeyCode = last_text[i]; |
| 5895 | char_event.nativeKeyCode = last_text[i]; |
[email protected] | 28fccb3 | 2013-08-29 22:25:46 | [diff] [blame] | 5896 | |
| 5897 | const int32 char_start = i; |
| 5898 | for (; i < iterator.array_pos(); ++i) { |
| 5899 | char_event.text[i - char_start] = last_text[i]; |
| 5900 | char_event.unmodifiedText[i - char_start] = last_text[i]; |
| 5901 | } |
| 5902 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5903 | if (webwidget()) |
| 5904 | webwidget()->handleInputEvent(char_event); |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5905 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5906 | } else { |
| 5907 | // Mimics the order of events sent by WebKit. |
| 5908 | // See WebCore::Editor::setComposition() for the corresponding code. |
| 5909 | focused_pepper_plugin_->HandleCompositionEnd(last_text); |
| 5910 | focused_pepper_plugin_->HandleTextInput(last_text); |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5911 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5912 | pepper_composition_text_.clear(); |
| 5913 | return; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5914 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5915 | #if defined(OS_WIN) |
| 5916 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 5917 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 5918 | // it to WebKit to prevent WebKit from controlling IMEs. |
| 5919 | // TODO(thakis): Honor |replacement_range| for plugins? |
| 5920 | if (focused_plugin_id_ >= 0) { |
| 5921 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5922 | for (it = plugin_delegates_.begin(); |
| 5923 | it != plugin_delegates_.end(); ++it) { |
| 5924 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 5925 | } |
| 5926 | return; |
| 5927 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5928 | #endif // OS_WIN |
| 5929 | #endif // ENABLE_PLUGINS |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5930 | if (replacement_range.IsValid() && webview()) { |
| 5931 | // Select the text in |replacement_range|, it will then be replaced by |
| 5932 | // text added by the call to RenderWidget::OnImeConfirmComposition(). |
| 5933 | if (WebFrame* frame = webview()->focusedFrame()) { |
| 5934 | WebRange webrange = WebRange::fromDocumentRange( |
| 5935 | frame, replacement_range.start(), replacement_range.length()); |
| 5936 | if (!webrange.isNull()) |
| 5937 | frame->selectRange(webrange); |
| 5938 | } |
| 5939 | } |
| 5940 | RenderWidget::OnImeConfirmComposition(text, |
| 5941 | replacement_range, |
| 5942 | keep_selection); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5943 | } |
| 5944 | |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 5945 | void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) { |
| 5946 | RenderWidget::SetDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 5947 | if (webview()) { |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 5948 | webview()->setDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 5949 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 5950 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 5951 | webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled( |
| 5952 | ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_)); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 5953 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 5954 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 5955 | webview()->settings()-> |
| 5956 | setAcceleratedCompositingForFixedRootBackgroundEnabled( |
| 5957 | ShouldUseAcceleratedFixedRootBackground(device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 5958 | } |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 5959 | if (auto_resize_mode_) |
| 5960 | AutoResizeCompositor(); |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 5961 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 5962 | if (browser_plugin_manager_.get()) |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 5963 | browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_); |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 5964 | } |
| 5965 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5966 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5967 | #if defined(ENABLE_PLUGINS) |
| 5968 | if (focused_pepper_plugin_) |
| 5969 | return focused_pepper_plugin_->text_input_type(); |
| 5970 | #endif |
| 5971 | return RenderWidget::GetTextInputType(); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5972 | } |
| 5973 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5974 | void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5975 | #if defined(ENABLE_PLUGINS) |
| 5976 | if (focused_pepper_plugin_) { |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5977 | // TODO(kinaba) http://crbug.com/101101 |
| 5978 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 5979 | // use the caret position as an empty range for now. It will be updated |
| 5980 | // after Pepper API equips features related to surrounding text retrieval. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5981 | gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds(); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5982 | *start = caret; |
| 5983 | *end = caret; |
| 5984 | return; |
| 5985 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5986 | #endif |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5987 | RenderWidget::GetSelectionBounds(start, end); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 5988 | } |
| 5989 | |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 5990 | #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA) |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 5991 | void RenderViewImpl::GetCompositionCharacterBounds( |
| 5992 | std::vector<gfx::Rect>* bounds) { |
| 5993 | DCHECK(bounds); |
| 5994 | bounds->clear(); |
| 5995 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5996 | #if defined(ENABLE_PLUGINS) |
| 5997 | if (focused_pepper_plugin_) { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 5998 | return; |
| 5999 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6000 | #endif |
| 6001 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 6002 | if (!webview()) |
| 6003 | return; |
| 6004 | size_t start_offset = 0; |
| 6005 | size_t character_count = 0; |
| 6006 | if (!webview()->compositionRange(&start_offset, &character_count)) |
| 6007 | return; |
| 6008 | if (character_count == 0) |
| 6009 | return; |
| 6010 | |
| 6011 | WebKit::WebFrame* frame = webview()->focusedFrame(); |
| 6012 | if (!frame) |
| 6013 | return; |
| 6014 | |
| 6015 | bounds->reserve(character_count); |
| 6016 | WebKit::WebRect webrect; |
| 6017 | for (size_t i = 0; i < character_count; ++i) { |
| 6018 | if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { |
| 6019 | DLOG(ERROR) << "Could not retrieve character rectangle at " << i; |
| 6020 | bounds->clear(); |
| 6021 | return; |
| 6022 | } |
| 6023 | bounds->push_back(webrect); |
| 6024 | } |
| 6025 | } |
| 6026 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 6027 | void RenderViewImpl::GetCompositionRange(gfx::Range* range) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6028 | #if defined(ENABLE_PLUGINS) |
| 6029 | if (focused_pepper_plugin_) { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 6030 | return; |
| 6031 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6032 | #endif |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 6033 | RenderWidget::GetCompositionRange(range); |
| 6034 | } |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 6035 | #endif |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 6036 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6037 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6038 | #if defined(ENABLE_PLUGINS) |
| 6039 | if (focused_pepper_plugin_) |
| 6040 | return IsPepperAcceptingCompositionEvents(); |
| 6041 | #endif |
| 6042 | return true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 6043 | } |
| 6044 | |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 6045 | void RenderViewImpl::InstrumentWillBeginFrame() { |
| 6046 | if (!webview()) |
| 6047 | return; |
| 6048 | if (!webview()->devToolsAgent()) |
| 6049 | return; |
| 6050 | webview()->devToolsAgent()->didBeginFrame(); |
| 6051 | } |
| 6052 | |
| 6053 | void RenderViewImpl::InstrumentDidBeginFrame() { |
| 6054 | if (!webview()) |
| 6055 | return; |
| 6056 | if (!webview()->devToolsAgent()) |
| 6057 | return; |
| 6058 | // TODO(jamesr/caseq): Decide if this needs to be renamed. |
| 6059 | webview()->devToolsAgent()->didComposite(); |
| 6060 | } |
| 6061 | |
| 6062 | void RenderViewImpl::InstrumentDidCancelFrame() { |
| 6063 | if (!webview()) |
| 6064 | return; |
| 6065 | if (!webview()->devToolsAgent()) |
| 6066 | return; |
| 6067 | webview()->devToolsAgent()->didCancelFrame(); |
| 6068 | } |
| 6069 | |
| 6070 | void RenderViewImpl::InstrumentWillComposite() { |
| 6071 | if (!webview()) |
| 6072 | return; |
| 6073 | if (!webview()->devToolsAgent()) |
| 6074 | return; |
| 6075 | webview()->devToolsAgent()->willComposite(); |
| 6076 | } |
| 6077 | |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 6078 | bool RenderViewImpl::AllowPartialSwap() const { |
| 6079 | return allow_partial_swap_; |
| 6080 | } |
| 6081 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6082 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6083 | const FileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 6084 | WebFileChooserCompletion* completion) { |
| 6085 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 6086 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 6087 | // This sanity check prevents too many file choose requests from getting |
| 6088 | // queued which could DoS the user. Getting these is most likely a |
| 6089 | // programming error (there are many ways to DoS the user so it's not |
| 6090 | // considered a "real" security check), either in JS requesting many file |
| 6091 | // choosers to pop up, or in a plugin. |
| 6092 | // |
| 6093 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 6094 | // a file picker, which will address this issue in a better way. |
| 6095 | return false; |
| 6096 | } |
| 6097 | |
| 6098 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 6099 | new PendingFileChooser(params, completion))); |
| 6100 | if (file_chooser_completions_.size() == 1) { |
| 6101 | // Actually show the browse dialog when this is the first request. |
| 6102 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 6103 | } |
| 6104 | return true; |
| 6105 | } |
| 6106 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6107 | WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 6108 | if (!geolocation_dispatcher_) |
| 6109 | geolocation_dispatcher_ = new GeolocationDispatcher(this); |
| 6110 | return geolocation_dispatcher_; |
[email protected] | 7e0c470 | 2010-12-31 14:06:25 | [diff] [blame] | 6111 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6112 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6113 | WebKit::WebSpeechInputController* RenderViewImpl::speechInputController( |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6114 | WebKit::WebSpeechInputListener* listener) { |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6115 | #if defined(ENABLE_INPUT_SPEECH) |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6116 | if (!input_tag_speech_dispatcher_) |
| 6117 | input_tag_speech_dispatcher_ = |
| 6118 | new InputTagSpeechDispatcher(this, listener); |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6119 | #endif |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6120 | return input_tag_speech_dispatcher_; |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6121 | } |
| 6122 | |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6123 | WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6124 | if (!speech_recognition_dispatcher_) |
| 6125 | speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6126 | return speech_recognition_dispatcher_; |
| 6127 | } |
| 6128 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6129 | WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 6130 | if (!device_orientation_dispatcher_) |
| 6131 | device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this); |
| 6132 | return device_orientation_dispatcher_; |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 6133 | } |
| 6134 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6135 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 6136 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6137 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 6138 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 6139 | // different). |
| 6140 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 6141 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6142 | int minimum_percent = static_cast<int>( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 6143 | ZoomLevelToZoomFactor(minimum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6144 | int maximum_percent = static_cast<int>( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 6145 | ZoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6146 | |
| 6147 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 6148 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 6149 | } |
| 6150 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6151 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6152 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6153 | float zoom_level = webview()->zoomLevel(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 6154 | |
| 6155 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged()); |
| 6156 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6157 | // Tell the browser which url got zoomed so it can update the menu and the |
| 6158 | // saved values if necessary |
| 6159 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6160 | routing_id_, zoom_level, remember, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 6161 | GURL(webview()->mainFrame()->document().url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6162 | } |
| 6163 | |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 6164 | double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const { |
| 6165 | return ZoomLevelToZoomFactor(zoom_level); |
| 6166 | } |
| 6167 | |
| 6168 | double RenderViewImpl::zoomFactorToZoomLevel(double factor) const { |
| 6169 | return ZoomFactorToZoomLevel(factor); |
| 6170 | } |
| 6171 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6172 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
| 6173 | const WebString& base_url, |
| 6174 | const WebString& url, |
| 6175 | const WebString& title) { |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 6176 | bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6177 | GURL base(base_url); |
| 6178 | GURL absolute_url = base.Resolve(UTF16ToUTF8(url)); |
| 6179 | if (base.GetOrigin() != absolute_url.GetOrigin()) { |
| 6180 | return; |
| 6181 | } |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 6182 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
| 6183 | UTF16ToUTF8(scheme), |
| 6184 | absolute_url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 6185 | title, |
| 6186 | user_gesture)); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6187 | } |
| 6188 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6189 | WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6190 | WebKit::WebPageVisibilityState current_state = is_hidden() ? |
| 6191 | WebKit::WebPageVisibilityStateHidden : |
| 6192 | WebKit::WebPageVisibilityStateVisible; |
| 6193 | WebKit::WebPageVisibilityState override_state = current_state; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6194 | if (GetContentClient()->renderer()-> |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6195 | ShouldOverridePageVisibilityState(this, |
| 6196 | &override_state)) |
| 6197 | return override_state; |
| 6198 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 6199 | } |
| 6200 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6201 | WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 6202 | // This can happen in tests, in which case it's OK to return NULL. |
| 6203 | if (!InitializeMediaStreamClient()) |
| 6204 | return NULL; |
| 6205 | |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 6206 | return web_user_media_client_; |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6207 | } |
| 6208 | |
[email protected] | 7b77f6cb | 2013-07-25 16:23:14 | [diff] [blame] | 6209 | WebKit::WebMIDIClient* RenderViewImpl::webMIDIClient() { |
| 6210 | if (!midi_dispatcher_) |
| 6211 | midi_dispatcher_ = new MIDIDispatcher(this); |
| 6212 | return midi_dispatcher_; |
| 6213 | } |
| 6214 | |
[email protected] | a0629af9 | 2012-08-08 00:39:37 | [diff] [blame] | 6215 | void RenderViewImpl::draggableRegionsChanged() { |
| 6216 | FOR_EACH_OBSERVER( |
| 6217 | RenderViewObserver, |
| 6218 | observers_, |
| 6219 | DraggableRegionsChanged(webview()->mainFrame())); |
| 6220 | } |
| 6221 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6222 | #if defined(OS_ANDROID) |
| 6223 | WebContentDetectionResult RenderViewImpl::detectContentAround( |
| 6224 | const WebHitTestResult& touch_hit) { |
| 6225 | DCHECK(!touch_hit.isNull()); |
| 6226 | DCHECK(!touch_hit.node().isNull()); |
| 6227 | DCHECK(touch_hit.node().isTextNode()); |
| 6228 | |
| 6229 | // Process the position with all the registered content detectors until |
| 6230 | // a match is found. Priority is provided by their relative order. |
| 6231 | for (ContentDetectorList::const_iterator it = content_detectors_.begin(); |
| 6232 | it != content_detectors_.end(); ++it) { |
| 6233 | ContentDetector::Result content = (*it)->FindTappedContent(touch_hit); |
| 6234 | if (content.valid) { |
| 6235 | return WebContentDetectionResult(content.content_boundaries, |
| 6236 | UTF8ToUTF16(content.text), content.intent_url); |
| 6237 | } |
| 6238 | } |
| 6239 | return WebContentDetectionResult(); |
| 6240 | } |
| 6241 | |
| 6242 | void RenderViewImpl::scheduleContentIntent(const WebURL& intent) { |
| 6243 | // Introduce a short delay so that the user can notice the content. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 6244 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6245 | FROM_HERE, |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 6246 | base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, |
| 6247 | AsWeakPtr(), |
| 6248 | intent, |
| 6249 | expected_content_intent_id_), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6250 | base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); |
| 6251 | } |
| 6252 | |
| 6253 | void RenderViewImpl::cancelScheduledContentIntents() { |
| 6254 | ++expected_content_intent_id_; |
| 6255 | } |
| 6256 | |
| 6257 | void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, |
| 6258 | size_t request_id) { |
| 6259 | if (request_id != expected_content_intent_id_) |
| 6260 | return; |
| 6261 | |
| 6262 | // Remove the content highlighting if any. |
| 6263 | scheduleComposite(); |
| 6264 | |
| 6265 | if (!intent.is_empty()) |
| 6266 | Send(new ViewHostMsg_StartContentIntent(routing_id_, intent)); |
| 6267 | } |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 6268 | |
| 6269 | bool RenderViewImpl::openDateTimeChooser( |
| 6270 | const WebKit::WebDateTimeChooserParams& params, |
| 6271 | WebKit::WebDateTimeChooserCompletion* completion) { |
| 6272 | date_time_picker_client_.reset( |
| 6273 | new RendererDateTimePicker(this, params, completion)); |
| 6274 | return date_time_picker_client_->Open(); |
| 6275 | } |
| 6276 | |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6277 | #endif // defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6278 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6279 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6280 | void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) { |
[email protected] | 68dc3ba | 2010-12-06 21:43:15 | [diff] [blame] | 6281 | if (external_popup_menu_ == NULL) { |
| 6282 | // Crash reports from the field indicate that we can be notified with a |
| 6283 | // NULL external popup menu (we probably get notified twice). |
| 6284 | // If you hit this please file a bug against jcivelli and include the page |
| 6285 | // and steps to repro. |
| 6286 | NOTREACHED(); |
| 6287 | return; |
| 6288 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6289 | external_popup_menu_->DidSelectItem(selected_index); |
| 6290 | external_popup_menu_.reset(); |
| 6291 | } |
| 6292 | #endif |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 6293 | |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6294 | #if defined(OS_ANDROID) |
| 6295 | void RenderViewImpl::OnSelectPopupMenuItems( |
| 6296 | bool canceled, |
| 6297 | const std::vector<int>& selected_indices) { |
| 6298 | // It is possible to receive more than one of these calls if the user presses |
| 6299 | // a select faster than it takes for the show-select-popup IPC message to make |
| 6300 | // it to the browser UI thread. Ignore the extra-messages. |
| 6301 | // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 6302 | if (!external_popup_menu_) |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6303 | return; |
| 6304 | |
| 6305 | external_popup_menu_->DidSelectItems(canceled, selected_indices); |
| 6306 | external_popup_menu_.reset(); |
| 6307 | } |
| 6308 | #endif |
| 6309 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6310 | void RenderViewImpl::OnContextMenuClosed( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6311 | const CustomContextMenuContext& custom_context) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6312 | if (custom_context.request_id) { |
| 6313 | // External request, should be in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6314 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6315 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 6316 | if (client) { |
| 6317 | client->OnMenuClosed(custom_context.request_id); |
| 6318 | pending_context_menus_.Remove(custom_context.request_id); |
| 6319 | } |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6320 | } else { |
| 6321 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 6322 | context_menu_node_.reset(); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6323 | } |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 6324 | } |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6325 | |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 6326 | void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 6327 | context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU; |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 6328 | touch_editing_context_menu_location_ = location; |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 6329 | if (webview()) |
| 6330 | webview()->showContextMenu(); |
| 6331 | } |
| 6332 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6333 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6334 | if (!webview()) |
| 6335 | return; |
| 6336 | WebFrame* main_frame = webview()->mainFrame(); |
| 6337 | if (!main_frame) |
| 6338 | return; |
| 6339 | main_frame->enableViewSourceMode(true); |
| 6340 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 6341 | |
[email protected] | c7654a23 | 2013-06-12 21:04:44 | [diff] [blame] | 6342 | #if defined(OS_ANDROID) |
[email protected] | 64d0e19 | 2011-12-09 14:44:20 | [diff] [blame] | 6343 | void RenderViewImpl::OnJavaBridgeInit() { |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6344 | DCHECK(!java_bridge_dispatcher_); |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6345 | java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 6346 | } |
[email protected] | da81627 | 2013-05-15 21:31:17 | [diff] [blame] | 6347 | #endif |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 6348 | |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 6349 | void RenderViewImpl::OnDisownOpener() { |
| 6350 | if (!webview()) |
| 6351 | return; |
| 6352 | |
| 6353 | WebFrame* main_frame = webview()->mainFrame(); |
| 6354 | if (main_frame && main_frame->opener()) |
| 6355 | main_frame->setOpener(NULL); |
| 6356 | } |
| 6357 | |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6358 | #if defined(OS_ANDROID) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6359 | bool RenderViewImpl::didTapMultipleTargets( |
| 6360 | const WebKit::WebGestureEvent& event, |
| 6361 | const WebVector<WebRect>& target_rects) { |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 6362 | // Never show a disambiguation popup when accessibility is enabled, |
| 6363 | // as this interferes with "touch exploration". |
| 6364 | if (accessibility_mode_ == AccessibilityModeComplete) |
| 6365 | return false; |
| 6366 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6367 | gfx::Rect finger_rect( |
| 6368 | event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2, |
| 6369 | event.data.tap.width, event.data.tap.height); |
| 6370 | gfx::Rect zoom_rect; |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6371 | float new_total_scale = |
| 6372 | DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( |
| 6373 | finger_rect, target_rects, GetSize(), |
| 6374 | gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(), |
| 6375 | device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect); |
| 6376 | if (!new_total_scale) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6377 | return false; |
| 6378 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 6379 | bool handled = false; |
| 6380 | switch (renderer_preferences_.tap_multiple_targets_strategy) { |
| 6381 | case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM: |
| 6382 | handled = webview()->zoomToMultipleTargetsRect(zoom_rect); |
| 6383 | break; |
| 6384 | case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: { |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 6385 | gfx::Size canvas_size = |
| 6386 | gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale)); |
| 6387 | TransportDIB* transport_dib = NULL; |
| 6388 | { |
| 6389 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 6390 | RenderProcess::current()->GetDrawingCanvas(&transport_dib, |
| 6391 | gfx::Rect(canvas_size))); |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 6392 | if (!canvas) { |
| 6393 | handled = false; |
| 6394 | break; |
| 6395 | } |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6396 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 6397 | // TODO(trchen): Cleanup the device scale factor mess. |
| 6398 | // device scale will be applied in WebKit |
| 6399 | // --> zoom_rect doesn't include device scale, |
| 6400 | // but WebKit will still draw on zoom_rect * device_scale_factor_ |
| 6401 | canvas->scale(new_total_scale / device_scale_factor_, |
| 6402 | new_total_scale / device_scale_factor_); |
| 6403 | canvas->translate(-zoom_rect.x() * device_scale_factor_, |
| 6404 | -zoom_rect.y() * device_scale_factor_); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6405 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 6406 | webwidget_->paint( |
| 6407 | canvas.get(), |
| 6408 | zoom_rect, |
| 6409 | WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent); |
| 6410 | } |
| 6411 | |
| 6412 | gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect( |
| 6413 | ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect))); |
| 6414 | Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_, |
| 6415 | physical_window_zoom_rect, |
| 6416 | canvas_size, |
| 6417 | transport_dib->id())); |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 6418 | handled = true; |
| 6419 | break; |
| 6420 | } |
| 6421 | case TAP_MULTIPLE_TARGETS_STRATEGY_NONE: |
| 6422 | // No-op. |
| 6423 | break; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6424 | } |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6425 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 6426 | return handled; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6427 | } |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6428 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6429 | |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 6430 | unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const { |
| 6431 | return history_list_length_; |
| 6432 | } |
| 6433 | |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 6434 | void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) { |
| 6435 | if (enable) { |
| 6436 | if (has_focus()) |
| 6437 | return; |
| 6438 | OnSetActive(true); |
| 6439 | OnSetFocus(true); |
| 6440 | } else { |
| 6441 | if (!has_focus()) |
| 6442 | return; |
| 6443 | OnSetFocus(false); |
| 6444 | OnSetActive(false); |
| 6445 | } |
| 6446 | } |
| 6447 | |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 6448 | void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) { |
[email protected] | b54fe45 | 2013-06-07 14:01:53 | [diff] [blame] | 6449 | ViewMsg_Resize_Params params; |
| 6450 | params.screen_info = screen_info_; |
| 6451 | params.screen_info.deviceScaleFactor = factor; |
| 6452 | params.new_size = size(); |
| 6453 | params.physical_backing_size = |
| 6454 | gfx::ToCeiledSize(gfx::ScaleSize(size(), factor)); |
| 6455 | params.overdraw_bottom_height = 0.f; |
| 6456 | params.resizer_rect = WebRect(); |
| 6457 | params.is_fullscreen = is_fullscreen(); |
| 6458 | OnResize(params); |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 6459 | } |
| 6460 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 6461 | void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size, |
| 6462 | const gfx::Size& max_size) { |
| 6463 | OnEnableAutoResize(min_size, max_size); |
| 6464 | } |
| 6465 | |
| 6466 | void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) { |
| 6467 | OnDisableAutoResize(new_size); |
| 6468 | } |
| 6469 | |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 6470 | void RenderViewImpl::SetMediaStreamClientForTesting( |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 6471 | MediaStreamClient* media_stream_client) { |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 6472 | DCHECK(!media_stream_client_); |
| 6473 | DCHECK(!web_user_media_client_); |
| 6474 | media_stream_client_ = media_stream_client; |
| 6475 | } |
| 6476 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6477 | void RenderViewImpl::OnReleaseDisambiguationPopupDIB( |
| 6478 | TransportDIB::Handle dib_handle) { |
| 6479 | TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
| 6480 | RenderProcess::current()->ReleaseTransportDIB(dib); |
| 6481 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6482 | |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 6483 | void RenderViewImpl::DidCommitCompositorFrame() { |
| 6484 | RenderWidget::DidCommitCompositorFrame(); |
| 6485 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame()); |
| 6486 | } |
| 6487 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 6488 | void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) { |
| 6489 | if (!urls.empty()) |
| 6490 | Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls)); |
| 6491 | } |
| 6492 | |
| 6493 | void RenderViewImpl::DidStopLoadingIcons() { |
| 6494 | int icon_types = WebIconURL::TypeFavicon; |
| 6495 | if (TouchEnabled()) |
| 6496 | icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
| 6497 | |
| 6498 | WebVector<WebIconURL> icon_urls = |
| 6499 | webview()->mainFrame()->iconURLs(icon_types); |
| 6500 | |
| 6501 | std::vector<FaviconURL> urls; |
| 6502 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 6503 | WebURL url = icon_urls[i].iconURL(); |
| 6504 | if (!url.isEmpty()) |
| 6505 | urls.push_back(FaviconURL(url, |
| 6506 | ToFaviconType(icon_urls[i].iconType()))); |
| 6507 | } |
| 6508 | SendUpdateFaviconURL(urls); |
| 6509 | } |
| 6510 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6511 | } // namespace content |