[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] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 18 | #include "base/i18n/rtl.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] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 26 | #include "base/process/process.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 27 | #include "base/strings/string_number_conversions.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 28 | #include "base/strings/string_piece.h" |
[email protected] | 27c0573 | 2013-02-15 21:55:49 | [diff] [blame] | 29 | #include "base/strings/string_split.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 30 | #include "base/strings/string_util.h" |
[email protected] | 40d11e0 | 2013-03-28 17:43:14 | [diff] [blame] | 31 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 32 | #include "base/strings/utf_string_conversions.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 33 | #include "base/time/time.h" |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 34 | #include "cc/base/switches.h" |
[email protected] | a8cb3b73b | 2013-08-12 05:50:50 | [diff] [blame] | 35 | #include "content/child/appcache/appcache_dispatcher.h" |
| 36 | #include "content/child/appcache/web_application_cache_host_impl.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 37 | #include "content/child/child_thread.h" |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 38 | #include "content/child/npapi/webplugin_delegate_impl.h" |
[email protected] | 541b7b0 | 2013-06-07 00:59:34 | [diff] [blame] | 39 | #include "content/child/request_extra_data.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 40 | #include "content/child/webmessageportchannel_impl.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 41 | #include "content/common/database_messages.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 42 | #include "content/common/dom_storage/dom_storage_types.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 43 | #include "content/common/drag_messages.h" |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 44 | #include "content/common/frame_messages.h" |
[email protected] | c26ad88 | 2012-02-07 06:41:20 | [diff] [blame] | 45 | #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 46 | #include "content/common/input_messages.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 47 | #include "content/common/pepper_messages.h" |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 48 | #include "content/common/socket_stream_handle_data.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 49 | #include "content/common/ssl_status_serialization.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 50 | #include "content/common/view_messages.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 51 | #include "content/public/common/bindings_policy.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 52 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 53 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 54 | #include "content/public/common/content_switches.h" |
[email protected] | 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] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 64 | #include "content/public/renderer/document_state.h" |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 65 | #include "content/public/renderer/history_item_serialization.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 66 | #include "content/public/renderer/navigation_state.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 67 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 68 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 69 | #include "content/public/renderer/web_preferences.h" |
[email protected] | 4e4646a5 | 2013-02-08 07:23:41 | [diff] [blame] | 70 | #include "content/renderer/accessibility/renderer_accessibility.h" |
| 71 | #include "content/renderer/accessibility/renderer_accessibility_complete.h" |
| 72 | #include "content/renderer/accessibility/renderer_accessibility_focus_only.h" |
[email protected] | e6e5675 | 2012-08-10 00:46:06 | [diff] [blame] | 73 | #include "content/renderer/browser_plugin/browser_plugin.h" |
| 74 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 75 | #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 76 | #include "content/renderer/devtools/devtools_agent.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 77 | #include "content/renderer/disambiguation_popup_helper.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 78 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 79 | #include "content/renderer/drop_data_builder.h" |
[email protected] | 5572215 | 2011-03-22 01:33:53 | [diff] [blame] | 80 | #include "content/renderer/external_popup_menu.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 81 | #include "content/renderer/geolocation_dispatcher.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 82 | #include "content/renderer/gpu/render_widget_compositor.h" |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 83 | #include "content/renderer/idle_user_detector.h" |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 84 | #include "content/renderer/ime_event_guard.h" |
[email protected] | 7a72d45 | 2013-12-13 10:01:13 | [diff] [blame] | 85 | #include "content/renderer/input/input_handler_manager.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 86 | #include "content/renderer/input_tag_speech_dispatcher.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 87 | #include "content/renderer/internal_document_state_data.h" |
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 88 | #include "content/renderer/load_progress_tracker.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 89 | #include "content/renderer/media/audio_device_factory.h" |
| 90 | #include "content/renderer/media/audio_renderer_mixer_manager.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 91 | #include "content/renderer/media/media_stream_dependency_factory.h" |
| 92 | #include "content/renderer/media/media_stream_dispatcher.h" |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 93 | #include "content/renderer/media/media_stream_impl.h" |
[email protected] | 7b77f6cb | 2013-07-25 16:23:14 | [diff] [blame] | 94 | #include "content/renderer/media/midi_dispatcher.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 95 | #include "content/renderer/media/render_media_log.h" |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 96 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 97 | #include "content/renderer/media/webmediaplayer_impl.h" |
| 98 | #include "content/renderer/media/webmediaplayer_ms.h" |
| 99 | #include "content/renderer/media/webmediaplayer_params.h" |
[email protected] | 3fad220d | 2014-01-23 11:30:06 | [diff] [blame] | 100 | #include "content/renderer/memory_benchmarking_extension.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 101 | #include "content/renderer/mhtml_generator.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 102 | #include "content/renderer/notification_provider.h" |
[email protected] | e1c17416 | 2014-04-08 15:39:31 | [diff] [blame] | 103 | #include "content/renderer/push_messaging_dispatcher.h" |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 104 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 105 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 106 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 107 | #include "content/renderer/render_view_impl_params.h" |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 108 | #include "content/renderer/render_view_mouse_lock_dispatcher.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 109 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 110 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 111 | #include "content/renderer/renderer_webcolorchooser_impl.h" |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 112 | #include "content/renderer/resizing_mode_selector.h" |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 113 | #include "content/renderer/savable_resources.h" |
[email protected] | cdb6b1e | 2014-01-23 00:06:49 | [diff] [blame] | 114 | #include "content/renderer/skia_benchmarking_extension.h" |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 115 | #include "content/renderer/speech_recognition_dispatcher.h" |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 116 | #include "content/renderer/stats_collection_controller.h" |
| 117 | #include "content/renderer/stats_collection_observer.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 118 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 119 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 120 | #include "content/renderer/web_ui_extension.h" |
| 121 | #include "content/renderer/web_ui_extension_data.h" |
[email protected] | 1c142a5 | 2014-04-05 20:14:17 | [diff] [blame] | 122 | #include "content/renderer/web_ui_mojo.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 123 | #include "content/renderer/websharedworker_proxy.h" |
[email protected] | f596114 | 2013-04-17 23:09:42 | [diff] [blame] | 124 | #include "media/audio/audio_output_device.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 125 | #include "media/base/audio_renderer_mixer_input.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 126 | #include "media/base/filter_collection.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 127 | #include "media/base/media_switches.h" |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 128 | #include "media/filters/audio_renderer_impl.h" |
[email protected] | 1cad880 | 2013-08-13 16:54:32 | [diff] [blame] | 129 | #include "media/filters/gpu_video_accelerator_factories.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 130 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | #include "net/base/escape.h" |
| 132 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 133 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 134 | #include "net/http/http_util.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 135 | #include "third_party/WebKit/public/platform/WebCString.h" |
| 136 | #include "third_party/WebKit/public/platform/WebDragData.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 137 | #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 138 | #include "third_party/WebKit/public/platform/WebImage.h" |
| 139 | #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 140 | #include "third_party/WebKit/public/platform/WebPoint.h" |
| 141 | #include "third_party/WebKit/public/platform/WebRect.h" |
| 142 | #include "third_party/WebKit/public/platform/WebSize.h" |
| 143 | #include "third_party/WebKit/public/platform/WebSocketStreamHandle.h" |
[email protected] | ec173b52 | 2013-11-14 11:01:18 | [diff] [blame] | 144 | #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 145 | #include "third_party/WebKit/public/platform/WebString.h" |
| 146 | #include "third_party/WebKit/public/platform/WebURL.h" |
| 147 | #include "third_party/WebKit/public/platform/WebURLError.h" |
| 148 | #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 149 | #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 150 | #include "third_party/WebKit/public/platform/WebVector.h" |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 151 | #include "third_party/WebKit/public/web/WebAXObject.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 152 | #include "third_party/WebKit/public/web/WebColorName.h" |
[email protected] | 8bc5ff0 | 2013-11-29 06:34:03 | [diff] [blame] | 153 | #include "third_party/WebKit/public/web/WebColorSuggestion.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 154 | #include "third_party/WebKit/public/web/WebDOMEvent.h" |
| 155 | #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" |
| 156 | #include "third_party/WebKit/public/web/WebDataSource.h" |
| 157 | #include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h" |
| 158 | #include "third_party/WebKit/public/web/WebDateTimeChooserParams.h" |
| 159 | #include "third_party/WebKit/public/web/WebDevToolsAgent.h" |
| 160 | #include "third_party/WebKit/public/web/WebDocument.h" |
| 161 | #include "third_party/WebKit/public/web/WebElement.h" |
| 162 | #include "third_party/WebKit/public/web/WebFileChooserParams.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 163 | #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 164 | #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 165 | #include "third_party/WebKit/public/web/WebFormElement.h" |
| 166 | #include "third_party/WebKit/public/web/WebFrame.h" |
[email protected] | 6bd867b | 2013-07-24 22:10:20 | [diff] [blame] | 167 | #include "third_party/WebKit/public/web/WebGlyphCache.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 168 | #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 169 | #include "third_party/WebKit/public/web/WebInputElement.h" |
| 170 | #include "third_party/WebKit/public/web/WebInputEvent.h" |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 171 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 172 | #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" |
| 173 | #include "third_party/WebKit/public/web/WebNavigationPolicy.h" |
| 174 | #include "third_party/WebKit/public/web/WebNodeList.h" |
| 175 | #include "third_party/WebKit/public/web/WebPageSerializer.h" |
| 176 | #include "third_party/WebKit/public/web/WebPlugin.h" |
| 177 | #include "third_party/WebKit/public/web/WebPluginAction.h" |
| 178 | #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 179 | #include "third_party/WebKit/public/web/WebPluginDocument.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 180 | #include "third_party/WebKit/public/web/WebRange.h" |
| 181 | #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 182 | #include "third_party/WebKit/public/web/WebSearchableFormData.h" |
| 183 | #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 184 | #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 185 | #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
| 186 | #include "third_party/WebKit/public/web/WebSettings.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 187 | #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 188 | #include "third_party/WebKit/public/web/WebUserMediaClient.h" |
| 189 | #include "third_party/WebKit/public/web/WebView.h" |
| 190 | #include "third_party/WebKit/public/web/WebWindowFeatures.h" |
| 191 | #include "third_party/WebKit/public/web/default/WebRenderTheme.h" |
[email protected] | 4ee6462 | 2014-03-21 22:34:15 | [diff] [blame] | 192 | #include "ui/base/clipboard/clipboard.h" |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 193 | #include "ui/base/ui_base_switches_util.h" |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 194 | #include "ui/events/latency_info.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 195 | #include "ui/gfx/native_widget_types.h" |
| 196 | #include "ui/gfx/point.h" |
| 197 | #include "ui/gfx/rect.h" |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 198 | #include "ui/gfx/rect_conversions.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 199 | #include "ui/gfx/size_conversions.h" |
[email protected] | 4344a3c | 2013-01-17 23:49:20 | [diff] [blame] | 200 | #include "ui/shell_dialogs/selected_file_info.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 201 | #include "v8/include/v8.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 202 | #include "webkit/child/weburlresponse_extradata_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 203 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 204 | #if defined(OS_ANDROID) |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 205 | #include <cpu-features.h> |
| 206 | |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 207 | #include "content/common/android/device_telephony_info.h" |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 208 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 209 | #include "content/renderer/android/address_detector.h" |
| 210 | #include "content/renderer/android/content_detector.h" |
| 211 | #include "content/renderer/android/email_detector.h" |
| 212 | #include "content/renderer/android/phone_number_detector.h" |
[email protected] | 3a59bb9 | 2013-08-22 18:54:08 | [diff] [blame] | 213 | #include "content/renderer/android/synchronous_compositor_factory.h" |
[email protected] | bc42744 | 2013-07-13 02:53:08 | [diff] [blame] | 214 | #include "content/renderer/media/android/renderer_media_player_manager.h" |
[email protected] | 2bd4e771 | 2014-04-03 00:14:37 | [diff] [blame] | 215 | #include "content/renderer/media/android/stream_texture_factory_impl.h" |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 216 | #include "content/renderer/media/android/webmediaplayer_android.h" |
[email protected] | c277d3c | 2013-07-15 21:49:37 | [diff] [blame] | 217 | #include "skia/ext/platform_canvas.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 218 | #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 219 | #include "third_party/WebKit/public/platform/WebFloatRect.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 220 | #include "third_party/WebKit/public/web/WebHitTestResult.h" |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 221 | #include "ui/gfx/rect_f.h" |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 222 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 223 | #elif defined(OS_WIN) |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 224 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 225 | // * theming |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 226 | #include "ui/native_theme/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 227 | #elif defined(USE_X11) |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 228 | #include "ui/native_theme/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 229 | #elif defined(OS_MACOSX) |
| 230 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 231 | #endif |
| 232 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 233 | #if defined(ENABLE_PLUGINS) |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 234 | #include "content/renderer/npapi/webplugin_delegate_proxy.h" |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 235 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 236 | #include "content/renderer/pepper/pepper_plugin_registry.h" |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 237 | #endif |
| 238 | |
[email protected] | 9ac667e | 2013-09-09 12:49:21 | [diff] [blame] | 239 | #if defined(ENABLE_WEBRTC) |
| 240 | #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 241 | #endif |
| 242 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 243 | using blink::WebAXObject; |
| 244 | using blink::WebApplicationCacheHost; |
| 245 | using blink::WebApplicationCacheHostClient; |
| 246 | using blink::WebCString; |
| 247 | using blink::WebColor; |
| 248 | using blink::WebColorName; |
| 249 | using blink::WebConsoleMessage; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 250 | using blink::WebData; |
| 251 | using blink::WebDataSource; |
| 252 | using blink::WebDocument; |
| 253 | using blink::WebDOMEvent; |
| 254 | using blink::WebDOMMessageEvent; |
| 255 | using blink::WebDragData; |
| 256 | using blink::WebDragOperation; |
| 257 | using blink::WebDragOperationsMask; |
| 258 | using blink::WebElement; |
| 259 | using blink::WebExternalPopupMenu; |
| 260 | using blink::WebExternalPopupMenuClient; |
| 261 | using blink::WebFileChooserCompletion; |
| 262 | using blink::WebFindOptions; |
| 263 | using blink::WebFormControlElement; |
| 264 | using blink::WebFormElement; |
| 265 | using blink::WebFrame; |
| 266 | using blink::WebGestureEvent; |
| 267 | using blink::WebHistoryItem; |
| 268 | using blink::WebHTTPBody; |
| 269 | using blink::WebIconURL; |
| 270 | using blink::WebImage; |
| 271 | using blink::WebInputElement; |
| 272 | using blink::WebInputEvent; |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 273 | using blink::WebLocalFrame; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 274 | using blink::WebMediaPlayer; |
| 275 | using blink::WebMediaPlayerAction; |
| 276 | using blink::WebMediaPlayerClient; |
| 277 | using blink::WebMouseEvent; |
| 278 | using blink::WebNavigationPolicy; |
| 279 | using blink::WebNavigationType; |
| 280 | using blink::WebNode; |
| 281 | using blink::WebPageSerializer; |
| 282 | using blink::WebPageSerializerClient; |
| 283 | using blink::WebPeerConnection00Handler; |
| 284 | using blink::WebPeerConnection00HandlerClient; |
| 285 | using blink::WebPeerConnectionHandler; |
| 286 | using blink::WebPeerConnectionHandlerClient; |
| 287 | using blink::WebPluginAction; |
| 288 | using blink::WebPluginContainer; |
| 289 | using blink::WebPluginDocument; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 290 | using blink::WebPoint; |
| 291 | using blink::WebPopupMenuInfo; |
| 292 | using blink::WebRange; |
| 293 | using blink::WebRect; |
| 294 | using blink::WebReferrerPolicy; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 295 | using blink::WebScriptSource; |
| 296 | using blink::WebSearchableFormData; |
| 297 | using blink::WebSecurityOrigin; |
| 298 | using blink::WebSecurityPolicy; |
| 299 | using blink::WebSerializedScriptValue; |
| 300 | using blink::WebSettings; |
| 301 | using blink::WebSize; |
| 302 | using blink::WebSocketStreamHandle; |
| 303 | using blink::WebStorageNamespace; |
| 304 | using blink::WebStorageQuotaCallbacks; |
| 305 | using blink::WebStorageQuotaError; |
| 306 | using blink::WebStorageQuotaType; |
| 307 | using blink::WebString; |
| 308 | using blink::WebTextAffinity; |
| 309 | using blink::WebTextDirection; |
| 310 | using blink::WebTouchEvent; |
| 311 | using blink::WebURL; |
| 312 | using blink::WebURLError; |
| 313 | using blink::WebURLRequest; |
| 314 | using blink::WebURLResponse; |
| 315 | using blink::WebUserGestureIndicator; |
| 316 | using blink::WebVector; |
| 317 | using blink::WebView; |
| 318 | using blink::WebWidget; |
| 319 | using blink::WebWindowFeatures; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 320 | using base::Time; |
| 321 | using base::TimeDelta; |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 322 | using webkit_glue::WebURLResponseExtraDataImpl; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 323 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 324 | #if defined(OS_ANDROID) |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 325 | using blink::WebContentDetectionResult; |
| 326 | using blink::WebFloatPoint; |
| 327 | using blink::WebFloatRect; |
| 328 | using blink::WebHitTestResult; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 329 | #endif |
| 330 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 331 | namespace content { |
| 332 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 333 | //----------------------------------------------------------------------------- |
| 334 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 335 | typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 336 | static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 337 | typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap; |
| 338 | static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map = |
| 339 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 340 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 341 | // Time, in seconds, we delay before sending content state changes (such as form |
| 342 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 343 | // spamming the browser. |
| 344 | // To avoid having tab/session restore require sending a message to get the |
| 345 | // current content state during tab closing we use a shorter timeout for the |
| 346 | // foreground renderer. This means there is a small window of time from which |
| 347 | // content state is modified and not sent to session restore, but this is |
| 348 | // better than having to wake up all renderers during shutdown. |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 349 | const int kDelaySecondsForContentStateSyncHidden = 5; |
| 350 | const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 351 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 352 | #if defined(OS_ANDROID) |
| 353 | // Delay between tapping in content and launching the associated android intent. |
| 354 | // Used to allow users see what has been recognized as content. |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 355 | const size_t kContentIntentDelayMilliseconds = 700; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 356 | #endif |
| 357 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 358 | static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = |
| 359 | NULL; |
| 360 | |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 361 | // static |
| 362 | bool RenderViewImpl::IsReload(const FrameMsg_Navigate_Params& params) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 363 | return |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 364 | params.navigation_type == FrameMsg_Navigate_Type::RELOAD || |
| 365 | params.navigation_type == FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE || |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 366 | params.navigation_type == |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 367 | FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 368 | } |
| 369 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 370 | // static |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 371 | Referrer RenderViewImpl::GetReferrerFromRequest( |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 372 | WebFrame* frame, |
| 373 | const WebURLRequest& request) { |
| 374 | return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
[email protected] | cacbd7a | 2014-02-04 01:26:02 | [diff] [blame] | 375 | request.referrerPolicy()); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 376 | } |
| 377 | |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 378 | // static |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 379 | WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition( |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 380 | WebNavigationPolicy policy) { |
| 381 | switch (policy) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 382 | case blink::WebNavigationPolicyIgnore: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 383 | return IGNORE_ACTION; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 384 | case blink::WebNavigationPolicyDownload: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 385 | return SAVE_TO_DISK; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 386 | case blink::WebNavigationPolicyCurrentTab: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 387 | return CURRENT_TAB; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 388 | case blink::WebNavigationPolicyNewBackgroundTab: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 389 | return NEW_BACKGROUND_TAB; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 390 | case blink::WebNavigationPolicyNewForegroundTab: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 391 | return NEW_FOREGROUND_TAB; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 392 | case blink::WebNavigationPolicyNewWindow: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 393 | return NEW_WINDOW; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 394 | case blink::WebNavigationPolicyNewPopup: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 395 | return NEW_POPUP; |
| 396 | default: |
| 397 | NOTREACHED() << "Unexpected WebNavigationPolicy"; |
| 398 | return IGNORE_ACTION; |
| 399 | } |
| 400 | } |
| 401 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 402 | // Returns true if the device scale is high enough that losing subpixel |
| 403 | // antialiasing won't have a noticeable effect on text quality. |
| 404 | static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) { |
| 405 | #if defined(OS_ANDROID) |
| 406 | // On Android, we never have subpixel antialiasing. |
| 407 | return true; |
| 408 | #else |
| 409 | return device_scale_factor > 1.5f; |
| 410 | #endif |
| 411 | |
| 412 | } |
| 413 | |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 414 | static bool ShouldUseFixedPositionCompositing(float device_scale_factor) { |
| 415 | // Compositing for fixed-position elements is dependent on |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 416 | // device_scale_factor if no flag is set. http://crbug.com/172738 |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 417 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 418 | |
| 419 | if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition)) |
| 420 | return false; |
| 421 | |
| 422 | if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition)) |
| 423 | return true; |
| 424 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 425 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 426 | } |
| 427 | |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 428 | static bool ShouldUseAcceleratedCompositingForOverflowScroll( |
| 429 | float device_scale_factor) { |
| 430 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 431 | |
[email protected] | 7d20c7c | 2013-10-15 13:55:46 | [diff] [blame] | 432 | if (command_line.HasSwitch(switches::kDisableAcceleratedOverflowScroll)) |
| 433 | return false; |
| 434 | |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 435 | if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll)) |
| 436 | return true; |
| 437 | |
| 438 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 439 | } |
| 440 | |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 441 | static bool ShouldUseAcceleratedCompositingForScrollableFrames( |
| 442 | float device_scale_factor) { |
[email protected] | a23530d | 2014-03-11 06:04:14 | [diff] [blame] | 443 | if (RenderThreadImpl::current() && |
| 444 | !RenderThreadImpl::current()->is_lcd_text_enabled()) |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 445 | return true; |
| 446 | |
| 447 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 448 | } |
| 449 | |
| 450 | static bool ShouldUseCompositedScrollingForFrames( |
| 451 | float device_scale_factor) { |
[email protected] | a23530d | 2014-03-11 06:04:14 | [diff] [blame] | 452 | if (RenderThreadImpl::current() && |
| 453 | !RenderThreadImpl::current()->is_lcd_text_enabled()) |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 454 | return true; |
| 455 | |
| 456 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 457 | } |
| 458 | |
[email protected] | f388a5d | 2013-11-04 20:19:13 | [diff] [blame] | 459 | static bool ShouldUseUniversalAcceleratedCompositingForOverflowScroll() { |
[email protected] | 44de749 | 2013-10-18 15:14:59 | [diff] [blame] | 460 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 461 | |
| 462 | if (command_line.HasSwitch( |
| 463 | switches::kDisableUniversalAcceleratedOverflowScroll)) |
| 464 | return false; |
| 465 | |
| 466 | if (command_line.HasSwitch( |
| 467 | switches::kEnableUniversalAcceleratedOverflowScroll)) |
| 468 | return true; |
| 469 | |
[email protected] | f388a5d | 2013-11-04 20:19:13 | [diff] [blame] | 470 | return false; |
[email protected] | 44de749 | 2013-10-18 15:14:59 | [diff] [blame] | 471 | } |
| 472 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 473 | static bool ShouldUseTransitionCompositing(float device_scale_factor) { |
| 474 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 475 | |
| 476 | if (command_line.HasSwitch(switches::kDisableCompositingForTransition)) |
| 477 | return false; |
| 478 | |
| 479 | if (command_line.HasSwitch(switches::kEnableCompositingForTransition)) |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 480 | return true; |
| 481 | |
[email protected] | 9a7f6e1 | 2013-06-11 07:05:13 | [diff] [blame] | 482 | // TODO(ajuma): Re-enable this by default for high-DPI once the problem |
| 483 | // of excessive layer promotion caused by overlap has been addressed. |
| 484 | // http://crbug.com/178119. |
| 485 | return false; |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 486 | } |
| 487 | |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 488 | static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) { |
| 489 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 490 | |
| 491 | if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground)) |
| 492 | return false; |
| 493 | |
| 494 | if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground)) |
| 495 | return true; |
| 496 | |
| 497 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 498 | } |
| 499 | |
[email protected] | 41d0493 | 2014-03-13 15:05:45 | [diff] [blame] | 500 | static bool ShouldUseCompositingForGpuRasterizationHint() { |
| 501 | return RenderThreadImpl::current() && |
| 502 | RenderThreadImpl::current()->is_gpu_rasterization_enabled(); |
| 503 | } |
| 504 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 505 | static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) { |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 506 | switch (type) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 507 | case blink::WebIconURL::TypeFavicon: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 508 | return FaviconURL::FAVICON; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 509 | case blink::WebIconURL::TypeTouch: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 510 | return FaviconURL::TOUCH_ICON; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 511 | case blink::WebIconURL::TypeTouchPrecomposed: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 512 | return FaviconURL::TOUCH_PRECOMPOSED_ICON; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 513 | case blink::WebIconURL::TypeInvalid: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 514 | return FaviconURL::INVALID_ICON; |
| 515 | } |
| 516 | return FaviconURL::INVALID_ICON; |
| 517 | } |
| 518 | |
[email protected] | f34ac13 | 2014-03-20 23:02:05 | [diff] [blame] | 519 | static void ConvertToFaviconSizes( |
| 520 | const blink::WebVector<blink::WebSize>& web_sizes, |
| 521 | std::vector<gfx::Size>* sizes) { |
| 522 | for (size_t i = 0; i < web_sizes.size(); ++i) |
| 523 | sizes->push_back(gfx::Size(web_sizes[i])); |
| 524 | } |
| 525 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 526 | /////////////////////////////////////////////////////////////////////////////// |
| 527 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 528 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 529 | PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c) |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 530 | : params(p), |
| 531 | completion(c) { |
| 532 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 533 | FileChooserParams params; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 534 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 535 | }; |
| 536 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 537 | namespace { |
| 538 | |
| 539 | class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { |
| 540 | public: |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 541 | explicit WebWidgetLockTarget(blink::WebWidget* webwidget) |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 542 | : webwidget_(webwidget) {} |
| 543 | |
| 544 | virtual void OnLockMouseACK(bool succeeded) OVERRIDE { |
| 545 | if (succeeded) |
| 546 | webwidget_->didAcquirePointerLock(); |
| 547 | else |
| 548 | webwidget_->didNotAcquirePointerLock(); |
| 549 | } |
| 550 | |
| 551 | virtual void OnMouseLockLost() OVERRIDE { |
| 552 | webwidget_->didLosePointerLock(); |
| 553 | } |
| 554 | |
| 555 | virtual bool HandleMouseLockedInputEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 556 | const blink::WebMouseEvent &event) OVERRIDE { |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 557 | // The WebWidget handles mouse lock in WebKit's handleInputEvent(). |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | private: |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 562 | blink::WebWidget* webwidget_; |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 563 | }; |
| 564 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 565 | bool TouchEnabled() { |
| 566 | // Based on the definition of chrome::kEnableTouchIcon. |
| 567 | #if defined(OS_ANDROID) |
| 568 | return true; |
| 569 | #else |
| 570 | return false; |
| 571 | #endif |
| 572 | } |
| 573 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 574 | WebDragData DropDataToWebDragData(const DropData& drop_data) { |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 575 | std::vector<WebDragData::Item> item_list; |
| 576 | |
| 577 | // These fields are currently unused when dragging into WebKit. |
| 578 | DCHECK(drop_data.download_metadata.empty()); |
| 579 | DCHECK(drop_data.file_contents.empty()); |
| 580 | DCHECK(drop_data.file_description_filename.empty()); |
| 581 | |
| 582 | if (!drop_data.text.is_null()) { |
| 583 | WebDragData::Item item; |
| 584 | item.storageType = WebDragData::Item::StorageTypeString; |
| 585 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| 586 | item.stringData = drop_data.text.string(); |
| 587 | item_list.push_back(item); |
| 588 | } |
| 589 | |
| 590 | // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it |
| 591 | // meaningful to write an empty URL to the clipboard? |
| 592 | if (!drop_data.url.is_empty()) { |
| 593 | WebDragData::Item item; |
| 594 | item.storageType = WebDragData::Item::StorageTypeString; |
| 595 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 596 | item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
| 597 | item.title = drop_data.url_title; |
| 598 | item_list.push_back(item); |
| 599 | } |
| 600 | |
| 601 | if (!drop_data.html.is_null()) { |
| 602 | WebDragData::Item item; |
| 603 | item.storageType = WebDragData::Item::StorageTypeString; |
| 604 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 605 | item.stringData = drop_data.html.string(); |
| 606 | item.baseURL = drop_data.html_base_url; |
| 607 | item_list.push_back(item); |
| 608 | } |
| 609 | |
[email protected] | 17ea0ae2 | 2014-03-28 21:54:46 | [diff] [blame] | 610 | for (std::vector<ui::FileInfo>::const_iterator it = |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 611 | drop_data.filenames.begin(); |
| 612 | it != drop_data.filenames.end(); |
| 613 | ++it) { |
| 614 | WebDragData::Item item; |
| 615 | item.storageType = WebDragData::Item::StorageTypeFilename; |
[email protected] | 17ea0ae2 | 2014-03-28 21:54:46 | [diff] [blame] | 616 | item.filenameData = it->path.AsUTF16Unsafe(); |
| 617 | item.displayNameData = it->display_name.AsUTF16Unsafe(); |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 618 | item_list.push_back(item); |
| 619 | } |
| 620 | |
| 621 | for (std::map<base::string16, base::string16>::const_iterator it = |
| 622 | drop_data.custom_data.begin(); |
| 623 | it != drop_data.custom_data.end(); |
| 624 | ++it) { |
| 625 | WebDragData::Item item; |
| 626 | item.storageType = WebDragData::Item::StorageTypeString; |
| 627 | item.stringType = it->first; |
| 628 | item.stringData = it->second; |
| 629 | item_list.push_back(item); |
| 630 | } |
| 631 | |
| 632 | WebDragData result; |
| 633 | result.initialize(); |
| 634 | result.setItems(item_list); |
| 635 | result.setFilesystemId(drop_data.filesystem_id); |
| 636 | return result; |
| 637 | } |
| 638 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 639 | } // namespace |
| 640 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 641 | RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 642 | : RenderWidget(blink::WebPopupTypeNone, |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 643 | params->screen_info, |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 644 | params->swapped_out, |
| 645 | params->hidden), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 646 | webkit_preferences_(params->webkit_prefs), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 647 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 648 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 649 | send_preferred_size_changes_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 650 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 651 | opened_by_user_gesture_(true), |
| 652 | opener_suppressed_(false), |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 653 | suppress_dialogs_until_swap_out_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 654 | page_id_(-1), |
| 655 | last_page_id_sent_to_browser_(-1), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 656 | next_page_id_(params->next_page_id), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 657 | history_list_offset_(-1), |
| 658 | history_list_length_(0), |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 659 | frames_in_progress_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 660 | target_url_status_(TARGET_NONE), |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 661 | #if defined(OS_ANDROID) |
| 662 | top_controls_constraints_(cc::BOTH), |
| 663 | #endif |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 664 | cached_is_main_frame_pinned_to_left_(false), |
| 665 | cached_is_main_frame_pinned_to_right_(false), |
| 666 | cached_has_main_frame_horizontal_scrollbar_(false), |
| 667 | cached_has_main_frame_vertical_scrollbar_(false), |
[email protected] | 1875bc0 | 2014-03-14 06:33:59 | [diff] [blame] | 668 | has_scrolled_focused_editable_node_into_rect_(false), |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 669 | notification_provider_(NULL), |
[email protected] | e1c17416 | 2014-04-08 15:39:31 | [diff] [blame] | 670 | push_messaging_dispatcher_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 671 | geolocation_dispatcher_(NULL), |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 672 | input_tag_speech_dispatcher_(NULL), |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 673 | speech_recognition_dispatcher_(NULL), |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 674 | media_stream_dispatcher_(NULL), |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 675 | browser_plugin_manager_(NULL), |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 676 | media_stream_client_(NULL), |
| 677 | web_user_media_client_(NULL), |
[email protected] | f39b9d5 | 2013-07-28 08:03:44 | [diff] [blame] | 678 | midi_dispatcher_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 679 | devtools_agent_(NULL), |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 680 | accessibility_mode_(AccessibilityModeOff), |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 681 | renderer_accessibility_(NULL), |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 682 | mouse_lock_dispatcher_(NULL), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 683 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 684 | body_background_color_(SK_ColorWHITE), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 685 | expected_content_intent_id_(0), |
[email protected] | 305ecfc7 | 2013-10-31 00:35:48 | [diff] [blame] | 686 | media_player_manager_(NULL), |
[email protected] | a756427 | 2013-04-19 14:24:46 | [diff] [blame] | 687 | #endif |
| 688 | #if defined(OS_WIN) |
| 689 | focused_plugin_id_(-1), |
| 690 | #endif |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 691 | #if defined(ENABLE_PLUGINS) |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 692 | plugin_find_handler_(NULL), |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 693 | focused_pepper_plugin_(NULL), |
| 694 | pepper_last_mouse_event_target_(NULL), |
| 695 | #endif |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 696 | enumeration_completion_id_(0), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 697 | load_progress_tracker_(new LoadProgressTracker(this)), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 698 | session_storage_namespace_id_(params->session_storage_namespace_id), |
[email protected] | f2c530d | 2014-02-20 20:15:30 | [diff] [blame] | 699 | next_snapshot_id_(0) { |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 700 | } |
| 701 | |
[email protected] | 0287e76 | 2014-04-11 13:07:58 | [diff] [blame^] | 702 | void RenderViewImpl::Initialize( |
| 703 | RenderViewImplParams* params, |
| 704 | RenderFrameImpl* main_render_frame) { |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 705 | routing_id_ = params->routing_id; |
| 706 | surface_id_ = params->surface_id; |
| 707 | if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created) |
| 708 | opener_id_ = params->opener_id; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 709 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 710 | // Ensure we start with a valid next_page_id_ from the browser. |
| 711 | DCHECK_GE(next_page_id_, 0); |
| 712 | |
[email protected] | 21b3a6ae | 2011-11-30 00:45:29 | [diff] [blame] | 713 | #if defined(ENABLE_NOTIFICATIONS) |
| 714 | notification_provider_ = new NotificationProvider(this); |
| 715 | #else |
| 716 | notification_provider_ = NULL; |
| 717 | #endif |
| 718 | |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 719 | webwidget_ = WebView::create(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 720 | webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 721 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 722 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 723 | |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 724 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 725 | stats_collection_observer_.reset(new StatsCollectionObserver(this)); |
| 726 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 727 | #if defined(OS_ANDROID) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 728 | content::DeviceTelephonyInfo device_info; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 729 | |
| 730 | const std::string region_code = |
| 731 | command_line.HasSwitch(switches::kNetworkCountryIso) |
| 732 | ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 733 | : device_info.GetNetworkCountryIso(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 734 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 735 | new AddressDetector())); |
| 736 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 737 | new PhoneNumberDetector(region_code))); |
| 738 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 739 | new EmailDetector())); |
| 740 | #endif |
| 741 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 742 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 743 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 744 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 745 | AddRef(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 746 | if (RenderThreadImpl::current()) { |
| 747 | RenderThreadImpl::current()->WidgetCreated(); |
| 748 | if (is_hidden_) |
| 749 | RenderThreadImpl::current()->WidgetHidden(); |
| 750 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 751 | |
| 752 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 753 | // completing initialization. Otherwise, we can finish it now. |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 754 | if (opener_id_ == MSG_ROUTING_NONE) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 755 | did_show_ = true; |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 756 | CompleteInit(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 757 | } |
| 758 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 759 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 760 | g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this)); |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 761 | webview()->setDeviceScaleFactor(device_scale_factor_); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 762 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 763 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 764 | webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled( |
| 765 | ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_)); |
[email protected] | 44de749 | 2013-10-18 15:14:59 | [diff] [blame] | 766 | webview()->settings()->setCompositorDrivenAcceleratedScrollingEnabled( |
[email protected] | f388a5d | 2013-11-04 20:19:13 | [diff] [blame] | 767 | ShouldUseUniversalAcceleratedCompositingForOverflowScroll()); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 768 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 769 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 770 | webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled( |
| 771 | ShouldUseAcceleratedFixedRootBackground(device_scale_factor_)); |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 772 | webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled( |
| 773 | ShouldUseAcceleratedCompositingForScrollableFrames(device_scale_factor_)); |
| 774 | webview()->settings()->setCompositedScrollingForFramesEnabled( |
| 775 | ShouldUseCompositedScrollingForFrames(device_scale_factor_)); |
[email protected] | 41d0493 | 2014-03-13 15:05:45 | [diff] [blame] | 776 | webview()->settings() |
| 777 | ->setAcceleratedCompositingForGpuRasterizationHintEnabled( |
| 778 | ShouldUseCompositingForGpuRasterizationHint()); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 779 | |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 780 | ApplyWebPreferences(webkit_preferences_, webview()); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 781 | |
[email protected] | 0287e76 | 2014-04-11 13:07:58 | [diff] [blame^] | 782 | main_render_frame_.reset(main_render_frame); |
| 783 | webview()->setMainFrame(main_render_frame_->GetWebFrame()); |
| 784 | main_render_frame_->Initialize(); |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 785 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 786 | if (switches::IsTouchDragDropEnabled()) |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 787 | webview()->settings()->setTouchDragDropEnabled(true); |
| 788 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 789 | if (switches::IsTouchEditingEnabled()) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 790 | webview()->settings()->setTouchEditingEnabled(true); |
| 791 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 792 | if (!params->frame_name.empty()) |
| 793 | webview()->mainFrame()->setName(params->frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 794 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 795 | OnSetRendererPrefs(params->renderer_prefs); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 796 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 797 | #if defined(ENABLE_WEBRTC) |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 798 | if (!media_stream_dispatcher_) |
| 799 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 800 | #endif |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 801 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 802 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 803 | #if defined(OS_MACOSX) |
| 804 | new TextInputClientObserver(this); |
| 805 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 806 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 807 | #if defined(OS_ANDROID) |
[email protected] | 305ecfc7 | 2013-10-31 00:35:48 | [diff] [blame] | 808 | media_player_manager_ = new RendererMediaPlayerManager(this); |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 809 | #endif |
| 810 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 811 | // The next group of objects all implement RenderViewObserver, so are deleted |
| 812 | // along with the RenderView automatically. |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 813 | devtools_agent_ = new DevToolsAgent(this); |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 814 | if (RenderWidgetCompositor* rwc = compositor()) { |
| 815 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 816 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 817 | mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 818 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 819 | // Create renderer_accessibility_ if needed. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 820 | OnSetAccessibilityMode(params->accessibility_mode); |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 821 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 822 | new IdleUserDetector(this); |
| 823 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 824 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 825 | enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION; |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 826 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 827 | enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION; |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 828 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 829 | ProcessViewLayoutFlags(command_line); |
[email protected] | 7ddea980 | 2012-02-22 23:08:05 | [diff] [blame] | 830 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 831 | GetContentClient()->renderer()->RenderViewCreated(this); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 832 | |
| 833 | // If we have an opener_id but we weren't created by a renderer, then |
| 834 | // it's the browser asking us to set our opener to another RenderView. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 835 | if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) { |
| 836 | RenderViewImpl* opener_view = FromRoutingID(params->opener_id); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 837 | if (opener_view) |
| 838 | webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | // If we are initially swapped out, navigate to kSwappedOutURL. |
| 842 | // This ensures we are in a unique origin that others cannot script. |
| 843 | if (is_swapped_out_) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 844 | NavigateToSwappedOutURL(webview()->mainFrame()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 845 | } |
| 846 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 847 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 848 | history_page_ids_.clear(); |
| 849 | |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 850 | base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_); |
| 851 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 852 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 853 | while (!file_chooser_completions_.empty()) { |
| 854 | if (file_chooser_completions_.front()->completion) { |
| 855 | file_chooser_completions_.front()->completion->didChooseFile( |
| 856 | WebVector<WebString>()); |
| 857 | } |
| 858 | file_chooser_completions_.pop_front(); |
| 859 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 860 | |
[email protected] | 8ed1d3f | 2013-02-20 11:45:55 | [diff] [blame] | 861 | #if defined(OS_ANDROID) |
| 862 | // The date/time picker client is both a scoped_ptr member of this class and |
| 863 | // a RenderViewObserver. Reset it to prevent double deletion. |
| 864 | date_time_picker_client_.reset(); |
| 865 | #endif |
| 866 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 867 | #ifndef NDEBUG |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 868 | // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 869 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 870 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 871 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 872 | RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 873 | for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 874 | it != routing_id_views->end(); ++it) |
| 875 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 876 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 877 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 878 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 879 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 883 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 884 | ViewMap* views = g_view_map.Pointer(); |
| 885 | ViewMap::iterator it = views->find(webview); |
| 886 | return it == views->end() ? NULL : it->second; |
| 887 | } |
| 888 | |
| 889 | /*static*/ |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 890 | RenderView* RenderView::FromWebView(blink::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 891 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | /*static*/ |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 895 | RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) { |
| 896 | RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
| 897 | RoutingIDViewMap::iterator it = views->find(routing_id); |
| 898 | return it == views->end() ? NULL : it->second; |
| 899 | } |
| 900 | |
| 901 | /*static*/ |
| 902 | RenderView* RenderView::FromRoutingID(int routing_id) { |
| 903 | return RenderViewImpl::FromRoutingID(routing_id); |
| 904 | } |
| 905 | |
| 906 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 907 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 908 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 909 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 910 | if (!visitor->Visit(it->second)) |
| 911 | return; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 916 | RenderViewImpl* RenderViewImpl::Create( |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 917 | int32 opener_id, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 918 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 919 | const WebPreferences& webkit_prefs, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 920 | int32 routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 921 | int32 main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 922 | int32 surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 923 | int64 session_storage_namespace_id, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 924 | const base::string16& frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 925 | bool is_renderer_created, |
| 926 | bool swapped_out, |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 927 | bool hidden, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 928 | int32 next_page_id, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 929 | const blink::WebScreenInfo& screen_info, |
[email protected] | bfa7124 | 2014-03-27 21:10:24 | [diff] [blame] | 930 | AccessibilityMode accessibility_mode) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 931 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | f2c530d | 2014-02-20 20:15:30 | [diff] [blame] | 932 | RenderViewImplParams params(opener_id, |
| 933 | renderer_prefs, |
| 934 | webkit_prefs, |
| 935 | routing_id, |
| 936 | main_frame_routing_id, |
| 937 | surface_id, |
| 938 | session_storage_namespace_id, |
| 939 | frame_name, |
| 940 | is_renderer_created, |
| 941 | swapped_out, |
| 942 | hidden, |
| 943 | next_page_id, |
| 944 | screen_info, |
| 945 | accessibility_mode); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 946 | RenderViewImpl* render_view = NULL; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 947 | if (g_create_render_view_impl) |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 948 | render_view = g_create_render_view_impl(¶ms); |
| 949 | else |
| 950 | render_view = new RenderViewImpl(¶ms); |
[email protected] | 0287e76 | 2014-04-11 13:07:58 | [diff] [blame^] | 951 | |
| 952 | RenderFrameImpl* main_frame = RenderFrameImpl::Create( |
| 953 | render_view, main_frame_routing_id); |
| 954 | // The main frame WebLocalFrame object is closed by |
| 955 | // RenderFrameImpl::frameDetached(). |
| 956 | WebLocalFrame* web_frame = WebLocalFrame::create(main_frame); |
| 957 | main_frame->SetWebFrame(web_frame); |
| 958 | |
| 959 | render_view->Initialize(¶ms, main_frame); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 960 | return render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | // static |
| 964 | void RenderViewImpl::InstallCreateHook( |
| 965 | RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) { |
| 966 | CHECK(!g_create_render_view_impl); |
| 967 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 968 | } |
| 969 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 970 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 971 | observers_.AddObserver(observer); |
| 972 | } |
| 973 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 974 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 975 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 976 | observers_.RemoveObserver(observer); |
| 977 | } |
| 978 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 979 | blink::WebView* RenderViewImpl::webview() const { |
| 980 | return static_cast<blink::WebView*>(webwidget()); |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 981 | } |
| 982 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 983 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 984 | void RenderViewImpl::PepperInstanceCreated( |
| 985 | PepperPluginInstanceImpl* instance) { |
| 986 | active_pepper_instances_.insert(instance); |
| 987 | } |
| 988 | |
| 989 | void RenderViewImpl::PepperInstanceDeleted( |
| 990 | PepperPluginInstanceImpl* instance) { |
| 991 | active_pepper_instances_.erase(instance); |
| 992 | |
| 993 | if (pepper_last_mouse_event_target_ == instance) |
| 994 | pepper_last_mouse_event_target_ = NULL; |
| 995 | if (focused_pepper_plugin_ == instance) |
| 996 | PepperFocusChanged(instance, false); |
| 997 | } |
| 998 | |
| 999 | void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance, |
| 1000 | bool focused) { |
| 1001 | if (focused) |
| 1002 | focused_pepper_plugin_ = instance; |
| 1003 | else if (focused_pepper_plugin_ == instance) |
| 1004 | focused_pepper_plugin_ = NULL; |
| 1005 | |
| 1006 | UpdateTextInputType(); |
| 1007 | UpdateSelectionBounds(); |
| 1008 | } |
| 1009 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1010 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1011 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1012 | // If the renderer is visible, set initial visibility and focus state. |
| 1013 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1014 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1015 | delegate->SetContainerVisibility(true); |
| 1016 | if (webview() && webview()->isActive()) |
| 1017 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1018 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1019 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1020 | // Plugins start assuming the content has focus (so that they work in |
| 1021 | // environments where RenderView isn't hosting them), so we always have to |
| 1022 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 1023 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1024 | } |
| 1025 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1026 | void RenderViewImpl::UnregisterPluginDelegate( |
| 1027 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1028 | plugin_delegates_.erase(delegate); |
| 1029 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1030 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 1031 | #if defined(OS_WIN) |
| 1032 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1033 | if (focused) |
| 1034 | focused_plugin_id_ = plugin_id; |
| 1035 | else |
| 1036 | focused_plugin_id_ = -1; |
| 1037 | } |
| 1038 | #endif |
| 1039 | |
| 1040 | #if defined(OS_MACOSX) |
| 1041 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1042 | Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); |
| 1043 | } |
| 1044 | |
| 1045 | void RenderViewImpl::StartPluginIme() { |
| 1046 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
| 1047 | // This message can be sent during event-handling, and needs to be delivered |
| 1048 | // within that context. |
| 1049 | msg->set_unblock(true); |
| 1050 | Send(msg); |
| 1051 | } |
| 1052 | #endif // defined(OS_MACOSX) |
| 1053 | |
| 1054 | #endif // ENABLE_PLUGINS |
| 1055 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 1056 | void RenderViewImpl::TransferActiveWheelFlingAnimation( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1057 | const blink::WebActiveWheelFlingParameters& params) { |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 1058 | if (webview()) |
| 1059 | webview()->transferActiveWheelFlingAnimation(params); |
| 1060 | } |
| 1061 | |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 1062 | bool RenderViewImpl::HasIMETextFocus() { |
| 1063 | return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
| 1064 | } |
| 1065 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1066 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1067 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 1068 | if (main_frame) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1069 | GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1070 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1071 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 1072 | RenderViewObserver* observer; |
| 1073 | while ((observer = it.GetNext()) != NULL) |
| 1074 | if (observer->OnMessageReceived(message)) |
| 1075 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1076 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1077 | bool handled = true; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1078 | bool msg_is_ok = true; |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1079 | IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1080 | IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand) |
| 1081 | IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1082 | IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect, |
| 1083 | OnScrollFocusedEditableNodeIntoRect) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1084 | IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent, |
| 1085 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 1086 | IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1087 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1088 | IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1089 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
| 1090 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 1091 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 1092 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1093 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1094 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 1095 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1096 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1097 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 1098 | OnResetPageEncodingToDefault) |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 1099 | IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1100 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 1101 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 1102 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 1103 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
[email protected] | 7a6d773f | 2014-04-04 01:25:09 | [diff] [blame] | 1104 | IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1105 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 1106 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 1107 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1108 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1109 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 1110 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1111 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 1112 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1113 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 1114 | IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut, |
| 1115 | OnSuppressDialogsUntilSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1116 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 1117 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1118 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | ab6c911 | 2014-02-27 00:20:58 | [diff] [blame] | 1119 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement, OnClearFocusedElement) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1120 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 1121 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 1122 | OnEnablePreferredSizeChangedMode) |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1123 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1124 | IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 1125 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 1126 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1127 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 1128 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 1129 | IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent, |
| 1130 | OnOrientationChangeEvent) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1131 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 1132 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 1133 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 1134 | OnGetAllSavableResourceLinksForCurrentPage) |
| 1135 | IPC_MESSAGE_HANDLER( |
| 1136 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 1137 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 1138 | IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 1139 | // TODO(viettrungluu): Move to a separate message filter. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1140 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 1141 | OnSetHistoryLengthAndPrune) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 1142 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1143 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 1144 | IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener) |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 1145 | IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB, |
| 1146 | OnReleaseDisambiguationPopupDIB) |
| 1147 | IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, |
| 1148 | OnWindowSnapshotCompleted) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1149 | #if defined(OS_ANDROID) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1150 | IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult, |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1151 | OnActivateNearestFindResult) |
| 1152 | IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects) |
| 1153 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
[email protected] | 452b4a9 | 2013-03-28 21:24:38 | [diff] [blame] | 1154 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState, |
| 1155 | OnUpdateTopControlsState) |
[email protected] | 68877c28 | 2013-09-20 05:52:42 | [diff] [blame] | 1156 | IPC_MESSAGE_HANDLER(ViewMsg_PauseVideo, OnPauseVideo) |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 1157 | IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData, OnExtractSmartClipData) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1158 | #elif defined(OS_MACOSX) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1159 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 1160 | OnPluginImeCompositionCompleted) |
| 1161 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 1162 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1163 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| 1164 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| 1165 | #endif |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 1166 | // Adding a new message? Add platform independent ones first, then put the |
| 1167 | // platform specific ones at the end. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1168 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1169 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1170 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1171 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1172 | |
| 1173 | if (!msg_is_ok) { |
| 1174 | // The message had a handler, but its deserialization failed. |
| 1175 | // Kill the renderer to avoid potential spoofing attacks. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1176 | CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1177 | } |
| 1178 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1179 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1180 | } |
| 1181 | |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 1182 | void RenderViewImpl::OnNavigate(const FrameMsg_Navigate_Params& params) { |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 1183 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1184 | } |
| 1185 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1186 | bool RenderViewImpl::IsBackForwardToStaleEntry( |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 1187 | const FrameMsg_Navigate_Params& params, |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1188 | bool is_reload) { |
| 1189 | // Make sure this isn't a back/forward to an entry we have already cropped |
| 1190 | // or replaced from our history, before the browser knew about it. If so, |
| 1191 | // 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] | 1192 | bool is_back_forward = !is_reload && params.page_state.IsValid(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1193 | |
| 1194 | // Note: if the history_list_length_ is 0 for a back/forward, we must be |
| 1195 | // restoring from a previous session. We'll update our state in OnNavigate. |
| 1196 | if (!is_back_forward || history_list_length_ <= 0) |
| 1197 | return false; |
| 1198 | |
| 1199 | DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_); |
| 1200 | |
| 1201 | // Check for whether the forward history has been cropped due to a recent |
| 1202 | // navigation the browser didn't know about. |
| 1203 | if (params.pending_history_list_offset >= history_list_length_) |
| 1204 | return true; |
| 1205 | |
| 1206 | // Check for whether this entry has been replaced with a new one. |
| 1207 | int expected_page_id = |
| 1208 | history_page_ids_[params.pending_history_list_offset]; |
[email protected] | 9978b8f0 | 2011-08-13 16:17:44 | [diff] [blame] | 1209 | if (expected_page_id > 0 && params.page_id != expected_page_id) { |
| 1210 | if (params.page_id < expected_page_id) |
| 1211 | return true; |
| 1212 | |
| 1213 | // Otherwise we've removed an earlier entry and should have shifted all |
| 1214 | // entries left. For now, it's ok to lazily update the list. |
| 1215 | // TODO(creis): Notify all live renderers when we remove entries from |
| 1216 | // the front of the list, so that we don't hit this case. |
| 1217 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
| 1218 | } |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1219 | |
| 1220 | return false; |
| 1221 | } |
| 1222 | |
[email protected] | 3d612f5 | 2014-01-13 23:48:29 | [diff] [blame] | 1223 | // Stop loading the current page. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1224 | void RenderViewImpl::OnStop() { |
[email protected] | 3d612f5 | 2014-01-13 23:48:29 | [diff] [blame] | 1225 | if (webview()) |
| 1226 | webview()->mainFrame()->stopLoading(); |
| 1227 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnStop()); |
[email protected] | 5815cf5 | 2014-01-29 17:45:05 | [diff] [blame] | 1228 | main_render_frame_->OnStop(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1229 | } |
| 1230 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1231 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1232 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1233 | } |
| 1234 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1235 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1236 | // Check if there is a targeturl waiting to be sent. |
| 1237 | if (target_url_status_ == TARGET_PENDING) { |
| 1238 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1239 | pending_target_url_)); |
| 1240 | } |
| 1241 | |
| 1242 | target_url_status_ = TARGET_NONE; |
| 1243 | } |
| 1244 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1245 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
| 1246 | const std::string& value) { |
| 1247 | if (!webview() || !webview()->focusedFrame()) |
| 1248 | return; |
| 1249 | |
| 1250 | webview()->focusedFrame()->executeCommand( |
| 1251 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
| 1252 | } |
| 1253 | |
| 1254 | void RenderViewImpl::OnMoveCaret(const gfx::Point& point) { |
| 1255 | if (!webview()) |
| 1256 | return; |
| 1257 | |
| 1258 | Send(new ViewHostMsg_MoveCaret_ACK(routing_id_)); |
| 1259 | |
[email protected] | b74d4064d | 2013-11-27 01:45:09 | [diff] [blame] | 1260 | webview()->focusedFrame()->moveCaretSelection(point); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1261 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1262 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1263 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1264 | const gfx::Rect& rect) { |
[email protected] | 1875bc0 | 2014-03-14 06:33:59 | [diff] [blame] | 1265 | if (has_scrolled_focused_editable_node_into_rect_ && |
| 1266 | rect == rect_for_scrolled_focused_editable_node_) { |
| 1267 | return; |
| 1268 | } |
| 1269 | |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 1270 | blink::WebElement element = GetFocusedElement(); |
[email protected] | 1875bc0 | 2014-03-14 06:33:59 | [diff] [blame] | 1271 | if (!element.isNull() && IsEditableNode(element)) { |
| 1272 | rect_for_scrolled_focused_editable_node_ = rect; |
| 1273 | has_scrolled_focused_editable_node_into_rect_ = true; |
| 1274 | webview()->scrollFocusedNodeIntoRect(rect); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1275 | } |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1276 | } |
| 1277 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1278 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
| 1279 | const EditCommands& edit_commands) { |
| 1280 | edit_commands_ = edit_commands; |
| 1281 | } |
| 1282 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1283 | void RenderViewImpl::OnSetName(const std::string& name) { |
| 1284 | if (!webview()) |
| 1285 | return; |
| 1286 | |
| 1287 | webview()->mainFrame()->setName(WebString::fromUTF8(name)); |
| 1288 | } |
| 1289 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1290 | void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length, |
| 1291 | int32 minimum_page_id) { |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1292 | DCHECK_GE(history_length, 0); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1293 | DCHECK(history_list_offset_ == history_list_length_ - 1); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1294 | DCHECK_GE(minimum_page_id, -1); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1295 | |
| 1296 | // Generate the new list. |
| 1297 | std::vector<int32> new_history_page_ids(history_length, -1); |
| 1298 | for (size_t i = 0; i < history_page_ids_.size(); ++i) { |
| 1299 | if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id) |
| 1300 | continue; |
| 1301 | new_history_page_ids.push_back(history_page_ids_[i]); |
| 1302 | } |
| 1303 | new_history_page_ids.swap(history_page_ids_); |
| 1304 | |
| 1305 | // Update indexes. |
| 1306 | history_list_length_ = history_page_ids_.size(); |
| 1307 | history_list_offset_ = history_list_length_ - 1; |
| 1308 | } |
| 1309 | |
| 1310 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1311 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1312 | if (!webview()) |
| 1313 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1314 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1315 | } |
| 1316 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1317 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1318 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1319 | if (!webview()) |
| 1320 | return; |
| 1321 | if (in_live_resize) |
| 1322 | webview()->willStartLiveResize(); |
| 1323 | else |
| 1324 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1325 | } |
| 1326 | #endif |
| 1327 | |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1328 | #if defined(OS_ANDROID) |
[email protected] | 68877c28 | 2013-09-20 05:52:42 | [diff] [blame] | 1329 | void RenderViewImpl::OnPauseVideo() { |
| 1330 | // Inform RendererMediaPlayerManager to release all video player resources. |
| 1331 | // If something is in progress the resource will not be freed, it will |
| 1332 | // only be freed once the tab is destroyed or if the user navigates away |
| 1333 | // via WebMediaPlayerAndroid::Destroy. |
| 1334 | media_player_manager_->ReleaseVideoResources(); |
| 1335 | } |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1336 | #endif |
| 1337 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1338 | /////////////////////////////////////////////////////////////////////////////// |
| 1339 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1340 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1341 | void RenderViewImpl::UpdateTitle(WebFrame* frame, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1342 | const base::string16& title, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1343 | WebTextDirection title_direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1344 | // Ignore all but top level navigations. |
| 1345 | if (frame->parent()) |
| 1346 | return; |
| 1347 | |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 1348 | base::debug::TraceLog::GetInstance()->UpdateProcessLabel( |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 1349 | routing_id_, base::UTF16ToUTF8(title)); |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 1350 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1351 | base::string16 shortened_title = title.substr(0, kMaxTitleChars); |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1352 | Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title, |
| 1353 | title_direction)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1354 | } |
| 1355 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1356 | void RenderViewImpl::UpdateEncoding(WebFrame* frame, |
| 1357 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1358 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1359 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1360 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1361 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1362 | last_encoding_name_ = encoding_name; |
| 1363 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1364 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 1368 | // Sends the last committed session history state to the browser so it will be |
| 1369 | // saved before we navigate to a new page. This must be called *before* the |
| 1370 | // page ID has been updated so we know what it was. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1371 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1372 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1373 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1374 | // there is no past session history to record. |
| 1375 | if (page_id_ == -1) |
| 1376 | return; |
| 1377 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1378 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1379 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 1380 | SendUpdateState(item); |
| 1381 | } |
| 1382 | |
| 1383 | void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1384 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1385 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1386 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1387 | // Don't send state updates for kSwappedOutURL. |
| 1388 | if (item.urlString() == WebString::fromUTF8(kSwappedOutURL)) |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 1389 | return; |
| 1390 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1391 | Send(new ViewHostMsg_UpdateState( |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1392 | routing_id_, page_id_, HistoryItemToPageState(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1393 | } |
| 1394 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1395 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1396 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1397 | void RenderViewImpl::LoadNavigationErrorPage( |
| 1398 | WebFrame* frame, |
| 1399 | const WebURLRequest& failed_request, |
| 1400 | const WebURLError& error, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1401 | bool replace) { |
[email protected] | 3d612f5 | 2014-01-13 23:48:29 | [diff] [blame] | 1402 | std::string error_html; |
| 1403 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
| 1404 | this, frame, failed_request, error, &error_html, NULL); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1405 | |
[email protected] | 3d612f5 | 2014-01-13 23:48:29 | [diff] [blame] | 1406 | frame->loadHTMLString(error_html, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1407 | GURL(kUnreachableWebDataURL), |
[email protected] | 21d61e5 | 2011-03-18 19:08:25 | [diff] [blame] | 1408 | error.unreachableURL, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1409 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1410 | } |
| 1411 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1412 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1413 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1414 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1415 | // it is particularly important that we do not call willEnterModalLoop as |
| 1416 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1417 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 1418 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1419 | |
| 1420 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1421 | return Send(message); |
| 1422 | } |
| 1423 | |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 1424 | void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) { |
| 1425 | int id = next_snapshot_id_++; |
| 1426 | pending_snapshots_.insert(std::make_pair(id, callback)); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1427 | ui::LatencyInfo latency_info; |
| 1428 | latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
[email protected] | 8a78459 | 2014-01-21 23:01:24 | [diff] [blame] | 1429 | 0, |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1430 | id); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 1431 | scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor; |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1432 | if (RenderWidgetCompositor* rwc = compositor()) { |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 1433 | latency_info_swap_promise_monitor = |
| 1434 | rwc->CreateLatencyInfoSwapPromiseMonitor(&latency_info).Pass(); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1435 | } else { |
[email protected] | 98a0447 | 2013-12-23 20:42:50 | [diff] [blame] | 1436 | latency_info_.push_back(latency_info); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1437 | } |
| 1438 | ScheduleCompositeWithForcedRedraw(); |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, |
| 1442 | const gfx::Size& size, const std::vector<unsigned char>& png) { |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1443 | |
| 1444 | // Any pending snapshots with a lower ID than the one received are considered |
| 1445 | // to be implicitly complete, and returned the same snapshot data. |
| 1446 | PendingSnapshotMap::iterator it = pending_snapshots_.begin(); |
| 1447 | while(it != pending_snapshots_.end()) { |
| 1448 | if (it->first <= snapshot_id) { |
| 1449 | it->second.Run(size, png); |
| 1450 | pending_snapshots_.erase(it++); |
| 1451 | } else { |
| 1452 | ++it; |
| 1453 | } |
| 1454 | } |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 1455 | } |
| 1456 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1457 | // blink::WebViewClient ------------------------------------------------------ |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1458 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 1459 | WebView* RenderViewImpl::createView(WebLocalFrame* creator, |
| 1460 | const WebURLRequest& request, |
| 1461 | const WebWindowFeatures& features, |
| 1462 | const WebString& frame_name, |
| 1463 | WebNavigationPolicy policy, |
| 1464 | bool suppress_opener) { |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1465 | ViewHostMsg_CreateWindow_Params params; |
| 1466 | params.opener_id = routing_id_; |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 1467 | params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame] | 1468 | if (GetContentClient()->renderer()->AllowPopup()) |
| 1469 | params.user_gesture = true; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1470 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1471 | params.session_storage_namespace_id = session_storage_namespace_id_; |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 1472 | if (frame_name != "_blank") |
| 1473 | params.frame_name = frame_name; |
[email protected] | a7531d77 | 2014-03-25 16:15:07 | [diff] [blame] | 1474 | params.opener_render_frame_id = |
[email protected] | 501052ff | 2014-02-21 22:19:07 | [diff] [blame] | 1475 | RenderFrameImpl::FromWebFrame(creator)->GetRoutingID(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1476 | params.opener_url = creator->document().url(); |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 1477 | params.opener_top_level_frame_url = creator->top()->document().url(); |
[email protected] | 6c53a7f | 2014-03-31 16:56:28 | [diff] [blame] | 1478 | GURL security_url(creator->document().securityOrigin().toString()); |
[email protected] | 7f48b71 | 2013-01-25 01:48:30 | [diff] [blame] | 1479 | if (!security_url.is_valid()) |
| 1480 | security_url = GURL(); |
| 1481 | params.opener_security_origin = security_url; |
[email protected] | 147b2bf | 2013-11-05 04:00:04 | [diff] [blame] | 1482 | params.opener_suppressed = suppress_opener; |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 1483 | params.disposition = NavigationPolicyToDisposition(policy); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 1484 | if (!request.isNull()) { |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1485 | params.target_url = request.url(); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 1486 | params.referrer = GetReferrerFromRequest(creator, request); |
| 1487 | } |
[email protected] | 453c1b2 | 2013-07-23 09:31:48 | [diff] [blame] | 1488 | params.features = features; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1489 | |
[email protected] | 22217ed3 | 2013-11-18 18:40:23 | [diff] [blame] | 1490 | for (size_t i = 0; i < features.additionalFeatures.size(); ++i) |
| 1491 | params.additional_features.push_back(features.additionalFeatures[i]); |
| 1492 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1493 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1494 | int32 main_frame_routing_id = MSG_ROUTING_NONE; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1495 | int32 surface_id = 0; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1496 | int64 cloned_session_storage_namespace_id; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1497 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1498 | RenderThread::Get()->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1499 | new ViewHostMsg_CreateWindow(params, |
| 1500 | &routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1501 | &main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1502 | &surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1503 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1504 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1505 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1506 | |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 1507 | WebUserGestureIndicator::consumeUserGesture(); |
[email protected] | c5926242 | 2012-11-30 21:20:52 | [diff] [blame] | 1508 | |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 1509 | WebPreferences transferred_preferences = webkit_preferences_; |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 1510 | |
| 1511 | // Unless accelerated compositing has been explicitly disabled from the |
| 1512 | // command line (e.g. via the blacklist or about:flags) re-enable it for |
| 1513 | // new views that get spawned by this view. This gets around the issue that |
| 1514 | // background extension pages disable accelerated compositing via web prefs |
| 1515 | // but can themselves spawn a visible render view which should be allowed |
| 1516 | // use gpu acceleration. |
| 1517 | if (!webkit_preferences_.accelerated_compositing_enabled) { |
| 1518 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1519 | if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing)) |
| 1520 | transferred_preferences.accelerated_compositing_enabled = true; |
| 1521 | } |
| 1522 | |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 1523 | // The initial hidden state for the RenderViewImpl here has to match what the |
| 1524 | // browser will eventually decide for the given disposition. Since we have to |
| 1525 | // return from this call synchronously, we just have to make our best guess |
| 1526 | // and rely on the browser sending a WasHidden / WasShown message if it |
| 1527 | // disagrees. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1528 | RenderViewImpl* view = RenderViewImpl::Create( |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1529 | routing_id_, |
| 1530 | renderer_preferences_, |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 1531 | transferred_preferences, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1532 | routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1533 | main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1534 | surface_id, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1535 | cloned_session_storage_namespace_id, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1536 | base::string16(), // WebCore will take care of setting the correct name. |
[email protected] | f2c530d | 2014-02-20 20:15:30 | [diff] [blame] | 1537 | true, // is_renderer_created |
| 1538 | false, // swapped_out |
| 1539 | params.disposition == NEW_BACKGROUND_TAB, // hidden |
| 1540 | 1, // next_page_id |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1541 | screen_info_, |
[email protected] | f2c530d | 2014-02-20 20:15:30 | [diff] [blame] | 1542 | accessibility_mode_); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1543 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1544 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1545 | // Record whether the creator frame is trying to suppress the opener field. |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 1546 | view->opener_suppressed_ = params.opener_suppressed; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1547 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1548 | return view->webview(); |
| 1549 | } |
| 1550 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1551 | WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) { |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1552 | RenderWidget* widget = |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1553 | RenderWidget::Create(routing_id_, popup_type, screen_info_); |
[email protected] | 3b78ec1 | 2014-03-04 05:18:28 | [diff] [blame] | 1554 | if (!widget) |
| 1555 | return NULL; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1556 | if (screen_metrics_emulator_) { |
| 1557 | widget->SetPopupOriginAdjustmentsForEmulation( |
| 1558 | screen_metrics_emulator_.get()); |
| 1559 | } |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1560 | return widget->webwidget(); |
| 1561 | } |
| 1562 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1563 | WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu( |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1564 | const WebPopupMenuInfo& popup_menu_info, |
| 1565 | WebExternalPopupMenuClient* popup_menu_client) { |
[email protected] | 5390786 | 2014-03-25 15:42:40 | [diff] [blame] | 1566 | #if defined(OS_MACOSX) || defined(OS_ANDROID) |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 1567 | // An IPC message is sent to the browser to build and display the actual |
| 1568 | // popup. The user could have time to click a different select by the time |
| 1569 | // the popup is shown. In that case external_popup_menu_ is non NULL. |
| 1570 | // By returning NULL in that case, we instruct WebKit to cancel that new |
| 1571 | // popup. So from the user perspective, only the first one will show, and |
| 1572 | // will have to close the first one before another one can be shown. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 1573 | if (external_popup_menu_) |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 1574 | return NULL; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1575 | external_popup_menu_.reset( |
| 1576 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1577 | if (screen_metrics_emulator_) { |
| 1578 | SetExternalPopupOriginAdjustmentsForEmulation( |
| 1579 | external_popup_menu_.get(), screen_metrics_emulator_.get()); |
| 1580 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1581 | return external_popup_menu_.get(); |
[email protected] | 5390786 | 2014-03-25 15:42:40 | [diff] [blame] | 1582 | #else |
| 1583 | return NULL; |
| 1584 | #endif |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1585 | } |
| 1586 | |
[email protected] | 2336748 | 2013-06-27 21:06:54 | [diff] [blame] | 1587 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() { |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 1588 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1589 | return new WebStorageNamespaceImpl(session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1590 | } |
| 1591 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 1592 | void RenderViewImpl::printPage(WebLocalFrame* frame) { |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 1593 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 1594 | PrintPage(frame, handling_input_event_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1595 | } |
| 1596 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1597 | blink::WebNotificationPresenter* RenderViewImpl::notificationPresenter() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1598 | return notification_provider_; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 1599 | } |
| 1600 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1601 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1602 | const WebString& path, |
| 1603 | WebFileChooserCompletion* chooser_completion) { |
| 1604 | int id = enumeration_completion_id_++; |
| 1605 | enumeration_completions_[id] = chooser_completion; |
| 1606 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 1607 | routing_id_, |
| 1608 | id, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 1609 | base::FilePath::FromUTF16Unsafe(path))); |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1610 | } |
| 1611 | |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1612 | void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) { |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 1613 | if (load_progress_tracker_ != NULL) { |
| 1614 | load_progress_tracker_->DidStartLoading( |
| 1615 | RenderFrameImpl::FromWebFrame(frame)->GetRoutingID()); |
| 1616 | } |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1617 | DCHECK_GE(frames_in_progress_, 0); |
| 1618 | if (frames_in_progress_ == 0) |
| 1619 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
| 1620 | frames_in_progress_++; |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 1621 | } |
| 1622 | |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1623 | void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) { |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 1624 | if (load_progress_tracker_ != NULL) { |
| 1625 | load_progress_tracker_->DidStopLoading( |
| 1626 | RenderFrameImpl::FromWebFrame(frame)->GetRoutingID()); |
| 1627 | } |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1628 | frames_in_progress_--; |
| 1629 | DCHECK_GE(frames_in_progress_, 0); |
| 1630 | if (frames_in_progress_ == 0) { |
| 1631 | DidStopLoadingIcons(); |
| 1632 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
| 1633 | } |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1634 | } |
| 1635 | |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1636 | void RenderViewImpl::FrameDidChangeLoadProgress(WebFrame* frame, |
| 1637 | double load_progress) { |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 1638 | if (load_progress_tracker_ != NULL) { |
| 1639 | load_progress_tracker_->DidChangeLoadProgress( |
| 1640 | RenderFrameImpl::FromWebFrame(frame)->GetRoutingID(), load_progress); |
| 1641 | } |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 1642 | } |
| 1643 | |
[email protected] | 550b0c9 | 2013-02-04 05:09:15 | [diff] [blame] | 1644 | void RenderViewImpl::didCancelCompositionOnSelectionChange() { |
| 1645 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 1646 | } |
| 1647 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1648 | void RenderViewImpl::didExecuteCommand(const WebString& command_name) { |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 1649 | const std::string& name = base::UTF16ToUTF8(command_name); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1650 | if (StartsWithASCII(name, "Move", true) || |
| 1651 | StartsWithASCII(name, "Insert", true) || |
| 1652 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1653 | return; |
[email protected] | 97880c8 | 2013-12-04 07:09:21 | [diff] [blame] | 1654 | RenderThreadImpl::current()->RecordComputedAction(name); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1655 | } |
| 1656 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1657 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1658 | if (edit_commands_.empty()) |
| 1659 | return false; |
| 1660 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1661 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1662 | if (!frame) |
| 1663 | return false; |
| 1664 | |
| 1665 | EditCommands::iterator it = edit_commands_.begin(); |
| 1666 | EditCommands::iterator end = edit_commands_.end(); |
| 1667 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1668 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1669 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 1670 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 1671 | // key (but it's the exception). Once one edit command is not executed, it |
| 1672 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1673 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 1674 | WebString::fromUTF8(it->value), |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 1675 | GetFocusedElement())) |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1676 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1677 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1678 | } |
| 1679 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1680 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1681 | } |
| 1682 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1683 | blink::WebColorChooser* RenderViewImpl::createColorChooser( |
| 1684 | blink::WebColorChooserClient* client, |
[email protected] | 8bc5ff0 | 2013-11-29 06:34:03 | [diff] [blame] | 1685 | const blink::WebColor& initial_color, |
| 1686 | const blink::WebVector<blink::WebColorSuggestion>& suggestions) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1687 | RendererWebColorChooserImpl* color_chooser = |
| 1688 | new RendererWebColorChooserImpl(this, client); |
[email protected] | 8bc5ff0 | 2013-11-29 06:34:03 | [diff] [blame] | 1689 | std::vector<content::ColorSuggestion> color_suggestions; |
| 1690 | for (size_t i = 0; i < suggestions.size(); i++) { |
| 1691 | color_suggestions.push_back(content::ColorSuggestion(suggestions[i])); |
| 1692 | } |
| 1693 | color_chooser->Open(static_cast<SkColor>(initial_color), color_suggestions); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1694 | return color_chooser; |
| 1695 | } |
| 1696 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1697 | bool RenderViewImpl::runFileChooser( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1698 | const blink::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1699 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 1700 | // Do not open the file dialog in a hidden RenderView. |
| 1701 | if (is_hidden()) |
| 1702 | return false; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1703 | FileChooserParams ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1704 | if (params.directory) |
[email protected] | 6bedbef | 2013-07-31 06:33:49 | [diff] [blame] | 1705 | ipc_params.mode = FileChooserParams::UploadFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1706 | else if (params.multiSelect) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1707 | ipc_params.mode = FileChooserParams::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame] | 1708 | else if (params.saveAs) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1709 | ipc_params.mode = FileChooserParams::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1710 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1711 | ipc_params.mode = FileChooserParams::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1712 | ipc_params.title = params.title; |
| 1713 | ipc_params.default_file_name = |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 1714 | base::FilePath::FromUTF16Unsafe(params.initialValue); |
[email protected] | f9a4c41a | 2012-05-30 00:05:32 | [diff] [blame] | 1715 | ipc_params.accept_types.reserve(params.acceptTypes.size()); |
| 1716 | for (size_t i = 0; i < params.acceptTypes.size(); ++i) |
| 1717 | ipc_params.accept_types.push_back(params.acceptTypes[i]); |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 1718 | #if defined(OS_ANDROID) |
[email protected] | b7b4beb | 2013-07-09 14:06:50 | [diff] [blame] | 1719 | ipc_params.capture = params.useMediaCapture; |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 1720 | #endif |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1721 | |
| 1722 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1723 | } |
| 1724 | |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1725 | void RenderViewImpl::showValidationMessage( |
| 1726 | const blink::WebRect& anchor_in_root_view, |
| 1727 | const blink::WebString& main_text, |
| 1728 | const blink::WebString& sub_text, |
| 1729 | blink::WebTextDirection hint) { |
| 1730 | base::string16 wrapped_main_text = main_text; |
| 1731 | base::string16 wrapped_sub_text = sub_text; |
| 1732 | if (hint == blink::WebTextDirectionLeftToRight) { |
| 1733 | wrapped_main_text = |
| 1734 | base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text); |
| 1735 | if (!wrapped_sub_text.empty()) { |
| 1736 | wrapped_sub_text = |
| 1737 | base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text); |
| 1738 | } |
| 1739 | } else if (hint == blink::WebTextDirectionRightToLeft |
| 1740 | && !base::i18n::IsRTL()) { |
| 1741 | base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text); |
| 1742 | if (!wrapped_sub_text.empty()) { |
| 1743 | base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text); |
| 1744 | } |
| 1745 | } |
| 1746 | Send(new ViewHostMsg_ShowValidationMessage( |
| 1747 | routing_id(), anchor_in_root_view, wrapped_main_text, wrapped_sub_text)); |
| 1748 | } |
| 1749 | |
| 1750 | void RenderViewImpl::hideValidationMessage() { |
| 1751 | Send(new ViewHostMsg_HideValidationMessage(routing_id())); |
| 1752 | } |
| 1753 | |
| 1754 | void RenderViewImpl::moveValidationMessage( |
| 1755 | const blink::WebRect& anchor_in_root_view) { |
| 1756 | Send(new ViewHostMsg_MoveValidationMessage(routing_id(), |
| 1757 | anchor_in_root_view)); |
| 1758 | } |
| 1759 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1760 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1761 | } |
| 1762 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1763 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 1764 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 1765 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1766 | if (latest_url == target_url_) |
| 1767 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1768 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1769 | // Tell the browser to display a destination link. |
| 1770 | if (target_url_status_ == TARGET_INFLIGHT || |
| 1771 | target_url_status_ == TARGET_PENDING) { |
| 1772 | // If we have a request in-flight, save the URL to be sent when we |
| 1773 | // receive an ACK to the in-flight request. We can happily overwrite |
| 1774 | // any existing pending sends. |
| 1775 | pending_target_url_ = latest_url; |
| 1776 | target_url_status_ = TARGET_PENDING; |
| 1777 | } else { |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 1778 | // URLs larger than |MaxURLChars()| cannot be sent through IPC - |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 1779 | // see |ParamTraits<GURL>|. |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 1780 | if (latest_url.possibly_invalid_spec().size() > GetMaxURLChars()) |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 1781 | latest_url = GURL(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1782 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 1783 | target_url_ = latest_url; |
| 1784 | target_url_status_ = TARGET_INFLIGHT; |
| 1785 | } |
| 1786 | } |
| 1787 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 1788 | gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect( |
| 1789 | const gfx::RectF& rect) const { |
| 1790 | gfx::RectF window_rect = rect; |
| 1791 | window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor()); |
| 1792 | return window_rect; |
| 1793 | } |
| 1794 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1795 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
[email protected] | a183fb8 | 2012-12-14 04:46:22 | [diff] [blame] | 1796 | // No need to update state if no page has committed yet. |
| 1797 | if (page_id_ == -1) |
| 1798 | return; |
| 1799 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1800 | int delay; |
| 1801 | if (send_content_state_immediately_) |
| 1802 | delay = 0; |
| 1803 | else if (is_hidden()) |
| 1804 | delay = kDelaySecondsForContentStateSyncHidden; |
| 1805 | else |
| 1806 | delay = kDelaySecondsForContentStateSync; |
| 1807 | |
| 1808 | if (nav_state_sync_timer_.IsRunning()) { |
| 1809 | // The timer is already running. If the delay of the timer maches the amount |
| 1810 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 1811 | // gets started with the right delay. |
| 1812 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 1813 | return; |
| 1814 | nav_state_sync_timer_.Stop(); |
| 1815 | } |
| 1816 | |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 1817 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1818 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1819 | } |
| 1820 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1821 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1822 | mouse_over_url_ = GURL(url); |
| 1823 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 1824 | } |
| 1825 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1826 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1827 | focus_url_ = GURL(url); |
| 1828 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 1829 | } |
| 1830 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 1831 | void RenderViewImpl::startDragging(WebLocalFrame* frame, |
[email protected] | 0407e42 | 2012-05-18 19:51:25 | [diff] [blame] | 1832 | const WebDragData& data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1833 | WebDragOperationsMask mask, |
| 1834 | const WebImage& image, |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 1835 | const WebPoint& webImageOffset) { |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 1836 | DropData drop_data(DropDataBuilder::Build(data)); |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 1837 | drop_data.referrer_policy = frame->document().referrerPolicy(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 1838 | gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1839 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 1840 | drop_data, |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1841 | mask, |
[email protected] | 97612707 | 2012-05-10 20:08:11 | [diff] [blame] | 1842 | image.getSkBitmap(), |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 1843 | imageOffset, |
| 1844 | possible_drag_event_info_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1845 | } |
| 1846 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1847 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 1848 | return renderer_preferences_.can_accept_load_drops; |
| 1849 | } |
| 1850 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1851 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1852 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 1853 | } |
| 1854 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1855 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1856 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 1857 | } |
| 1858 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1859 | void RenderViewImpl::focusedNodeChanged(const WebNode& node) { |
[email protected] | 1875bc0 | 2014-03-14 06:33:59 | [diff] [blame] | 1860 | has_scrolled_focused_editable_node_into_rect_ = false; |
| 1861 | |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 1862 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 1863 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 1864 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node)); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 1865 | } |
| 1866 | |
[email protected] | 572a6ca | 2012-10-11 19:38:01 | [diff] [blame] | 1867 | void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
| 1868 | Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
| 1869 | } |
| 1870 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 1871 | void RenderViewImpl::didUpdateLayout() { |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 1872 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout()); |
| 1873 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 1874 | // We don't always want to set up a timer, only if we've been put in that |
| 1875 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 1876 | // message. |
| 1877 | if (!send_preferred_size_changes_ || !webview()) |
| 1878 | return; |
| 1879 | |
| 1880 | if (check_preferred_size_timer_.IsRunning()) |
| 1881 | return; |
| 1882 | check_preferred_size_timer_.Start(FROM_HERE, |
| 1883 | TimeDelta::FromMilliseconds(0), this, |
| 1884 | &RenderViewImpl::CheckPreferredSize); |
| 1885 | } |
| 1886 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1887 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1888 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 1889 | } |
| 1890 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1891 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1892 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1893 | } |
| 1894 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1895 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1896 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1897 | } |
| 1898 | |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 1899 | void RenderViewImpl::postAccessibilityEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1900 | const WebAXObject& obj, blink::WebAXEvent event) { |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1901 | if (renderer_accessibility_) { |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 1902 | renderer_accessibility_->HandleWebAccessibilityEvent(obj, event); |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1903 | } |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 1904 | } |
| 1905 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1906 | void RenderViewImpl::didUpdateInspectorSetting(const WebString& key, |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 1907 | const WebString& value) { |
| 1908 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 1909 | key.utf8(), |
| 1910 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1911 | } |
| 1912 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1913 | // blink::WebWidgetClient ---------------------------------------------------- |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1914 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1915 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1916 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 1917 | // we won't have to test for user gesture anymore and we can |
| 1918 | // move that code back to render_widget.cc |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 1919 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 1920 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 1921 | Send(new ViewHostMsg_Focus(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1925 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1926 | // TODO(jcivelli): see TODO above in didFocus(). |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 1927 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 1928 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 1929 | Send(new ViewHostMsg_Blur(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1930 | } |
| 1931 | } |
| 1932 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1933 | // 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] | 1934 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1935 | // point to dispatch the ShowView message. |
| 1936 | // |
| 1937 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 1938 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1939 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1940 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 1941 | if (did_show_) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 1942 | // When supports_multiple_windows is disabled, popups are reusing |
| 1943 | // the same view. In some scenarios, this makes WebKit to call show() twice. |
[email protected] | c9edabd | 2013-05-23 13:56:24 | [diff] [blame] | 1944 | if (webkit_preferences_.supports_multiple_windows) |
| 1945 | NOTREACHED() << "received extraneous Show call"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1946 | return; |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 1947 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1948 | did_show_ = true; |
| 1949 | |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 1950 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 1951 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 1952 | // Force new windows to a popup if they were not opened with a user gesture. |
| 1953 | if (!opened_by_user_gesture_) { |
| 1954 | // We exempt background tabs for compat with older versions of Chrome. |
| 1955 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 1956 | // we probably don't need this check. |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1957 | if (policy != blink::WebNavigationPolicyNewBackgroundTab) |
| 1958 | policy = blink::WebNavigationPolicyNewPopup; |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 1959 | } |
| 1960 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1961 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 1962 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 1963 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1964 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 1965 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 1966 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1967 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1968 | } |
| 1969 | |
[email protected] | dd48d49 | 2014-03-16 05:04:39 | [diff] [blame] | 1970 | void RenderViewImpl::runModal() { |
| 1971 | DCHECK(did_show_) << "should already have shown the view"; |
| 1972 | |
| 1973 | // Don't allow further dialogs if we are waiting to swap out, since the |
| 1974 | // PageGroupLoadDeferrer in our stack prevents it. |
| 1975 | if (suppress_dialogs_until_swap_out_) |
| 1976 | return; |
| 1977 | |
| 1978 | // We must keep WebKit's shared timer running in this case in order to allow |
| 1979 | // showModalDialog to function properly. |
| 1980 | // |
| 1981 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 1982 | // timers so that we do not need to manage the shared timer in such a heavy |
| 1983 | // handed manner. |
| 1984 | // |
| 1985 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 1986 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
| 1987 | |
| 1988 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal( |
| 1989 | routing_id_, opener_id_)); |
| 1990 | } |
| 1991 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1992 | bool RenderViewImpl::enterFullScreen() { |
| 1993 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 1994 | return true; |
| 1995 | } |
| 1996 | |
| 1997 | void RenderViewImpl::exitFullScreen() { |
| 1998 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 1999 | } |
| 2000 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 2001 | bool RenderViewImpl::requestPointerLock() { |
| 2002 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2003 | } |
| 2004 | |
| 2005 | void RenderViewImpl::requestPointerUnlock() { |
| 2006 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2007 | } |
| 2008 | |
| 2009 | bool RenderViewImpl::isPointerLocked() { |
| 2010 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2011 | webwidget_mouse_lock_target_.get()); |
| 2012 | } |
| 2013 | |
[email protected] | c0b0bd1 | 2014-03-13 00:39:58 | [diff] [blame] | 2014 | // FIXME: To be removed as soon as chromium and blink side changes land |
| 2015 | // didActivateCompositor with parameters is still kept in order to land |
| 2016 | // these changes s-chromium - https://codereview.chromium.org/137893025/. |
| 2017 | // s-blink - https://codereview.chromium.org/138523003/ |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2018 | void RenderViewImpl::didActivateCompositor(int input_handler_identifier) { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 2019 | #if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003 |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 2020 | InputHandlerManager* input_handler_manager = |
| 2021 | RenderThreadImpl::current()->input_handler_manager(); |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 2022 | if (input_handler_manager) { |
| 2023 | input_handler_manager->AddInputHandler( |
| 2024 | routing_id_, |
| 2025 | compositor_->GetInputHandler(), |
| 2026 | AsWeakPtr()); |
| 2027 | } |
[email protected] | 70cff2750 | 2013-01-17 09:16:49 | [diff] [blame] | 2028 | #endif |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2029 | |
| 2030 | RenderWidget::didActivateCompositor(input_handler_identifier); |
| 2031 | } |
| 2032 | |
[email protected] | c0b0bd1 | 2014-03-13 00:39:58 | [diff] [blame] | 2033 | void RenderViewImpl::didActivateCompositor() { |
| 2034 | #if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003 |
| 2035 | InputHandlerManager* input_handler_manager = |
| 2036 | RenderThreadImpl::current()->input_handler_manager(); |
| 2037 | if (input_handler_manager) { |
| 2038 | input_handler_manager->AddInputHandler( |
| 2039 | routing_id_, |
| 2040 | compositor_->GetInputHandler(), |
| 2041 | AsWeakPtr()); |
| 2042 | } |
| 2043 | #endif |
| 2044 | |
| 2045 | RenderWidget::didActivateCompositor(); |
| 2046 | } |
| 2047 | |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2048 | void RenderViewImpl::didHandleGestureEvent( |
| 2049 | const WebGestureEvent& event, |
| 2050 | bool event_cancelled) { |
| 2051 | RenderWidget::didHandleGestureEvent(event, event_cancelled); |
[email protected] | bb37b65 | 2013-11-27 23:47:11 | [diff] [blame] | 2052 | |
| 2053 | if (event.type != blink::WebGestureEvent::GestureTap) |
| 2054 | return; |
| 2055 | |
| 2056 | blink::WebTextInputType text_input_type = |
| 2057 | GetWebView()->textInputInfo().type; |
| 2058 | |
| 2059 | Send(new ViewHostMsg_FocusedNodeTouched( |
| 2060 | routing_id(), text_input_type != blink::WebTextInputTypeNone)); |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2061 | } |
| 2062 | |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 2063 | void RenderViewImpl::initializeLayerTreeView() { |
| 2064 | RenderWidget::initializeLayerTreeView(); |
| 2065 | RenderWidgetCompositor* rwc = compositor(); |
| 2066 | if (!rwc || !webview() || !webview()->devToolsAgent()) |
| 2067 | return; |
| 2068 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 2069 | } |
| 2070 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2071 | // blink::WebFrameClient ----------------------------------------------------- |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2072 | |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 2073 | blink::WebMediaPlayer* RenderViewImpl::CreateMediaPlayer( |
| 2074 | RenderFrame* render_frame, |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2075 | blink::WebLocalFrame* frame, |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 2076 | const blink::WebURL& url, |
| 2077 | blink::WebMediaPlayerClient* client) { |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 2078 | FOR_EACH_OBSERVER( |
| 2079 | RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client)); |
[email protected] | 7198402c | 2011-04-11 12:15:17 | [diff] [blame] | 2080 | |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 2081 | WebMediaPlayer* player = CreateWebMediaPlayerForMediaStream(frame, url, |
| 2082 | client); |
| 2083 | if (player) |
| 2084 | return player; |
[email protected] | d05e216 | 2012-11-16 22:21:46 | [diff] [blame] | 2085 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2086 | #if defined(OS_ANDROID) |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 2087 | return CreateAndroidWebMediaPlayer(frame, url, client); |
| 2088 | #else |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 2089 | WebMediaPlayerParams params( |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 2090 | base::Bind(&ContentRendererClient::DeferMediaLoad, |
| 2091 | base::Unretained(GetContentClient()->renderer()), |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 2092 | static_cast<RenderFrame*>(render_frame)), |
[email protected] | c6a04ba | 2014-03-07 11:47:04 | [diff] [blame] | 2093 | RenderThreadImpl::current()->GetAudioRendererMixerManager()->CreateInput( |
| 2094 | routing_id_, render_frame->GetRoutingID())); |
[email protected] | 1dd0bb75 | 2014-02-01 01:16:26 | [diff] [blame] | 2095 | return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params); |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 2096 | #endif // defined(OS_ANDROID) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2097 | } |
| 2098 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2099 | void RenderViewImpl::didAccessInitialDocument(WebLocalFrame* frame) { |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 2100 | // Notify the browser process that it is no longer safe to show the pending |
| 2101 | // URL of the main frame, since a URL spoof is now possible. |
| 2102 | if (!frame->parent() && page_id_ == -1) |
| 2103 | Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_)); |
| 2104 | } |
| 2105 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2106 | void RenderViewImpl::didDisownOpener(blink::WebLocalFrame* frame) { |
[email protected] | 29ece2e | 2013-04-03 04:53:52 | [diff] [blame] | 2107 | // We only need to notify the browser if the active, top-level frame clears |
| 2108 | // its opener. We can ignore cases where a swapped out frame clears its |
| 2109 | // opener after hearing about it from the browser, and the browser does not |
| 2110 | // (yet) care about subframe openers. |
| 2111 | if (is_swapped_out_ || frame->parent()) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 2112 | return; |
| 2113 | |
| 2114 | // Notify WebContents and all its swapped out RenderViews. |
| 2115 | Send(new ViewHostMsg_DidDisownOpener(routing_id_)); |
| 2116 | } |
| 2117 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2118 | void RenderViewImpl::frameDetached(WebFrame* frame) { |
[email protected] | 5f96f5a6 | 2014-01-10 00:05:11 | [diff] [blame] | 2119 | // NOTE: We may get here for either the main frame or for subframes. The |
| 2120 | // RenderFrameImpl will be deleted immediately after this call for subframes |
| 2121 | // but not for the main frame, which is owned by |main_render_frame_|. |
| 2122 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2123 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2124 | } |
| 2125 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2126 | void RenderViewImpl::willClose(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2127 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2128 | } |
| 2129 | |
[email protected] | f5b6dd112 | 2013-10-04 02:42:50 | [diff] [blame] | 2130 | void RenderViewImpl::didMatchCSS( |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2131 | WebLocalFrame* frame, |
[email protected] | f5b6dd112 | 2013-10-04 02:42:50 | [diff] [blame] | 2132 | const WebVector<WebString>& newly_matching_selectors, |
| 2133 | const WebVector<WebString>& stopped_matching_selectors) { |
| 2134 | FOR_EACH_OBSERVER( |
| 2135 | RenderViewObserver, observers_, |
| 2136 | DidMatchCSS(frame, newly_matching_selectors, stopped_matching_selectors)); |
| 2137 | } |
| 2138 | |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2139 | void RenderViewImpl::Repaint(const gfx::Size& size) { |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 2140 | OnRepaint(size); |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2141 | } |
| 2142 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 2143 | void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name, |
| 2144 | const std::string& value) { |
| 2145 | EditCommands edit_commands; |
| 2146 | edit_commands.push_back(EditCommand(name, value)); |
| 2147 | OnSetEditCommandsForNextKeyEvent(edit_commands); |
| 2148 | } |
| 2149 | |
| 2150 | void RenderViewImpl::ClearEditCommands() { |
| 2151 | edit_commands_.clear(); |
| 2152 | } |
| 2153 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2154 | SSLStatus RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame* frame) const { |
[email protected] | 83c0abca | 2013-07-23 20:09:42 | [diff] [blame] | 2155 | std::string security_info; |
| 2156 | if (frame && frame->dataSource()) |
| 2157 | security_info = frame->dataSource()->response().securityInfo(); |
| 2158 | |
| 2159 | SSLStatus ssl_status; |
| 2160 | DeserializeSecurityInfo(security_info, |
| 2161 | &ssl_status.cert_id, |
| 2162 | &ssl_status.cert_status, |
| 2163 | &ssl_status.security_bits, |
[email protected] | 0bbd63b | 2013-11-29 00:02:12 | [diff] [blame] | 2164 | &ssl_status.connection_status, |
| 2165 | &ssl_status.signed_certificate_timestamp_ids); |
[email protected] | 83c0abca | 2013-07-23 20:09:42 | [diff] [blame] | 2166 | return ssl_status; |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 2167 | } |
| 2168 | |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 2169 | const std::string& RenderViewImpl::GetAcceptLanguages() const { |
| 2170 | return renderer_preferences_.accept_languages; |
| 2171 | } |
| 2172 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2173 | void RenderViewImpl::willSendSubmitEvent(blink::WebLocalFrame* frame, |
| 2174 | const blink::WebFormElement& form) { |
[email protected] | 0660a8c | 2013-08-16 01:09:12 | [diff] [blame] | 2175 | FOR_EACH_OBSERVER( |
| 2176 | RenderViewObserver, observers_, WillSendSubmitEvent(frame, form)); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2177 | } |
| 2178 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2179 | void RenderViewImpl::willSubmitForm(WebLocalFrame* frame, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2180 | const WebFormElement& form) { |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 2181 | FOR_EACH_OBSERVER( |
| 2182 | RenderViewObserver, observers_, WillSubmitForm(frame, form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2183 | } |
| 2184 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2185 | void RenderViewImpl::didCreateDataSource(WebLocalFrame* frame, |
| 2186 | WebDataSource* ds) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2187 | bool content_initiated = !pending_navigation_params_.get(); |
| 2188 | |
[email protected] | f887290 | 2013-10-30 03:18:57 | [diff] [blame] | 2189 | // Make sure any previous redirect URLs end up in our new data source. |
| 2190 | if (pending_navigation_params_.get()) { |
| 2191 | for (std::vector<GURL>::const_iterator i = |
| 2192 | pending_navigation_params_->redirects.begin(); |
| 2193 | i != pending_navigation_params_->redirects.end(); ++i) { |
| 2194 | ds->appendRedirect(*i); |
| 2195 | } |
| 2196 | } |
| 2197 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2198 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 2199 | if (!document_state) { |
| 2200 | document_state = new DocumentState; |
| 2201 | ds->setExtraData(document_state); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2202 | if (!content_initiated) |
| 2203 | PopulateDocumentStateFromPending(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2204 | } |
| 2205 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2206 | // Carry over the user agent override flag, if it exists. |
| 2207 | if (content_initiated && webview() && webview()->mainFrame() && |
| 2208 | webview()->mainFrame()->dataSource()) { |
| 2209 | DocumentState* old_document_state = |
| 2210 | DocumentState::FromDataSource(webview()->mainFrame()->dataSource()); |
| 2211 | if (old_document_state) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2212 | InternalDocumentStateData* internal_data = |
| 2213 | InternalDocumentStateData::FromDocumentState(document_state); |
| 2214 | InternalDocumentStateData* old_internal_data = |
| 2215 | InternalDocumentStateData::FromDocumentState(old_document_state); |
| 2216 | internal_data->set_is_overriding_user_agent( |
| 2217 | old_internal_data->is_overriding_user_agent()); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2221 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2222 | // non-null NavigationState. |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 2223 | if (content_initiated) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2224 | document_state->set_navigation_state( |
| 2225 | NavigationState::CreateContentInitiated()); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 2226 | } else { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2227 | document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 2228 | pending_navigation_params_.reset(); |
| 2229 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2230 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2231 | // DocumentState::referred_by_prefetcher_ is true if we are |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2232 | // navigating from a page that used prefetching using a link on that |
| 2233 | // page. We are early enough in the request process here that we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2234 | // can still see the DocumentState of the previous page and set |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2235 | // this value appropriately. |
| 2236 | // TODO(gavinp): catch the important case of navigation in a new |
| 2237 | // renderer process. |
| 2238 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2239 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2240 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2241 | const GURL referrer( |
| 2242 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2243 | if (!referrer.is_empty() && |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2244 | DocumentState::FromDataSource( |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2245 | old_frame->dataSource())->was_prefetcher()) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2246 | for (; old_frame; old_frame = old_frame->traverseNext(false)) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2247 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 2248 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2249 | document_state->set_was_referred_by_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2250 | break; |
| 2251 | } |
| 2252 | } |
| 2253 | } |
| 2254 | } |
| 2255 | } |
| 2256 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2257 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2258 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2259 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2260 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2261 | document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2262 | break; |
| 2263 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2264 | document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2265 | break; |
| 2266 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2267 | document_state->set_load_type( |
| 2268 | DocumentState::LINK_LOAD_CACHE_STALE_OK); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2269 | break; |
| 2270 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2271 | document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2272 | break; |
| 2273 | } |
| 2274 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2275 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 2276 | FOR_EACH_OBSERVER( |
| 2277 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2278 | } |
| 2279 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2280 | void RenderViewImpl::PopulateDocumentStateFromPending( |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2281 | DocumentState* document_state) { |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 2282 | const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2283 | document_state->set_request_time(params.request_time); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2284 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2285 | InternalDocumentStateData* internal_data = |
| 2286 | InternalDocumentStateData::FromDocumentState(document_state); |
| 2287 | |
[email protected] | 44b0581 | 2013-08-19 07:59:35 | [diff] [blame] | 2288 | if (!params.url.SchemeIs(kJavaScriptScheme) && |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 2289 | params.navigation_type == FrameMsg_Navigate_Type::RESTORE) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2290 | // We're doing a load of a page that was restored from the last session. By |
| 2291 | // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which |
| 2292 | // can result in stale data for pages that are set to expire. We explicitly |
| 2293 | // override that by setting the policy here so that as necessary we load |
| 2294 | // from the network. |
[email protected] | a8ff8ed | 2014-01-09 07:32:26 | [diff] [blame] | 2295 | // |
| 2296 | // TODO(davidben): Remove this in favor of passing a cache policy to the |
| 2297 | // loadHistoryItem call in OnNavigate. That requires not overloading |
| 2298 | // UseProtocolCachePolicy to mean both "normal load" and "determine cache |
| 2299 | // policy based on load type, etc". |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2300 | internal_data->set_cache_policy_override( |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2301 | WebURLRequest::UseProtocolCachePolicy); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | if (IsReload(params)) |
| 2305 | document_state->set_load_type(DocumentState::RELOAD); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 2306 | else if (params.page_state.IsValid()) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2307 | document_state->set_load_type(DocumentState::HISTORY_LOAD); |
| 2308 | else |
| 2309 | document_state->set_load_type(DocumentState::NORMAL_LOAD); |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 2310 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2311 | internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent); |
| 2312 | internal_data->set_must_reset_scroll_and_scale_state( |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 2313 | params.navigation_type == |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 2314 | FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 2315 | document_state->set_can_load_local_resources(params.can_load_local_resources); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2316 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2317 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2318 | NavigationState* RenderViewImpl::CreateNavigationStateFromPending() { |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 2319 | const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2320 | NavigationState* navigation_state = NULL; |
| 2321 | |
| 2322 | // A navigation resulting from loading a javascript URL should not be treated |
| 2323 | // as a browser initiated event. Instead, we want it to look as if the page |
| 2324 | // initiated any load resulting from JS execution. |
[email protected] | 44b0581 | 2013-08-19 07:59:35 | [diff] [blame] | 2325 | if (!params.url.SchemeIs(kJavaScriptScheme)) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2326 | navigation_state = NavigationState::CreateBrowserInitiated( |
| 2327 | params.page_id, |
| 2328 | params.pending_history_list_offset, |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 2329 | params.should_clear_history_list, |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2330 | params.transition); |
[email protected] | 4972fc8 | 2013-11-19 04:33:42 | [diff] [blame] | 2331 | navigation_state->set_should_replace_current_entry( |
| 2332 | params.should_replace_current_entry); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2333 | navigation_state->set_transferred_request_child_id( |
| 2334 | params.transferred_request_child_id); |
| 2335 | navigation_state->set_transferred_request_request_id( |
| 2336 | params.transferred_request_request_id); |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 2337 | navigation_state->set_allow_download(params.allow_download); |
[email protected] | f050fde | 2013-03-21 00:40:45 | [diff] [blame] | 2338 | navigation_state->set_extra_headers(params.extra_headers); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2339 | } else { |
| 2340 | navigation_state = NavigationState::CreateContentInitiated(); |
| 2341 | } |
| 2342 | return navigation_state; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2343 | } |
| 2344 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 2345 | void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) { |
| 2346 | bool enable_viewport = |
[email protected] | a41f8f60 | 2013-11-12 20:15:28 | [diff] [blame] | 2347 | command_line.HasSwitch(switches::kEnableViewport) || |
| 2348 | command_line.HasSwitch(switches::kEnableViewportMeta); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 2349 | |
[email protected] | 47e932da | 2013-03-07 00:11:24 | [diff] [blame] | 2350 | // If viewport tag is enabled, then the WebKit side will take care |
| 2351 | // of setting the fixed layout size and page scale limits. |
| 2352 | if (enable_viewport) |
| 2353 | return; |
| 2354 | |
[email protected] | a02a0c9 | 2013-08-12 20:18:58 | [diff] [blame] | 2355 | // When navigating to a new page, reset the page scale factor to be 1.0. |
| 2356 | webview()->setInitialPageScaleOverride(1.f); |
| 2357 | |
[email protected] | e4cd82e | 2013-04-10 15:20:38 | [diff] [blame] | 2358 | float maxPageScaleFactor = |
| 2359 | command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ; |
| 2360 | webview()->setPageScaleFactorLimits(1, maxPageScaleFactor); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 2361 | } |
| 2362 | |
[email protected] | 8672bbf | 2013-10-22 13:37:08 | [diff] [blame] | 2363 | // TODO(nasko): Remove this method once WebTestProxy in Blink is fixed. |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2364 | void RenderViewImpl::didStartProvisionalLoad(WebLocalFrame* frame) {} |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2365 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2366 | void RenderViewImpl::didFailProvisionalLoad(WebLocalFrame* frame, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2367 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2368 | // Notify the browser that we failed a provisional load with an error. |
| 2369 | // |
| 2370 | // Note: It is important this notification occur before DidStopLoading so the |
| 2371 | // SSL manager can react to the provisional load failure before being |
| 2372 | // notified the load stopped. |
| 2373 | // |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2374 | FOR_EACH_OBSERVER( |
| 2375 | RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2376 | } |
| 2377 | |
[email protected] | 934a201 | 2014-04-08 22:42:38 | [diff] [blame] | 2378 | void RenderViewImpl::FrameDidCommitProvisionalLoad(WebLocalFrame* frame, |
[email protected] | 5d5471b | 2014-04-04 22:17:52 | [diff] [blame] | 2379 | bool is_new_navigation) { |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2380 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2381 | DidCommitProvisionalLoad(frame, is_new_navigation)); |
| 2382 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 2383 | // TODO(nasko): Transition this code to RenderFrameImpl, since g_view_map is |
| 2384 | // not accessible from there. |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 2385 | if (!frame->parent()) { // Only for top frames. |
| 2386 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 2387 | if (render_thread_impl) { // Can be NULL in tests. |
| 2388 | render_thread_impl->histogram_customizer()-> |
| 2389 | RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(), |
| 2390 | g_view_map.Get().size()); |
| 2391 | } |
| 2392 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2393 | } |
| 2394 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2395 | void RenderViewImpl::didClearWindowObject(WebLocalFrame* frame, int world_id) { |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 2396 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
[email protected] | c4f80f7 | 2014-01-13 11:24:12 | [diff] [blame] | 2397 | DidClearWindowObject(frame, world_id)); |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 2398 | |
[email protected] | 2904308 | 2014-01-22 21:53:51 | [diff] [blame] | 2399 | // Only install controllers into the main world. |
| 2400 | if (world_id) |
| 2401 | return; |
| 2402 | |
[email protected] | f5c9f088 | 2014-02-16 22:19:32 | [diff] [blame] | 2403 | if (enabled_bindings_& BINDINGS_POLICY_WEB_UI) |
| 2404 | WebUIExtension::Install(frame); |
| 2405 | |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 2406 | if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) |
| 2407 | StatsCollectionController::Install(frame); |
[email protected] | cdb6b1e | 2014-01-23 00:06:49 | [diff] [blame] | 2408 | |
| 2409 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 2410 | |
| 2411 | if (command_line.HasSwitch(switches::kEnableSkiaBenchmarking)) |
| 2412 | SkiaBenchmarking::Install(frame); |
[email protected] | 3fad220d | 2014-01-23 11:30:06 | [diff] [blame] | 2413 | |
| 2414 | if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking)) |
| 2415 | MemoryBenchmarkingExtension::Install(frame); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2416 | } |
| 2417 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2418 | void RenderViewImpl::didCreateDocumentElement(WebLocalFrame* frame) { |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2419 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2420 | DidCreateDocumentElement(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2421 | } |
| 2422 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2423 | void RenderViewImpl::didReceiveTitle(WebLocalFrame* frame, |
| 2424 | const WebString& title, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2425 | WebTextDirection direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 2426 | UpdateTitle(frame, title, direction); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2427 | |
| 2428 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2429 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2430 | } |
| 2431 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2432 | void RenderViewImpl::didChangeIcon(WebLocalFrame* frame, |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 2433 | WebIconURL::Type icon_type) { |
| 2434 | if (frame->parent()) |
| 2435 | return; |
| 2436 | |
| 2437 | if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon) |
| 2438 | return; |
| 2439 | |
| 2440 | WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
| 2441 | std::vector<FaviconURL> urls; |
| 2442 | for (size_t i = 0; i < icon_urls.size(); i++) { |
[email protected] | f34ac13 | 2014-03-20 23:02:05 | [diff] [blame] | 2443 | std::vector<gfx::Size> sizes(icon_urls[i].sizes().size()); |
| 2444 | ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); |
| 2445 | urls.push_back(FaviconURL( |
| 2446 | icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes)); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 2447 | } |
| 2448 | SendUpdateFaviconURL(urls); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 2449 | } |
| 2450 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2451 | void RenderViewImpl::didFinishDocumentLoad(WebLocalFrame* frame) { |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2452 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2453 | DidFinishDocumentLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2454 | } |
| 2455 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2456 | void RenderViewImpl::didHandleOnloadEvents(WebLocalFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 2457 | if (webview()->mainFrame() == frame) { |
| 2458 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 2459 | page_id_)); |
| 2460 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2461 | } |
| 2462 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2463 | void RenderViewImpl::didFailLoad(WebLocalFrame* frame, |
| 2464 | const WebURLError& error) { |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2465 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2466 | } |
| 2467 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2468 | void RenderViewImpl::didFinishLoad(WebLocalFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2469 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2470 | } |
| 2471 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2472 | void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2473 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 2474 | } |
| 2475 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2476 | void RenderViewImpl::didFinishResourceLoad(WebLocalFrame* frame, |
| 2477 | unsigned identifier) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2478 | InternalDocumentStateData* internal_data = |
| 2479 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 2480 | if (!internal_data->use_error_page()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2481 | return; |
| 2482 | |
[email protected] | 7bfc153f | 2011-09-23 22:00:20 | [diff] [blame] | 2483 | // Do not show error page when DevTools is attached. |
| 2484 | if (devtools_agent_->IsAttached()) |
| 2485 | return; |
| 2486 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 2487 | // Display error page, if appropriate. |
[email protected] | 3d612f5 | 2014-01-13 23:48:29 | [diff] [blame] | 2488 | std::string error_domain = "http"; |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2489 | int http_status_code = internal_data->http_status_code(); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2490 | if (GetContentClient()->renderer()->HasErrorPage( |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 2491 | http_status_code, &error_domain)) { |
| 2492 | WebURLError error; |
| 2493 | error.unreachableURL = frame->document().url(); |
| 2494 | error.domain = WebString::fromUTF8(error_domain); |
| 2495 | error.reason = http_status_code; |
[email protected] | 3d612f5 | 2014-01-13 23:48:29 | [diff] [blame] | 2496 | LoadNavigationErrorPage(frame, frame->dataSource()->request(), error, true); |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 2497 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2498 | } |
| 2499 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2500 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 2501 | // We don't always want to send the change messages over IPC, only if we've |
| 2502 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 2503 | // message. |
| 2504 | if (!send_preferred_size_changes_ || !webview()) |
| 2505 | return; |
| 2506 | |
[email protected] | e76b797 | 2013-06-06 02:58:48 | [diff] [blame] | 2507 | gfx::Size size = webview()->contentsPreferredMinimumSize(); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 2508 | |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 2509 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 2510 | // so we need to adjust. |
| 2511 | double zoom_factor = ZoomLevelToZoomFactor(webview()->zoomLevel()); |
| 2512 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 2513 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 2514 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 2515 | if (size == preferred_size_) |
| 2516 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2517 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 2518 | preferred_size_ = size; |
| 2519 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 2520 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2521 | } |
| 2522 | |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 2523 | BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2524 | if (!browser_plugin_manager_.get()) |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 2525 | browser_plugin_manager_ = BrowserPluginManager::Create(this); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2526 | return browser_plugin_manager_.get(); |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 2527 | } |
| 2528 | |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 2529 | bool RenderViewImpl::InitializeMediaStreamClient() { |
| 2530 | if (media_stream_client_) |
| 2531 | return true; |
| 2532 | |
[email protected] | 7082fb94 | 2012-05-16 23:44:59 | [diff] [blame] | 2533 | if (!RenderThreadImpl::current()) // Will be NULL during unit tests. |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 2534 | return false; |
[email protected] | 0838156 | 2012-05-15 20:55:40 | [diff] [blame] | 2535 | |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 2536 | #if defined(OS_ANDROID) |
[email protected] | ce585bf | 2013-03-14 16:25:16 | [diff] [blame] | 2537 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC)) |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 2538 | return false; |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 2539 | #endif |
| 2540 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 2541 | #if defined(ENABLE_WEBRTC) |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 2542 | if (!media_stream_dispatcher_) |
| 2543 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 2544 | |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 2545 | MediaStreamImpl* media_stream_impl = new MediaStreamImpl( |
| 2546 | this, |
| 2547 | media_stream_dispatcher_, |
| 2548 | RenderThreadImpl::current()->GetMediaStreamDependencyFactory()); |
| 2549 | media_stream_client_ = media_stream_impl; |
| 2550 | web_user_media_client_ = media_stream_impl; |
| 2551 | return true; |
| 2552 | #else |
| 2553 | return false; |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 2554 | #endif |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 2555 | } |
| 2556 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2557 | void RenderViewImpl::didChangeContentsSize(WebLocalFrame* frame, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2558 | const WebSize& size) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2559 | if (webview()->mainFrame() != frame) |
| 2560 | return; |
| 2561 | WebView* frameView = frame->view(); |
| 2562 | if (!frameView) |
| 2563 | return; |
| 2564 | |
| 2565 | bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); |
| 2566 | bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); |
| 2567 | |
| 2568 | if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || |
| 2569 | has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { |
| 2570 | Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( |
| 2571 | routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); |
| 2572 | |
| 2573 | cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; |
| 2574 | cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; |
| 2575 | } |
| 2576 | } |
| 2577 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2578 | void RenderViewImpl::UpdateScrollState(WebFrame* frame) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2579 | WebSize offset = frame->scrollOffset(); |
| 2580 | WebSize minimum_offset = frame->minimumScrollOffset(); |
| 2581 | WebSize maximum_offset = frame->maximumScrollOffset(); |
| 2582 | |
| 2583 | bool is_pinned_to_left = offset.width <= minimum_offset.width; |
| 2584 | bool is_pinned_to_right = offset.width >= maximum_offset.width; |
| 2585 | |
| 2586 | if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || |
| 2587 | is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { |
| 2588 | Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( |
| 2589 | routing_id_, is_pinned_to_left, is_pinned_to_right)); |
| 2590 | |
| 2591 | cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; |
| 2592 | cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; |
| 2593 | } |
[email protected] | 4e72174 | 2013-02-04 21:39:30 | [diff] [blame] | 2594 | |
| 2595 | Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2596 | } |
| 2597 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2598 | void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) { |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 2599 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2600 | |
| 2601 | if (webview()->mainFrame() == frame) |
| 2602 | UpdateScrollState(frame); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 2603 | |
| 2604 | FOR_EACH_OBSERVER( |
| 2605 | RenderViewObserver, observers_, DidChangeScrollOffset(frame)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2606 | } |
| 2607 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2608 | void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebLocalFrame* frame) { |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 2609 | if (frame != webview()->mainFrame()) |
| 2610 | return; |
| 2611 | |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 2612 | InternalDocumentStateData* data = |
| 2613 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 2614 | data->set_did_first_visually_non_empty_layout(true); |
| 2615 | |
| 2616 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 2617 | // Update body background color if necessary. |
| 2618 | SkColor bg_color = webwidget_->backgroundColor(); |
| 2619 | |
| 2620 | // If not initialized, default to white. Note that 0 is different from black |
| 2621 | // as black still has alpha 0xFF. |
| 2622 | if (!bg_color) |
| 2623 | bg_color = SK_ColorWHITE; |
| 2624 | |
| 2625 | if (bg_color != body_background_color_) { |
| 2626 | body_background_color_ = bg_color; |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 2627 | Send(new ViewHostMsg_DidChangeBodyBackgroundColor( |
| 2628 | GetRoutingID(), bg_color)); |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 2629 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 2630 | #endif |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 2631 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 2632 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2633 | void RenderViewImpl::SendFindReply(int request_id, |
| 2634 | int match_count, |
| 2635 | int ordinal, |
| 2636 | const WebRect& selection_rect, |
| 2637 | bool final_status_update) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2638 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 2639 | request_id, |
| 2640 | match_count, |
| 2641 | selection_rect, |
| 2642 | ordinal, |
| 2643 | final_status_update)); |
| 2644 | } |
| 2645 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2646 | bool RenderViewImpl::willCheckAndDispatchMessageEvent( |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2647 | blink::WebLocalFrame* sourceFrame, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2648 | blink::WebFrame* targetFrame, |
| 2649 | blink::WebSecurityOrigin target_origin, |
| 2650 | blink::WebDOMMessageEvent event) { |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2651 | if (!is_swapped_out_) |
| 2652 | return false; |
| 2653 | |
| 2654 | ViewMsg_PostMessage_Params params; |
| 2655 | params.data = event.data().toString(); |
| 2656 | params.source_origin = event.origin(); |
| 2657 | if (!target_origin.isNull()) |
| 2658 | params.target_origin = target_origin.toString(); |
| 2659 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2660 | blink::WebMessagePortChannelArray channels = event.releaseChannels(); |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 2661 | if (!channels.isEmpty()) { |
| 2662 | std::vector<int> message_port_ids(channels.size()); |
| 2663 | // Extract the port IDs from the channel array. |
| 2664 | for (size_t i = 0; i < channels.size(); ++i) { |
| 2665 | WebMessagePortChannelImpl* webchannel = |
| 2666 | static_cast<WebMessagePortChannelImpl*>(channels[i]); |
| 2667 | message_port_ids[i] = webchannel->message_port_id(); |
| 2668 | webchannel->QueueMessages(); |
| 2669 | DCHECK_NE(message_port_ids[i], MSG_ROUTING_NONE); |
| 2670 | } |
| 2671 | params.message_port_ids = message_port_ids; |
| 2672 | } |
| 2673 | |
[email protected] | 2bb45f5 | 2013-11-02 02:15:08 | [diff] [blame] | 2674 | // Include the routing ID for the source frame (if one exists), which the |
| 2675 | // browser process will translate into the routing ID for the equivalent |
| 2676 | // frame in the target process. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2677 | params.source_routing_id = MSG_ROUTING_NONE; |
[email protected] | 2bb45f5 | 2013-11-02 02:15:08 | [diff] [blame] | 2678 | if (sourceFrame) { |
| 2679 | RenderViewImpl* source_view = FromWebView(sourceFrame->view()); |
| 2680 | if (source_view) |
| 2681 | params.source_routing_id = source_view->routing_id(); |
| 2682 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2683 | |
| 2684 | Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
| 2685 | return true; |
| 2686 | } |
| 2687 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2688 | blink::WebString RenderViewImpl::acceptLanguages() { |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame] | 2689 | return WebString::fromUTF8(renderer_preferences_.accept_languages); |
| 2690 | } |
| 2691 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2692 | // blink::WebPageSerializerClient implementation ------------------------------ |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 2693 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2694 | void RenderViewImpl::didSerializeDataForFrame( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 2695 | const WebURL& frame_url, |
| 2696 | const WebCString& data, |
| 2697 | WebPageSerializerClient::PageSerializationStatus status) { |
| 2698 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 2699 | routing_id(), |
| 2700 | frame_url, |
| 2701 | data.data(), |
| 2702 | static_cast<int32>(status))); |
| 2703 | } |
| 2704 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2705 | // RenderView implementation --------------------------------------------------- |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2706 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2707 | bool RenderViewImpl::Send(IPC::Message* message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2708 | return RenderWidget::Send(message); |
| 2709 | } |
| 2710 | |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 2711 | RenderFrame* RenderViewImpl::GetMainRenderFrame() { |
| 2712 | return main_render_frame_.get(); |
| 2713 | } |
| 2714 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2715 | int RenderViewImpl::GetRoutingID() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2716 | return routing_id_; |
| 2717 | } |
| 2718 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2719 | int RenderViewImpl::GetPageId() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2720 | return page_id_; |
| 2721 | } |
| 2722 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2723 | gfx::Size RenderViewImpl::GetSize() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2724 | return size(); |
| 2725 | } |
| 2726 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2727 | WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2728 | return webkit_preferences_; |
| 2729 | } |
| 2730 | |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 2731 | void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) { |
| 2732 | OnUpdateWebPreferences(preferences); |
| 2733 | } |
| 2734 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2735 | blink::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2736 | return webview(); |
| 2737 | } |
| 2738 | |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2739 | blink::WebElement RenderViewImpl::GetFocusedElement() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2740 | if (!webview()) |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2741 | return WebElement(); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2742 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 2743 | if (focused_frame) { |
| 2744 | WebDocument doc = focused_frame->document(); |
| 2745 | if (!doc.isNull()) |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2746 | return doc.focusedElement(); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2747 | } |
| 2748 | |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2749 | return WebElement(); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2750 | } |
| 2751 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2752 | bool RenderViewImpl::IsEditableNode(const WebNode& node) const { |
| 2753 | if (node.isNull()) |
| 2754 | return false; |
| 2755 | |
| 2756 | if (node.isContentEditable()) |
| 2757 | return true; |
| 2758 | |
| 2759 | if (node.isElementNode()) { |
| 2760 | const WebElement& element = node.toConst<WebElement>(); |
| 2761 | if (element.isTextFormControlElement()) |
| 2762 | return true; |
| 2763 | |
| 2764 | // Also return true if it has an ARIA role of 'textbox'. |
| 2765 | for (unsigned i = 0; i < element.attributeCount(); ++i) { |
| 2766 | if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) { |
| 2767 | if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox")) |
| 2768 | return true; |
| 2769 | break; |
| 2770 | } |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2771 | } |
| 2772 | } |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2773 | |
| 2774 | return false; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2775 | } |
| 2776 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2777 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2778 | return (!send_preferred_size_changes_ || |
| 2779 | (disable_scrollbars_size_limit_.width() <= width || |
| 2780 | disable_scrollbars_size_limit_.height() <= height)); |
| 2781 | } |
| 2782 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2783 | int RenderViewImpl::GetEnabledBindings() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2784 | return enabled_bindings_; |
| 2785 | } |
| 2786 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2787 | bool RenderViewImpl::GetContentStateImmediately() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2788 | return send_content_state_immediately_; |
| 2789 | } |
| 2790 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2791 | float RenderViewImpl::GetFilteredTimePerFrame() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2792 | return filtered_time_per_frame(); |
| 2793 | } |
| 2794 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2795 | blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2796 | return visibilityState(); |
| 2797 | } |
| 2798 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2799 | void RenderViewImpl::DidStartLoading() { |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 2800 | main_render_frame_->didStartLoading(true); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | void RenderViewImpl::DidStopLoading() { |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 2804 | main_render_frame_->didStopLoading(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2805 | } |
| 2806 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2807 | void RenderViewImpl::DidPlay(blink::WebMediaPlayer* player) { |
[email protected] | 1dd0bb75 | 2014-02-01 01:16:26 | [diff] [blame] | 2808 | Send(new ViewHostMsg_MediaPlayingNotification(routing_id_, |
| 2809 | reinterpret_cast<int64>(player), |
| 2810 | player->hasVideo(), |
| 2811 | player->hasAudio())); |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 2812 | } |
| 2813 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2814 | void RenderViewImpl::DidPause(blink::WebMediaPlayer* player) { |
[email protected] | 1dd0bb75 | 2014-02-01 01:16:26 | [diff] [blame] | 2815 | Send(new ViewHostMsg_MediaPausedNotification( |
| 2816 | routing_id_, reinterpret_cast<int64>(player))); |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 2817 | } |
| 2818 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2819 | void RenderViewImpl::PlayerGone(blink::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 2820 | DidPause(player); |
| 2821 | } |
| 2822 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2823 | void RenderViewImpl::SyncNavigationState() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2824 | if (!webview()) |
| 2825 | return; |
| 2826 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2827 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 2828 | SendUpdateState(item); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2829 | } |
| 2830 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2831 | GURL RenderViewImpl::GetLoadingUrl(blink::WebFrame* frame) const { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 2832 | WebDataSource* ds = frame->dataSource(); |
| 2833 | if (ds->hasUnreachableURL()) |
| 2834 | return ds->unreachableURL(); |
| 2835 | |
| 2836 | const WebURLRequest& request = ds->request(); |
| 2837 | return request.url(); |
| 2838 | } |
| 2839 | |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2840 | blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() { |
| 2841 | if (!webview()) |
| 2842 | return NULL; |
| 2843 | |
| 2844 | WebFrame* main_frame = webview()->mainFrame(); |
| 2845 | if (main_frame->document().isPluginDocument()) |
| 2846 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
| 2847 | |
| 2848 | #if defined(ENABLE_PLUGINS) |
| 2849 | if (plugin_find_handler_) |
| 2850 | return plugin_find_handler_->container()->plugin(); |
| 2851 | #endif |
| 2852 | |
| 2853 | return NULL; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2854 | } |
| 2855 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2856 | void RenderViewImpl::OnFind(int request_id, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 2857 | const base::string16& search_text, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2858 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2859 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2860 | blink::WebPlugin* plugin = GetWebPluginForFind(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 2861 | // Check if the plugin still exists in the document. |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2862 | if (plugin) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2863 | if (options.findNext) { |
| 2864 | // Just navigate back/forward. |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2865 | plugin->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2866 | } else { |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2867 | if (!plugin->startFind( |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 2868 | search_text, options.matchCase, request_id)) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 2869 | // Send "no results". |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2870 | SendFindReply(request_id, 0, 0, gfx::Rect(), true); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2871 | } |
| 2872 | } |
| 2873 | return; |
| 2874 | } |
| 2875 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 2876 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2877 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2878 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 2879 | |
| 2880 | bool multi_frame = (frame_after_main != main_frame); |
| 2881 | |
| 2882 | // If we have multiple frames, we don't want to wrap the search within the |
| 2883 | // frame, so we check here if we only have main_frame in the chain. |
| 2884 | bool wrap_within_frame = !multi_frame; |
| 2885 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 2886 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2887 | bool result = false; |
| 2888 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 2889 | // If something is selected when we start searching it means we cannot just |
| 2890 | // increment the current match ordinal; we need to re-generate it. |
| 2891 | WebRange current_selection = focused_frame->selectionRange(); |
| 2892 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2893 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2894 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2895 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2896 | |
| 2897 | if (!result) { |
| 2898 | // don't leave text selected as you move to the next frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 2899 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2900 | GetFocusedElement()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2901 | |
| 2902 | // Find the next frame, but skip the invisible ones. |
| 2903 | do { |
| 2904 | // What is the next frame to search? (we might be going backwards). Note |
| 2905 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2906 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 2907 | search_frame->traverseNext(true) : |
| 2908 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2909 | } while (!search_frame->hasVisibleContent() && |
| 2910 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2911 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 2912 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 2913 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2914 | GetFocusedElement()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2915 | |
| 2916 | // If we have multiple frames and we have wrapped back around to the |
| 2917 | // focused frame, we need to search it once more allowing wrap within |
| 2918 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 2919 | // reported matches, but no frames after the focused_frame contain a |
| 2920 | // match for the search word(s). |
| 2921 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2922 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2923 | request_id, search_text, options, true, // Force wrapping. |
| 2924 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2925 | } |
| 2926 | } |
| 2927 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2928 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2929 | } while (!result && search_frame != focused_frame); |
| 2930 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 2931 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2932 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2933 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2934 | } else { |
| 2935 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 2936 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 2937 | // yet what is active. |
| 2938 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 2939 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2940 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2941 | // If we find no matches then this will be our last status update. |
| 2942 | // Otherwise the scoping effort will send more results. |
| 2943 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2944 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2945 | SendFindReply(request_id, match_count, ordinal, selection_rect, |
| 2946 | final_status_update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2947 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2948 | // Scoping effort begins, starting with the mainframe. |
| 2949 | search_frame = main_frame; |
| 2950 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2951 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2952 | |
| 2953 | do { |
| 2954 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2955 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2956 | |
| 2957 | // We don't start another scoping effort unless at least one match has |
| 2958 | // been found. |
| 2959 | if (result) { |
| 2960 | // Start new scoping request. If the scoping function determines that it |
| 2961 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2962 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2963 | search_text, |
| 2964 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2965 | true); // reset the tickmarks |
| 2966 | } |
| 2967 | |
| 2968 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 2969 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 2970 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2971 | } while (search_frame != main_frame); |
| 2972 | } |
| 2973 | } |
| 2974 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2975 | void RenderViewImpl::OnStopFinding(StopFindAction action) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2976 | WebView* view = webview(); |
| 2977 | if (!view) |
| 2978 | return; |
| 2979 | |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2980 | blink::WebPlugin* plugin = GetWebPluginForFind(); |
| 2981 | if (plugin) { |
| 2982 | plugin->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2983 | return; |
| 2984 | } |
| 2985 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2986 | bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 2987 | if (clear_selection) { |
| 2988 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2989 | GetFocusedElement()); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 2990 | } |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2991 | |
| 2992 | WebFrame* frame = view->mainFrame(); |
| 2993 | while (frame) { |
| 2994 | frame->stopFinding(clear_selection); |
| 2995 | frame = frame->traverseNext(false); |
| 2996 | } |
| 2997 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2998 | if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2999 | WebFrame* focused_frame = view->focusedFrame(); |
| 3000 | if (focused_frame) { |
| 3001 | WebDocument doc = focused_frame->document(); |
| 3002 | if (!doc.isNull()) { |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 3003 | WebElement element = doc.focusedElement(); |
| 3004 | if (!element.isNull()) |
| 3005 | element.simulateClick(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3006 | } |
| 3007 | } |
| 3008 | } |
| 3009 | } |
| 3010 | |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3011 | #if defined(OS_ANDROID) |
| 3012 | void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| 3013 | float x, float y) { |
| 3014 | if (!webview()) |
| 3015 | return; |
| 3016 | |
| 3017 | WebFrame* main_frame = webview()->mainFrame(); |
| 3018 | WebRect selection_rect; |
| 3019 | int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), |
| 3020 | &selection_rect); |
| 3021 | if (ordinal == -1) { |
| 3022 | // Something went wrong, so send a no-op reply (force the main_frame to |
| 3023 | // report the current match count) in case the host is waiting for a |
| 3024 | // response due to rate-limiting). |
| 3025 | main_frame->increaseMatchCount(0, request_id); |
| 3026 | return; |
| 3027 | } |
| 3028 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 3029 | SendFindReply(request_id, |
| 3030 | -1 /* number_of_matches */, |
| 3031 | ordinal, |
| 3032 | selection_rect, |
| 3033 | true /* final_update */); |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | void RenderViewImpl::OnFindMatchRects(int current_version) { |
| 3037 | if (!webview()) |
| 3038 | return; |
| 3039 | |
| 3040 | WebFrame* main_frame = webview()->mainFrame(); |
| 3041 | std::vector<gfx::RectF> match_rects; |
| 3042 | |
| 3043 | int rects_version = main_frame->findMatchMarkersVersion(); |
| 3044 | if (current_version != rects_version) { |
| 3045 | WebVector<WebFloatRect> web_match_rects; |
| 3046 | main_frame->findMatchRects(web_match_rects); |
| 3047 | match_rects.reserve(web_match_rects.size()); |
| 3048 | for (size_t i = 0; i < web_match_rects.size(); ++i) |
| 3049 | match_rects.push_back(gfx::RectF(web_match_rects[i])); |
| 3050 | } |
| 3051 | |
| 3052 | gfx::RectF active_rect = main_frame->activeFindMatchRect(); |
| 3053 | Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_, |
| 3054 | rects_version, |
| 3055 | match_rects, |
| 3056 | active_rect)); |
| 3057 | } |
| 3058 | #endif |
| 3059 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3060 | void RenderViewImpl::OnZoom(PageZoom zoom) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3061 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 3062 | return; |
| 3063 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 3064 | webview()->hidePopups(); |
[email protected] | 854ab546 | 2011-11-22 20:48:10 | [diff] [blame] | 3065 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3066 | double old_zoom_level = webview()->zoomLevel(); |
| 3067 | double zoom_level; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3068 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3069 | zoom_level = 0; |
| 3070 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 3071 | // Previous zoom level is a whole number, so just increment/decrement. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 3072 | zoom_level = old_zoom_level + zoom; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3073 | } else { |
| 3074 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 3075 | // not a whole number, or a plugin changed it to a custom value. We want |
| 3076 | // to go to the next whole number so that the user can always get back to |
| 3077 | // 100% with the keyboard/menu. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 3078 | if ((old_zoom_level > 1 && zoom > 0) || |
| 3079 | (old_zoom_level < 1 && zoom < 0)) { |
| 3080 | zoom_level = static_cast<int>(old_zoom_level + zoom); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3081 | } else { |
| 3082 | // We're going towards 100%, so first go to the next whole number. |
| 3083 | zoom_level = static_cast<int>(old_zoom_level); |
| 3084 | } |
| 3085 | } |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 3086 | webview()->setZoomLevel(zoom_level); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 3087 | zoomLevelChanged(); |
| 3088 | } |
| 3089 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3090 | void RenderViewImpl::OnSetZoomLevel(double zoom_level) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 3091 | webview()->hidePopups(); |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 3092 | webview()->setZoomLevel(zoom_level); |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 3093 | zoomLevelChanged(); |
| 3094 | } |
| 3095 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3096 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 3097 | double zoom_level) { |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 3098 | #if !defined(OS_ANDROID) |
| 3099 | // On Android, page zoom isn't used, and in case of WebView, text zoom is used |
| 3100 | // for legacy WebView text scaling emulation. Thus, the code that resets |
| 3101 | // the zoom level from this map will be effectively resetting text zoom level. |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3102 | host_zoom_levels_[url] = zoom_level; |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 3103 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3104 | } |
| 3105 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3106 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3107 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3108 | } |
| 3109 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3110 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3111 | WebString no_encoding; |
| 3112 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 3113 | } |
| 3114 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 3115 | void RenderViewImpl::OnPostMessageEvent( |
| 3116 | const ViewMsg_PostMessage_Params& params) { |
[email protected] | bf4a231 | 2013-04-23 00:32:11 | [diff] [blame] | 3117 | // TODO(nasko): Support sending to subframes. |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 3118 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 3119 | |
| 3120 | // Find the source frame if it exists. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 3121 | WebFrame* source_frame = NULL; |
| 3122 | if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 3123 | RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
| 3124 | if (source_view) |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 3125 | source_frame = source_view->webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 3126 | } |
| 3127 | |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 3128 | // If the message contained MessagePorts, create the corresponding endpoints. |
| 3129 | DCHECK_EQ(params.message_port_ids.size(), params.new_routing_ids.size()); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3130 | blink::WebMessagePortChannelArray channels(params.message_port_ids.size()); |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 3131 | for (size_t i = 0; |
| 3132 | i < params.message_port_ids.size() && i < params.new_routing_ids.size(); |
| 3133 | ++i) { |
| 3134 | channels[i] = |
| 3135 | new WebMessagePortChannelImpl(params.new_routing_ids[i], |
| 3136 | params.message_port_ids[i], |
| 3137 | base::MessageLoopProxy::current().get()); |
| 3138 | } |
| 3139 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 3140 | // Create an event with the message. The final parameter to initMessageEvent |
| 3141 | // is the last event ID, which is not used with postMessage. |
| 3142 | WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
| 3143 | WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 3144 | msg_event.initMessageEvent("message", |
| 3145 | // |canBubble| and |cancellable| are always false |
| 3146 | false, false, |
| 3147 | WebSerializedScriptValue::fromString(params.data), |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 3148 | params.source_origin, source_frame, "", channels); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 3149 | |
| 3150 | // We must pass in the target_origin to do the security check on this side, |
| 3151 | // since it may have changed since the original postMessage call was made. |
| 3152 | WebSecurityOrigin target_origin; |
| 3153 | if (!params.target_origin.empty()) { |
| 3154 | target_origin = |
| 3155 | WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 3156 | } |
| 3157 | frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 3158 | } |
| 3159 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3160 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 3161 | if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && |
| 3162 | !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { |
[email protected] | 69a0a13 | 2014-03-26 16:45:02 | [diff] [blame] | 3163 | // WebUIExtensionData deletes itself when we're destroyed. |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 3164 | new WebUIExtensionData(this); |
[email protected] | 69a0a13 | 2014-03-26 16:45:02 | [diff] [blame] | 3165 | // WebUIMojo deletes itself when we're destroyed. |
| 3166 | new WebUIMojo(this); |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 3167 | } |
| 3168 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 3169 | enabled_bindings_ |= enabled_bindings_flags; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3170 | |
| 3171 | // Keep track of the total bindings accumulated in this process. |
| 3172 | RenderProcess::current()->AddBindings(enabled_bindings_flags); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3173 | } |
| 3174 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 3175 | void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3176 | const gfx::Point& client_point, |
| 3177 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 3178 | WebDragOperationsMask ops, |
| 3179 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3180 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 3181 | DropDataToWebDragData(drop_data), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3182 | client_point, |
| 3183 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 3184 | ops, |
| 3185 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3186 | |
| 3187 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 3188 | } |
| 3189 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3190 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 3191 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 3192 | WebDragOperationsMask ops, |
| 3193 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3194 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 3195 | client_point, |
| 3196 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 3197 | ops, |
| 3198 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3199 | |
| 3200 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 3201 | } |
| 3202 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3203 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3204 | webview()->dragTargetDragLeave(); |
| 3205 | } |
| 3206 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3207 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 3208 | const gfx::Point& screen_point, |
| 3209 | int key_modifiers) { |
| 3210 | webview()->dragTargetDrop(client_point, screen_point, key_modifiers); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 3211 | |
| 3212 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3213 | } |
| 3214 | |
[email protected] | 7a6d773f | 2014-04-04 01:25:09 | [diff] [blame] | 3215 | void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point, |
| 3216 | const gfx::Point& screen_point, |
| 3217 | WebDragOperation op) { |
| 3218 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3219 | } |
| 3220 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3221 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3222 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3223 | } |
| 3224 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3225 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 3226 | webkit_preferences_ = prefs; |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 3227 | ApplyWebPreferences(webkit_preferences_, webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3228 | } |
| 3229 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3230 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 3231 | int id, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 3232 | const std::vector<base::FilePath>& paths) { |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 3233 | if (!enumeration_completions_[id]) |
| 3234 | return; |
| 3235 | |
| 3236 | WebVector<WebString> ws_file_names(paths.size()); |
| 3237 | for (size_t i = 0; i < paths.size(); ++i) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 3238 | ws_file_names[i] = paths[i].AsUTF16Unsafe(); |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 3239 | |
| 3240 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 3241 | enumeration_completions_.erase(id); |
| 3242 | } |
| 3243 | |
[email protected] | fb11b6a4 | 2012-03-14 07:25:12 | [diff] [blame] | 3244 | void RenderViewImpl::OnFileChooserResponse( |
[email protected] | ddb034b | 2012-06-26 20:31:39 | [diff] [blame] | 3245 | const std::vector<ui::SelectedFileInfo>& files) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 3246 | // This could happen if we navigated to a different page before the user |
| 3247 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3248 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 3249 | return; |
| 3250 | |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 3251 | // Convert Chrome's SelectedFileInfo list to WebKit's. |
| 3252 | WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files( |
| 3253 | files.size()); |
| 3254 | for (size_t i = 0; i < files.size(); ++i) { |
| 3255 | WebFileChooserCompletion::SelectedFileInfo selected_file; |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 3256 | selected_file.path = files[i].local_path.AsUTF16Unsafe(); |
| 3257 | selected_file.displayName = |
| 3258 | base::FilePath(files[i].display_name).AsUTF16Unsafe(); |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 3259 | selected_files[i] = selected_file; |
| 3260 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 3261 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3262 | if (file_chooser_completions_.front()->completion) |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 3263 | file_chooser_completions_.front()->completion->didChooseFile( |
| 3264 | selected_files); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3265 | file_chooser_completions_.pop_front(); |
| 3266 | |
| 3267 | // If there are more pending file chooser requests, schedule one now. |
| 3268 | if (!file_chooser_completions_.empty()) { |
| 3269 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 3270 | file_chooser_completions_.front()->params)); |
| 3271 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3272 | } |
| 3273 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 3274 | void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
| 3275 | const gfx::Size& max_size) { |
| 3276 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 3277 | if (!webview()) |
| 3278 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 3279 | auto_resize_mode_ = true; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 3280 | webview()->enableAutoResizeMode(min_size, max_size); |
| 3281 | } |
| 3282 | |
| 3283 | void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) { |
| 3284 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 3285 | if (!webview()) |
| 3286 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 3287 | auto_resize_mode_ = false; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 3288 | webview()->disableAutoResizeMode(); |
| 3289 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 3290 | if (!new_size.IsEmpty()) { |
| 3291 | Resize(new_size, |
| 3292 | physical_backing_size_, |
| 3293 | overdraw_bottom_height_, |
| 3294 | resizer_rect_, |
| 3295 | is_fullscreen_, |
| 3296 | NO_RESIZE_ACK); |
| 3297 | } |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 3298 | } |
| 3299 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 3300 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 3301 | if (send_preferred_size_changes_) |
| 3302 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 3303 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 3304 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 3305 | // Start off with an initial preferred size notification (in case |
| 3306 | // |didUpdateLayout| was already called). |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 3307 | didUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 3308 | } |
| 3309 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3310 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3311 | const gfx::Size& disable_scrollbar_size_limit) { |
| 3312 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 3313 | } |
| 3314 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3315 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3316 | const RendererPreferences& renderer_prefs) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 3317 | double old_zoom_level = renderer_preferences_.default_zoom_level; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3318 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 3319 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 3320 | |
[email protected] | dcc29777 | 2014-04-10 22:20:52 | [diff] [blame] | 3321 | #if defined(USE_DEFAULT_RENDER_THEME) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 3322 | if (renderer_prefs.use_custom_colors) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3323 | WebColorName name = blink::WebColorWebkitFocusRingColor; |
| 3324 | blink::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
| 3325 | blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 3326 | |
| 3327 | if (webview()) { |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 3328 | webview()->setSelectionColors( |
| 3329 | renderer_prefs.active_selection_bg_color, |
| 3330 | renderer_prefs.active_selection_fg_color, |
| 3331 | renderer_prefs.inactive_selection_bg_color, |
| 3332 | renderer_prefs.inactive_selection_fg_color); |
| 3333 | webview()->themeChanged(); |
| 3334 | } |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3335 | } |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 3336 | #endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 3337 | |
[email protected] | 107c053 | 2013-02-06 02:34:09 | [diff] [blame] | 3338 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 3339 | RenderThreadImpl::current()->SetFlingCurveParameters( |
| 3340 | renderer_prefs.touchpad_fling_profile, |
| 3341 | renderer_prefs.touchscreen_fling_profile); |
| 3342 | |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 3343 | // If the zoom level for this page matches the old zoom default, and this |
| 3344 | // is not a plugin, update the zoom level to match the new default. |
| 3345 | if (webview() && !webview()->mainFrame()->document().isPluginDocument() && |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 3346 | !ZoomValuesEqual(old_zoom_level, |
| 3347 | renderer_preferences_.default_zoom_level) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3348 | ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) { |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 3349 | webview()->setZoomLevel(renderer_preferences_.default_zoom_level); |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 3350 | zoomLevelChanged(); |
| 3351 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3352 | } |
| 3353 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3354 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 3355 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 3356 | if (webview()) |
| 3357 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 3358 | } |
| 3359 | |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 3360 | void RenderViewImpl::OnOrientationChangeEvent(int orientation) { |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 3361 | // Screen has rotated. 0 = default (portrait), 90 = one turn right, and so on. |
[email protected] | 652ad83 | 2013-08-16 11:47:04 | [diff] [blame] | 3362 | FOR_EACH_OBSERVER(RenderViewObserver, |
| 3363 | observers_, |
| 3364 | OrientationChangeEvent(orientation)); |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 3365 | webview()->mainFrame()->sendOrientationChangeEvent(orientation); |
| 3366 | } |
| 3367 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 3368 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 3369 | const WebPluginAction& action) { |
| 3370 | if (webview()) |
| 3371 | webview()->performPluginAction(action, location); |
| 3372 | } |
| 3373 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3374 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3375 | const GURL& page_url) { |
| 3376 | // Prepare list to storage all savable resource links. |
| 3377 | std::vector<GURL> resources_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 3378 | std::vector<GURL> referrer_urls_list; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3379 | std::vector<blink::WebReferrerPolicy> referrer_policies_list; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3380 | std::vector<GURL> frames_list; |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 3381 | SavableResourcesResult result(&resources_list, |
| 3382 | &referrer_urls_list, |
| 3383 | &referrer_policies_list, |
| 3384 | &frames_list); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3385 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3386 | // webkit/ doesn't know about Referrer. |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 3387 | if (!GetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3388 | webview(), |
| 3389 | page_url, |
| 3390 | &result, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3391 | const_cast<const char**>(GetSavableSchemes()))) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3392 | // If something is wrong when collecting all savable resource links, |
| 3393 | // send empty list to embedder(browser) to tell it failed. |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 3394 | referrer_urls_list.clear(); |
| 3395 | referrer_policies_list.clear(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3396 | resources_list.clear(); |
| 3397 | frames_list.clear(); |
| 3398 | } |
| 3399 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3400 | std::vector<Referrer> referrers_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 3401 | CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size()); |
| 3402 | for (unsigned i = 0; i < referrer_urls_list.size(); ++i) { |
| 3403 | referrers_list.push_back( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3404 | Referrer(referrer_urls_list[i], referrer_policies_list[i])); |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 3405 | } |
| 3406 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3407 | // Send result of all savable resource links to embedder. |
| 3408 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 3409 | resources_list, |
| 3410 | referrers_list, |
| 3411 | frames_list)); |
| 3412 | } |
| 3413 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3414 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3415 | const std::vector<GURL>& links, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 3416 | const std::vector<base::FilePath>& local_paths, |
| 3417 | const base::FilePath& local_directory_name) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3418 | |
| 3419 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 3420 | WebVector<WebURL> weburl_links(links); |
| 3421 | |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 3422 | // Convert std::vector of base::FilePath to WebVector<WebString> |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3423 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 3424 | for (size_t i = 0; i < local_paths.size(); i++) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 3425 | webstring_paths[i] = local_paths[i].AsUTF16Unsafe(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3426 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 3427 | WebPageSerializer::serialize(webview()->mainFrame()->toWebLocalFrame(), |
| 3428 | true, |
| 3429 | this, |
| 3430 | weburl_links, |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3431 | webstring_paths, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 3432 | local_directory_name.AsUTF16Unsafe()); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3433 | } |
| 3434 | |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 3435 | void RenderViewImpl::OnSuppressDialogsUntilSwapOut() { |
| 3436 | // Don't show any more dialogs until we finish OnSwapOut. |
| 3437 | suppress_dialogs_until_swap_out_ = true; |
| 3438 | } |
| 3439 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3440 | void RenderViewImpl::NavigateToSwappedOutURL(blink::WebFrame* frame) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 3441 | // We use loadRequest instead of loadHTMLString because the former commits |
| 3442 | // synchronously. Otherwise a new navigation can interrupt the navigation |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3443 | // to kSwappedOutURL. If that happens to be to the page we had been |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 3444 | // showing, then WebKit will never send a commit and we'll be left spinning. |
[email protected] | b70da4c | 2014-01-06 19:57:09 | [diff] [blame] | 3445 | // TODO(creis): Until we move this to RenderFrame, we may call this from a |
| 3446 | // swapped out RenderFrame while our own is_swapped_out_ is false. |
[email protected] | a5ac6dc | 2014-01-15 07:02:14 | [diff] [blame] | 3447 | RenderFrameImpl* rf = RenderFrameImpl::FromWebFrame(frame); |
[email protected] | b70da4c | 2014-01-06 19:57:09 | [diff] [blame] | 3448 | CHECK(is_swapped_out_ || rf->is_swapped_out()); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3449 | GURL swappedOutURL(kSwappedOutURL); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 3450 | WebURLRequest request(swappedOutURL); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3451 | frame->loadRequest(request); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 3452 | } |
| 3453 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3454 | void RenderViewImpl::OnClosePage() { |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 3455 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3456 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 3457 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 3458 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 3459 | // calling the FrameLoader's CloseURL method directly. This should be |
| 3460 | // revisited to avoid having two ways to close a page. Having a single way |
| 3461 | // to close that can run onunload is also useful for fixing |
| 3462 | // http://b/issue?id=753080. |
[email protected] | 11fd5db | 2014-04-02 03:49:46 | [diff] [blame] | 3463 | webview()->mainFrame()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3464 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3465 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3466 | } |
| 3467 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3468 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 3469 | #if defined(USE_AURA) |
| 3470 | // Aura doesn't care if we switch themes. |
| 3471 | #elif defined(OS_WIN) |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 3472 | ui::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 3473 | if (webview()) |
| 3474 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 3475 | #else // defined(OS_WIN) |
| 3476 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 3477 | NOTIMPLEMENTED(); |
| 3478 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3479 | } |
| 3480 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3481 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 3482 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 3483 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 3484 | } |
| 3485 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 3486 | void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3487 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 3488 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3489 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 3490 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 3491 | ShouldDisplayScrollbars(params.new_size.width(), |
| 3492 | params.new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3493 | } |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3494 | UpdateScrollState(webview()->mainFrame()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3495 | } |
| 3496 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 3497 | RenderWidget::OnResize(params); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 3498 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 3499 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3500 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3501 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3502 | // Notify all instances that we painted. The same caveats apply as for |
| 3503 | // ViewFlushedPaint regarding instances closing themselves, so we take |
| 3504 | // similar precautions. |
| 3505 | PepperPluginSet plugins = active_pepper_instances_; |
| 3506 | for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) { |
| 3507 | if (active_pepper_instances_.find(*i) != active_pepper_instances_.end()) |
| 3508 | (*i)->ViewInitiatedPaint(); |
| 3509 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3510 | #endif |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3511 | } |
| 3512 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3513 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3514 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3515 | // Notify all instances that we flushed. This will call into the plugin, and |
| 3516 | // we it may ask to close itself as a result. This will, in turn, modify our |
| 3517 | // set, possibly invalidating the iterator. So we iterate on a copy that |
| 3518 | // won't change out from under us. |
| 3519 | PepperPluginSet plugins = active_pepper_instances_; |
| 3520 | for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) { |
| 3521 | // The copy above makes sure our iterator is never invalid if some plugins |
| 3522 | // are destroyed. But some plugin may decide to close all of its views in |
| 3523 | // response to a paint in one of them, so we need to make sure each one is |
| 3524 | // still "current" before using it. |
| 3525 | // |
| 3526 | // It's possible that a plugin was destroyed, but another one was created |
| 3527 | // with the same address. In this case, we'll call ViewFlushedPaint on that |
| 3528 | // new plugin. But that's OK for this particular case since we're just |
| 3529 | // notifying all of our instances that the view flushed, and the new one is |
| 3530 | // one of our instances. |
| 3531 | // |
| 3532 | // What about the case where a new one is created in a callback at a new |
| 3533 | // address and we don't issue the callback? We're still OK since this |
| 3534 | // callback is used for flush callbacks and we could not have possibly |
| 3535 | // started a new paint for the new plugin while processing a previous paint |
| 3536 | // for an existing one. |
| 3537 | if (active_pepper_instances_.find(*i) != active_pepper_instances_.end()) |
| 3538 | (*i)->ViewFlushedPaint(); |
| 3539 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3540 | #endif |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 3541 | |
[email protected] | 5b1dec8c | 2012-02-07 04:35:38 | [diff] [blame] | 3542 | // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 3543 | // See crbug.com/112921. |
| 3544 | if (!webview()) |
| 3545 | return; |
| 3546 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3547 | WebFrame* main_frame = webview()->mainFrame(); |
| 3548 | |
| 3549 | // If we have a provisional frame we are between the start and commit stages |
| 3550 | // of loading and we don't want to save stats. |
| 3551 | if (!main_frame->provisionalDataSource()) { |
| 3552 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3553 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 3554 | InternalDocumentStateData* data = |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3555 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 3556 | if (data->did_first_visually_non_empty_layout() && |
| 3557 | !data->did_first_visually_non_empty_paint()) { |
| 3558 | data->set_did_first_visually_non_empty_paint(true); |
| 3559 | Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_, |
| 3560 | page_id_)); |
| 3561 | } |
| 3562 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3563 | // TODO(jar): The following code should all be inside a method, probably in |
| 3564 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3565 | Time now = Time::Now(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3566 | if (document_state->first_paint_time().is_null()) { |
| 3567 | document_state->set_first_paint_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3568 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3569 | if (document_state->first_paint_after_load_time().is_null() && |
| 3570 | !document_state->finish_load_time().is_null()) { |
| 3571 | document_state->set_first_paint_after_load_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3572 | } |
| 3573 | } |
| 3574 | } |
| 3575 | |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 3576 | gfx::Vector2d RenderViewImpl::GetScrollOffset() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 3577 | WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 3578 | return gfx::Vector2d(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 3579 | } |
| 3580 | |
[email protected] | ab6c911 | 2014-02-27 00:20:58 | [diff] [blame] | 3581 | void RenderViewImpl::OnClearFocusedElement() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 3582 | if (webview()) |
[email protected] | ab6c911 | 2014-02-27 00:20:58 | [diff] [blame] | 3583 | webview()->clearFocusedElement(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 3584 | } |
| 3585 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3586 | void RenderViewImpl::OnSetBackground(const SkBitmap& background) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 3587 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3588 | webview()->setIsTransparent(!background.empty()); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 3589 | if (compositor_) |
| 3590 | compositor_->setHasTransparentBackground(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 3591 | |
| 3592 | SetBackground(background); |
| 3593 | } |
| 3594 | |
[email protected] | bfa7124 | 2014-03-27 21:10:24 | [diff] [blame] | 3595 | void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) { |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 3596 | if (accessibility_mode_ == new_mode) |
| 3597 | return; |
| 3598 | accessibility_mode_ = new_mode; |
| 3599 | if (renderer_accessibility_) { |
| 3600 | delete renderer_accessibility_; |
| 3601 | renderer_accessibility_ = NULL; |
| 3602 | } |
[email protected] | 1e558fa | 2014-02-12 23:28:52 | [diff] [blame] | 3603 | if (accessibility_mode_ == AccessibilityModeOff) |
| 3604 | return; |
| 3605 | |
[email protected] | bfa7124 | 2014-03-27 21:10:24 | [diff] [blame] | 3606 | if (accessibility_mode_ & AccessibilityModeFlagFullTree) |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 3607 | renderer_accessibility_ = new RendererAccessibilityComplete(this); |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 3608 | #if !defined(OS_ANDROID) |
[email protected] | 1e558fa | 2014-02-12 23:28:52 | [diff] [blame] | 3609 | else |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 3610 | renderer_accessibility_ = new RendererAccessibilityFocusOnly(this); |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 3611 | #endif |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 3612 | } |
| 3613 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3614 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 3615 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3616 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 3617 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3618 | #if defined(ENABLE_PLUGINS) && defined(OS_MACOSX) |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 3619 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3620 | for (plugin_it = plugin_delegates_.begin(); |
| 3621 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3622 | (*plugin_it)->SetWindowFocus(active); |
| 3623 | } |
| 3624 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 3625 | } |
| 3626 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 3627 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3628 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3629 | #if defined(ENABLE_PLUGINS) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 3630 | // Inform plugins that their container has changed visibility. |
| 3631 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3632 | for (plugin_it = plugin_delegates_.begin(); |
| 3633 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3634 | (*plugin_it)->SetContainerVisibility(visible); |
| 3635 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3636 | #endif |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 3637 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3638 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3639 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 3640 | const gfx::Rect& view_frame) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3641 | #if defined(ENABLE_PLUGINS) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3642 | // Inform plugins that their window's frame has changed. |
| 3643 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3644 | for (plugin_it = plugin_delegates_.begin(); |
| 3645 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3646 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 3647 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3648 | #endif |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3649 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 3650 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3651 | void RenderViewImpl::OnPluginImeCompositionCompleted(const base::string16& text, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3652 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 3653 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 3654 | // applies to it or not, so inform all the delegates. |
| 3655 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3656 | for (plugin_it = plugin_delegates_.begin(); |
| 3657 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 3658 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 3659 | } |
| 3660 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 3661 | #endif // OS_MACOSX |
| 3662 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3663 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 3664 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 3665 | WebView* doomed = webview(); |
| 3666 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 3667 | g_view_map.Get().erase(doomed); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 3668 | g_routing_id_view_map.Get().erase(routing_id_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 3669 | } |
| 3670 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3671 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 3672 | ClearEditCommands(); |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 3673 | } |
| 3674 | |
[email protected] | 72aee84 | 2014-02-20 19:41:41 | [diff] [blame] | 3675 | void RenderViewImpl::WillProcessUserGesture() { |
| 3676 | FOR_EACH_OBSERVER( |
| 3677 | RenderViewObserver, observers_, WillProcessUserGesture()); |
| 3678 | } |
| 3679 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3680 | bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent& event) { |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 3681 | possible_drag_event_info_.event_source = |
| 3682 | ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 3683 | possible_drag_event_info_.event_location = |
| 3684 | gfx::Point(event.globalX, event.globalY); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3685 | |
| 3686 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3687 | // This method is called for every mouse event that the render view receives. |
| 3688 | // And then the mouse event is forwarded to WebKit, which dispatches it to the |
| 3689 | // event target. Potentially a Pepper plugin will receive the event. |
| 3690 | // In order to tell whether a plugin gets the last mouse event and which it |
| 3691 | // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets |
| 3692 | // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 3693 | // |pepper_last_mouse_event_target_|. |
| 3694 | pepper_last_mouse_event_target_ = NULL; |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3695 | #endif |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 3696 | |
| 3697 | // If the mouse is locked, only the current owner of the mouse lock can |
| 3698 | // process mouse events. |
| 3699 | return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 3700 | } |
| 3701 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 3702 | bool RenderViewImpl::WillHandleGestureEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3703 | const blink::WebGestureEvent& event) { |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 3704 | possible_drag_event_info_.event_source = |
| 3705 | ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH; |
| 3706 | possible_drag_event_info_.event_location = |
| 3707 | gfx::Point(event.globalX, event.globalY); |
| 3708 | return false; |
| 3709 | } |
| 3710 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 3711 | void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3712 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3713 | } |
| 3714 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3715 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 3716 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 3717 | } |
| 3718 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 3719 | bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const { |
| 3720 | if (!webview()) |
| 3721 | return false; |
| 3722 | return webview()->hasTouchEventHandlersAt(point); |
| 3723 | } |
| 3724 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3725 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3726 | RenderWidget::OnWasHidden(); |
| 3727 | |
[email protected] | 68877c28 | 2013-09-20 05:52:42 | [diff] [blame] | 3728 | #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 3729 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 3730 | SuspendDevices(true); |
| 3731 | #endif |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 3732 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 3733 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 3734 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3735 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3736 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3737 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 3738 | i != active_pepper_instances_.end(); ++i) |
| 3739 | (*i)->PageVisibilityChanged(false); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 3740 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3741 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 3742 | // Inform NPAPI plugins that their container is no longer visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3743 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3744 | for (plugin_it = plugin_delegates_.begin(); |
| 3745 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3746 | (*plugin_it)->SetContainerVisibility(false); |
| 3747 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3748 | #endif // OS_MACOSX |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3749 | #endif // ENABLE_PLUGINS |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3750 | } |
| 3751 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 3752 | void RenderViewImpl::OnWasShown(bool needs_repainting) { |
| 3753 | RenderWidget::OnWasShown(needs_repainting); |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3754 | |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 3755 | #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 3756 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 3757 | SuspendDevices(false); |
| 3758 | #endif |
| 3759 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 3760 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 3761 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3762 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3763 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3764 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 3765 | i != active_pepper_instances_.end(); ++i) |
| 3766 | (*i)->PageVisibilityChanged(true); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 3767 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3768 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 3769 | // Inform NPAPI plugins that their container is now visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3770 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3771 | for (plugin_it = plugin_delegates_.begin(); |
| 3772 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3773 | (*plugin_it)->SetContainerVisibility(true); |
| 3774 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 3775 | #endif // OS_MACOSX |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3776 | #endif // ENABLE_PLUGINS |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3777 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3778 | |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 3779 | GURL RenderViewImpl::GetURLForGraphicsContext3D() { |
| 3780 | DCHECK(webview()); |
| 3781 | if (webview()->mainFrame()) |
| 3782 | return GURL(webview()->mainFrame()->document().url()); |
| 3783 | else |
| 3784 | return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 3785 | } |
| 3786 | |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 3787 | bool RenderViewImpl::ForceCompositingModeEnabled() { |
| 3788 | return webkit_preferences_.force_compositing_mode; |
| 3789 | } |
| 3790 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3791 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3792 | RenderWidget::OnSetFocus(enable); |
| 3793 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3794 | #if defined(ENABLE_PLUGINS) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 3795 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 3796 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3797 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3798 | for (plugin_it = plugin_delegates_.begin(); |
| 3799 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 3800 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 3801 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 3802 | // activation state to change just like a call to setIsActive. |
| 3803 | if (enable) |
| 3804 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 3805 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 3806 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3807 | } |
| 3808 | } |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3809 | // Notify all Pepper plugins. |
| 3810 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 3811 | i != active_pepper_instances_.end(); ++i) |
| 3812 | (*i)->SetContentAreaFocus(enable); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3813 | #endif |
[email protected] | 32103299 | 2012-11-08 01:01:27 | [diff] [blame] | 3814 | // Notify all BrowserPlugins of the RenderView's focus state. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 3815 | if (browser_plugin_manager_.get()) |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 3816 | browser_plugin_manager_->UpdateFocusState(); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3817 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3818 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3819 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3820 | const base::string16& text, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3821 | const std::vector<blink::WebCompositionUnderline>& underlines, |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3822 | int selection_start, |
| 3823 | int selection_end) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3824 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3825 | if (focused_pepper_plugin_) { |
| 3826 | focused_pepper_plugin_->render_frame()->OnImeSetComposition( |
[email protected] | 7a4e253 | 2013-12-02 21:30:02 | [diff] [blame] | 3827 | text, underlines, selection_start, selection_end); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3828 | return; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3829 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3830 | |
| 3831 | #if defined(OS_WIN) |
| 3832 | // When a plug-in has focus, we create platform-specific IME data used by |
| 3833 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 3834 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 3835 | // instance ID is the same one as the specified ID.) |
| 3836 | if (focused_plugin_id_ >= 0) { |
| 3837 | std::vector<int> clauses; |
| 3838 | std::vector<int> target; |
| 3839 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 3840 | clauses.push_back(underlines[i].startOffset); |
| 3841 | clauses.push_back(underlines[i].endOffset); |
| 3842 | if (underlines[i].thick) { |
| 3843 | target.clear(); |
| 3844 | target.push_back(underlines[i].startOffset); |
| 3845 | target.push_back(underlines[i].endOffset); |
| 3846 | } |
| 3847 | } |
| 3848 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 3849 | for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) { |
| 3850 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 3851 | focused_plugin_id_); |
| 3852 | } |
| 3853 | return; |
| 3854 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3855 | #endif // OS_WIN |
| 3856 | #endif // ENABLE_PLUGINS |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3857 | RenderWidget::OnImeSetComposition(text, |
| 3858 | underlines, |
| 3859 | selection_start, |
| 3860 | selection_end); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3861 | } |
| 3862 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 3863 | void RenderViewImpl::OnImeConfirmComposition( |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3864 | const base::string16& text, |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 3865 | const gfx::Range& replacement_range, |
| 3866 | bool keep_selection) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3867 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3868 | if (focused_pepper_plugin_) { |
| 3869 | focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( |
[email protected] | 7a4e253 | 2013-12-02 21:30:02 | [diff] [blame] | 3870 | text, replacement_range, keep_selection); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3871 | return; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3872 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3873 | #if defined(OS_WIN) |
| 3874 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 3875 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 3876 | // it to WebKit to prevent WebKit from controlling IMEs. |
| 3877 | // TODO(thakis): Honor |replacement_range| for plugins? |
| 3878 | if (focused_plugin_id_ >= 0) { |
| 3879 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 3880 | for (it = plugin_delegates_.begin(); |
| 3881 | it != plugin_delegates_.end(); ++it) { |
| 3882 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 3883 | } |
| 3884 | return; |
| 3885 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3886 | #endif // OS_WIN |
| 3887 | #endif // ENABLE_PLUGINS |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3888 | if (replacement_range.IsValid() && webview()) { |
| 3889 | // Select the text in |replacement_range|, it will then be replaced by |
| 3890 | // text added by the call to RenderWidget::OnImeConfirmComposition(). |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 3891 | if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3892 | WebRange webrange = WebRange::fromDocumentRange( |
| 3893 | frame, replacement_range.start(), replacement_range.length()); |
| 3894 | if (!webrange.isNull()) |
| 3895 | frame->selectRange(webrange); |
| 3896 | } |
| 3897 | } |
| 3898 | RenderWidget::OnImeConfirmComposition(text, |
| 3899 | replacement_range, |
| 3900 | keep_selection); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3901 | } |
| 3902 | |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 3903 | void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) { |
| 3904 | RenderWidget::SetDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 3905 | if (webview()) { |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 3906 | webview()->setDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 3907 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 3908 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 3909 | webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled( |
| 3910 | ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_)); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 3911 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 3912 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 3913 | webview()->settings()-> |
| 3914 | setAcceleratedCompositingForFixedRootBackgroundEnabled( |
| 3915 | ShouldUseAcceleratedFixedRootBackground(device_scale_factor_)); |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 3916 | webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled( |
| 3917 | ShouldUseAcceleratedCompositingForScrollableFrames( |
| 3918 | device_scale_factor_)); |
| 3919 | webview()->settings()->setCompositedScrollingForFramesEnabled( |
| 3920 | ShouldUseCompositedScrollingForFrames(device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 3921 | } |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 3922 | if (auto_resize_mode_) |
| 3923 | AutoResizeCompositor(); |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 3924 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 3925 | if (browser_plugin_manager_.get()) |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 3926 | browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_); |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 3927 | } |
| 3928 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3929 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3930 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3931 | if (focused_pepper_plugin_) |
| 3932 | return focused_pepper_plugin_->text_input_type(); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3933 | #endif |
| 3934 | return RenderWidget::GetTextInputType(); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 3935 | } |
| 3936 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 3937 | void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3938 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3939 | if (focused_pepper_plugin_) { |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 3940 | // TODO(kinaba) http://crbug.com/101101 |
| 3941 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 3942 | // use the caret position as an empty range for now. It will be updated |
| 3943 | // after Pepper API equips features related to surrounding text retrieval. |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3944 | gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds(); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 3945 | *start = caret; |
| 3946 | *end = caret; |
| 3947 | return; |
| 3948 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3949 | #endif |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 3950 | RenderWidget::GetSelectionBounds(start, end); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 3951 | } |
| 3952 | |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 3953 | #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA) |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 3954 | void RenderViewImpl::GetCompositionCharacterBounds( |
| 3955 | std::vector<gfx::Rect>* bounds) { |
| 3956 | DCHECK(bounds); |
| 3957 | bounds->clear(); |
| 3958 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3959 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3960 | if (focused_pepper_plugin_) { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 3961 | return; |
| 3962 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3963 | #endif |
| 3964 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 3965 | if (!webview()) |
| 3966 | return; |
| 3967 | size_t start_offset = 0; |
| 3968 | size_t character_count = 0; |
| 3969 | if (!webview()->compositionRange(&start_offset, &character_count)) |
| 3970 | return; |
| 3971 | if (character_count == 0) |
| 3972 | return; |
| 3973 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3974 | blink::WebFrame* frame = webview()->focusedFrame(); |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 3975 | if (!frame) |
| 3976 | return; |
| 3977 | |
| 3978 | bounds->reserve(character_count); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3979 | blink::WebRect webrect; |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 3980 | for (size_t i = 0; i < character_count; ++i) { |
| 3981 | if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { |
| 3982 | DLOG(ERROR) << "Could not retrieve character rectangle at " << i; |
| 3983 | bounds->clear(); |
| 3984 | return; |
| 3985 | } |
| 3986 | bounds->push_back(webrect); |
| 3987 | } |
| 3988 | } |
| 3989 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 3990 | void RenderViewImpl::GetCompositionRange(gfx::Range* range) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3991 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3992 | if (focused_pepper_plugin_) { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 3993 | return; |
| 3994 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3995 | #endif |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 3996 | RenderWidget::GetCompositionRange(range); |
| 3997 | } |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 3998 | #endif |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 3999 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4000 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4001 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 4002 | if (focused_pepper_plugin_) |
| 4003 | return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents(); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4004 | #endif |
| 4005 | return true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4006 | } |
| 4007 | |
[email protected] | 3300477 | 2013-11-12 09:49:23 | [diff] [blame] | 4008 | void RenderViewImpl::InstrumentWillBeginFrame(int frame_id) { |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 4009 | if (!webview()) |
| 4010 | return; |
| 4011 | if (!webview()->devToolsAgent()) |
| 4012 | return; |
[email protected] | 3300477 | 2013-11-12 09:49:23 | [diff] [blame] | 4013 | webview()->devToolsAgent()->didBeginFrame(frame_id); |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | void RenderViewImpl::InstrumentDidBeginFrame() { |
| 4017 | if (!webview()) |
| 4018 | return; |
| 4019 | if (!webview()->devToolsAgent()) |
| 4020 | return; |
| 4021 | // TODO(jamesr/caseq): Decide if this needs to be renamed. |
| 4022 | webview()->devToolsAgent()->didComposite(); |
| 4023 | } |
| 4024 | |
| 4025 | void RenderViewImpl::InstrumentDidCancelFrame() { |
| 4026 | if (!webview()) |
| 4027 | return; |
| 4028 | if (!webview()->devToolsAgent()) |
| 4029 | return; |
| 4030 | webview()->devToolsAgent()->didCancelFrame(); |
| 4031 | } |
| 4032 | |
| 4033 | void RenderViewImpl::InstrumentWillComposite() { |
| 4034 | if (!webview()) |
| 4035 | return; |
| 4036 | if (!webview()->devToolsAgent()) |
| 4037 | return; |
| 4038 | webview()->devToolsAgent()->willComposite(); |
| 4039 | } |
| 4040 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 4041 | void RenderViewImpl::SetScreenMetricsEmulationParameters( |
[email protected] | 7f99fc2 | 2013-11-08 14:05:58 | [diff] [blame] | 4042 | float device_scale_factor, |
| 4043 | const gfx::Point& root_layer_offset, |
| 4044 | float root_layer_scale) { |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 4045 | if (webview()) { |
| 4046 | webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor); |
[email protected] | 7f99fc2 | 2013-11-08 14:05:58 | [diff] [blame] | 4047 | webview()->setRootLayerTransform( |
| 4048 | blink::WebSize(root_layer_offset.x(), root_layer_offset.y()), |
| 4049 | root_layer_scale); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 4050 | } |
| 4051 | } |
| 4052 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4053 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4054 | const FileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4055 | WebFileChooserCompletion* completion) { |
| 4056 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 4057 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 4058 | // This sanity check prevents too many file choose requests from getting |
| 4059 | // queued which could DoS the user. Getting these is most likely a |
| 4060 | // programming error (there are many ways to DoS the user so it's not |
| 4061 | // considered a "real" security check), either in JS requesting many file |
| 4062 | // choosers to pop up, or in a plugin. |
| 4063 | // |
| 4064 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 4065 | // a file picker, which will address this issue in a better way. |
| 4066 | return false; |
| 4067 | } |
| 4068 | |
| 4069 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 4070 | new PendingFileChooser(params, completion))); |
| 4071 | if (file_chooser_completions_.size() == 1) { |
| 4072 | // Actually show the browse dialog when this is the first request. |
| 4073 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 4074 | } |
| 4075 | return true; |
| 4076 | } |
| 4077 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4078 | blink::WebGeolocationClient* RenderViewImpl::geolocationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4079 | if (!geolocation_dispatcher_) |
| 4080 | geolocation_dispatcher_ = new GeolocationDispatcher(this); |
| 4081 | return geolocation_dispatcher_; |
[email protected] | 7e0c470 | 2010-12-31 14:06:25 | [diff] [blame] | 4082 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4083 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4084 | blink::WebSpeechInputController* RenderViewImpl::speechInputController( |
| 4085 | blink::WebSpeechInputListener* listener) { |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 4086 | #if defined(ENABLE_INPUT_SPEECH) |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 4087 | if (!input_tag_speech_dispatcher_) |
| 4088 | input_tag_speech_dispatcher_ = |
| 4089 | new InputTagSpeechDispatcher(this, listener); |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 4090 | #endif |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 4091 | return input_tag_speech_dispatcher_; |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 4092 | } |
| 4093 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4094 | blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 4095 | if (!speech_recognition_dispatcher_) |
| 4096 | speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 4097 | return speech_recognition_dispatcher_; |
| 4098 | } |
| 4099 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4100 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 4101 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4102 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 4103 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 4104 | // different). |
| 4105 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 4106 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4107 | int minimum_percent = static_cast<int>( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 4108 | ZoomLevelToZoomFactor(minimum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4109 | int maximum_percent = static_cast<int>( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 4110 | ZoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4111 | |
| 4112 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 4113 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 4114 | } |
| 4115 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4116 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4117 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 4118 | float zoom_level = webview()->zoomLevel(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 4119 | |
| 4120 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged()); |
| 4121 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4122 | // Tell the browser which url got zoomed so it can update the menu and the |
| 4123 | // saved values if necessary |
| 4124 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 4125 | routing_id_, zoom_level, remember, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4126 | GURL(webview()->mainFrame()->document().url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4127 | } |
| 4128 | |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 4129 | double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const { |
| 4130 | return ZoomLevelToZoomFactor(zoom_level); |
| 4131 | } |
| 4132 | |
| 4133 | double RenderViewImpl::zoomFactorToZoomLevel(double factor) const { |
| 4134 | return ZoomFactorToZoomLevel(factor); |
| 4135 | } |
| 4136 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4137 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
[email protected] | 5958c6bc | 2014-01-22 14:48:05 | [diff] [blame] | 4138 | const WebURL& base_url, |
| 4139 | const WebURL& url, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4140 | const WebString& title) { |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 4141 | bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 4142 | GURL base(base_url); |
[email protected] | 5958c6bc | 2014-01-22 14:48:05 | [diff] [blame] | 4143 | GURL absolute_url = base.Resolve(base::UTF16ToUTF8(url.string())); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 4144 | if (base.GetOrigin() != absolute_url.GetOrigin()) { |
| 4145 | return; |
| 4146 | } |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 4147 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 4148 | base::UTF16ToUTF8(scheme), |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 4149 | absolute_url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 4150 | title, |
| 4151 | user_gesture)); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 4152 | } |
| 4153 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4154 | blink::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
| 4155 | blink::WebPageVisibilityState current_state = is_hidden() ? |
| 4156 | blink::WebPageVisibilityStateHidden : |
| 4157 | blink::WebPageVisibilityStateVisible; |
| 4158 | blink::WebPageVisibilityState override_state = current_state; |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 4159 | // TODO(jam): move this method to WebFrameClient. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4160 | if (GetContentClient()->renderer()-> |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 4161 | ShouldOverridePageVisibilityState(main_render_frame_.get(), |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 4162 | &override_state)) |
| 4163 | return override_state; |
| 4164 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 4165 | } |
| 4166 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4167 | blink::WebUserMediaClient* RenderViewImpl::userMediaClient() { |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 4168 | // This can happen in tests, in which case it's OK to return NULL. |
| 4169 | if (!InitializeMediaStreamClient()) |
| 4170 | return NULL; |
| 4171 | |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 4172 | return web_user_media_client_; |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4173 | } |
| 4174 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4175 | blink::WebMIDIClient* RenderViewImpl::webMIDIClient() { |
[email protected] | 7b77f6cb | 2013-07-25 16:23:14 | [diff] [blame] | 4176 | if (!midi_dispatcher_) |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 4177 | midi_dispatcher_ = new MidiDispatcher(this); |
[email protected] | 7b77f6cb | 2013-07-25 16:23:14 | [diff] [blame] | 4178 | return midi_dispatcher_; |
| 4179 | } |
| 4180 | |
[email protected] | e1c17416 | 2014-04-08 15:39:31 | [diff] [blame] | 4181 | blink::WebPushClient* RenderViewImpl::webPushClient() { |
| 4182 | if (!push_messaging_dispatcher_) |
| 4183 | push_messaging_dispatcher_ = new PushMessagingDispatcher(this); |
| 4184 | return push_messaging_dispatcher_; |
| 4185 | } |
| 4186 | |
[email protected] | a0629af9 | 2012-08-08 00:39:37 | [diff] [blame] | 4187 | void RenderViewImpl::draggableRegionsChanged() { |
| 4188 | FOR_EACH_OBSERVER( |
| 4189 | RenderViewObserver, |
| 4190 | observers_, |
| 4191 | DraggableRegionsChanged(webview()->mainFrame())); |
| 4192 | } |
| 4193 | |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4194 | WebMediaPlayer* RenderViewImpl::CreateWebMediaPlayerForMediaStream( |
| 4195 | WebFrame* frame, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4196 | const blink::WebURL& url, |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4197 | WebMediaPlayerClient* client) { |
| 4198 | #if defined(ENABLE_WEBRTC) |
| 4199 | if (!InitializeMediaStreamClient()) { |
| 4200 | LOG(ERROR) << "Failed to initialize MediaStreamClient"; |
| 4201 | return NULL; |
| 4202 | } |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4203 | if (media_stream_client_->IsMediaStream(url)) { |
| 4204 | #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
| 4205 | bool found_neon = |
| 4206 | (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; |
| 4207 | UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon); |
| 4208 | #endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
| 4209 | return new WebMediaPlayerMS(frame, client, AsWeakPtr(), |
| 4210 | media_stream_client_, new RenderMediaLog()); |
| 4211 | } |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4212 | #endif // defined(ENABLE_WEBRTC) |
| 4213 | return NULL; |
| 4214 | } |
| 4215 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 4216 | #if defined(OS_ANDROID) |
| 4217 | WebContentDetectionResult RenderViewImpl::detectContentAround( |
| 4218 | const WebHitTestResult& touch_hit) { |
| 4219 | DCHECK(!touch_hit.isNull()); |
| 4220 | DCHECK(!touch_hit.node().isNull()); |
| 4221 | DCHECK(touch_hit.node().isTextNode()); |
| 4222 | |
| 4223 | // Process the position with all the registered content detectors until |
| 4224 | // a match is found. Priority is provided by their relative order. |
| 4225 | for (ContentDetectorList::const_iterator it = content_detectors_.begin(); |
| 4226 | it != content_detectors_.end(); ++it) { |
| 4227 | ContentDetector::Result content = (*it)->FindTappedContent(touch_hit); |
| 4228 | if (content.valid) { |
| 4229 | return WebContentDetectionResult(content.content_boundaries, |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 4230 | base::UTF8ToUTF16(content.text), content.intent_url); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 4231 | } |
| 4232 | } |
| 4233 | return WebContentDetectionResult(); |
| 4234 | } |
| 4235 | |
| 4236 | void RenderViewImpl::scheduleContentIntent(const WebURL& intent) { |
| 4237 | // Introduce a short delay so that the user can notice the content. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 4238 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 4239 | FROM_HERE, |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 4240 | base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, |
| 4241 | AsWeakPtr(), |
| 4242 | intent, |
| 4243 | expected_content_intent_id_), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 4244 | base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); |
| 4245 | } |
| 4246 | |
| 4247 | void RenderViewImpl::cancelScheduledContentIntents() { |
| 4248 | ++expected_content_intent_id_; |
| 4249 | } |
| 4250 | |
| 4251 | void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, |
| 4252 | size_t request_id) { |
| 4253 | if (request_id != expected_content_intent_id_) |
| 4254 | return; |
| 4255 | |
| 4256 | // Remove the content highlighting if any. |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 4257 | scheduleComposite(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 4258 | |
| 4259 | if (!intent.is_empty()) |
| 4260 | Send(new ViewHostMsg_StartContentIntent(routing_id_, intent)); |
| 4261 | } |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 4262 | |
| 4263 | bool RenderViewImpl::openDateTimeChooser( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4264 | const blink::WebDateTimeChooserParams& params, |
| 4265 | blink::WebDateTimeChooserCompletion* completion) { |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 4266 | // JavaScript may try to open a date time chooser while one is already open. |
| 4267 | if (date_time_picker_client_) |
| 4268 | return false; |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 4269 | date_time_picker_client_.reset( |
| 4270 | new RendererDateTimePicker(this, params, completion)); |
| 4271 | return date_time_picker_client_->Open(); |
| 4272 | } |
| 4273 | |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 4274 | void RenderViewImpl::DismissDateTimeDialog() { |
| 4275 | DCHECK(date_time_picker_client_); |
| 4276 | date_time_picker_client_.reset(NULL); |
| 4277 | } |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 4278 | |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4279 | WebMediaPlayer* RenderViewImpl::CreateAndroidWebMediaPlayer( |
| 4280 | WebFrame* frame, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4281 | const blink::WebURL& url, |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4282 | WebMediaPlayerClient* client) { |
| 4283 | GpuChannelHost* gpu_channel_host = |
| 4284 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
| 4285 | CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
| 4286 | if (!gpu_channel_host) { |
| 4287 | LOG(ERROR) << "Failed to establish GPU channel for media player"; |
| 4288 | return NULL; |
| 4289 | } |
| 4290 | |
[email protected] | 5448f9b | 2014-04-01 15:21:20 | [diff] [blame] | 4291 | scoped_refptr<StreamTextureFactory> stream_texture_factory; |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4292 | if (UsingSynchronousRendererCompositor()) { |
| 4293 | SynchronousCompositorFactory* factory = |
| 4294 | SynchronousCompositorFactory::GetInstance(); |
| 4295 | stream_texture_factory = factory->CreateStreamTextureFactory(routing_id_); |
| 4296 | } else { |
[email protected] | 9cdd715 | 2014-01-14 14:20:43 | [diff] [blame] | 4297 | scoped_refptr<webkit::gpu::ContextProviderWebContext> context_provider = |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4298 | RenderThreadImpl::current()->SharedMainThreadContextProvider(); |
| 4299 | |
| 4300 | if (!context_provider.get()) { |
| 4301 | LOG(ERROR) << "Failed to get context3d for media player"; |
| 4302 | return NULL; |
| 4303 | } |
| 4304 | |
[email protected] | 5448f9b | 2014-04-01 15:21:20 | [diff] [blame] | 4305 | stream_texture_factory = StreamTextureFactoryImpl::Create( |
| 4306 | context_provider, gpu_channel_host, routing_id_); |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4307 | } |
| 4308 | |
[email protected] | 693f63c | 2014-01-17 06:52:19 | [diff] [blame] | 4309 | return new WebMediaPlayerAndroid( |
[email protected] | 1dd0bb75 | 2014-02-01 01:16:26 | [diff] [blame] | 4310 | frame, |
| 4311 | client, |
| 4312 | AsWeakPtr(), |
| 4313 | media_player_manager_, |
[email protected] | 5448f9b | 2014-04-01 15:21:20 | [diff] [blame] | 4314 | stream_texture_factory, |
[email protected] | 1dd0bb75 | 2014-02-01 01:16:26 | [diff] [blame] | 4315 | RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(), |
| 4316 | new RenderMediaLog()); |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 4317 | } |
| 4318 | |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 4319 | #endif // defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 4320 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 4321 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4322 | void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) { |
[email protected] | 8ff26a8c | 2014-03-24 02:59:40 | [diff] [blame] | 4323 | if (external_popup_menu_ == NULL) |
[email protected] | 68dc3ba | 2010-12-06 21:43:15 | [diff] [blame] | 4324 | return; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 4325 | external_popup_menu_->DidSelectItem(selected_index); |
| 4326 | external_popup_menu_.reset(); |
| 4327 | } |
| 4328 | #endif |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 4329 | |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 4330 | #if defined(OS_ANDROID) |
| 4331 | void RenderViewImpl::OnSelectPopupMenuItems( |
| 4332 | bool canceled, |
| 4333 | const std::vector<int>& selected_indices) { |
| 4334 | // It is possible to receive more than one of these calls if the user presses |
| 4335 | // a select faster than it takes for the show-select-popup IPC message to make |
| 4336 | // it to the browser UI thread. Ignore the extra-messages. |
| 4337 | // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 4338 | if (!external_popup_menu_) |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 4339 | return; |
| 4340 | |
| 4341 | external_popup_menu_->DidSelectItems(canceled, selected_indices); |
| 4342 | external_popup_menu_.reset(); |
| 4343 | } |
| 4344 | #endif |
| 4345 | |
[email protected] | 5390786 | 2014-03-25 15:42:40 | [diff] [blame] | 4346 | #if defined(OS_MACOSX) || defined(OS_ANDROID) |
[email protected] | 8ff26a8c | 2014-03-24 02:59:40 | [diff] [blame] | 4347 | void RenderViewImpl::DidHideExternalPopupMenu() { |
| 4348 | // We need to clear external_popup_menu_ as soon as ExternalPopupMenu::close |
| 4349 | // is called. Otherwise, createExternalPopupMenu() for new popup will fail. |
| 4350 | external_popup_menu_.reset(); |
| 4351 | } |
[email protected] | 5390786 | 2014-03-25 15:42:40 | [diff] [blame] | 4352 | #endif |
[email protected] | 8ff26a8c | 2014-03-24 02:59:40 | [diff] [blame] | 4353 | |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 4354 | void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 4355 | context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU; |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 4356 | touch_editing_context_menu_location_ = location; |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 4357 | if (webview()) |
| 4358 | webview()->showContextMenu(); |
| 4359 | } |
| 4360 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4361 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 4362 | if (!webview()) |
| 4363 | return; |
| 4364 | WebFrame* main_frame = webview()->mainFrame(); |
| 4365 | if (!main_frame) |
| 4366 | return; |
| 4367 | main_frame->enableViewSourceMode(true); |
| 4368 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 4369 | |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 4370 | void RenderViewImpl::OnDisownOpener() { |
| 4371 | if (!webview()) |
| 4372 | return; |
| 4373 | |
| 4374 | WebFrame* main_frame = webview()->mainFrame(); |
| 4375 | if (main_frame && main_frame->opener()) |
| 4376 | main_frame->setOpener(NULL); |
| 4377 | } |
| 4378 | |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 4379 | #if defined(OS_ANDROID) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4380 | bool RenderViewImpl::didTapMultipleTargets( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 4381 | const blink::WebGestureEvent& event, |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4382 | const WebVector<WebRect>& target_rects) { |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 4383 | // Never show a disambiguation popup when accessibility is enabled, |
| 4384 | // as this interferes with "touch exploration". |
[email protected] | 1e558fa | 2014-02-12 23:28:52 | [diff] [blame] | 4385 | bool matchesAccessibilityModeComplete = |
| 4386 | (accessibility_mode_ & AccessibilityModeComplete) == |
| 4387 | AccessibilityModeComplete; |
| 4388 | if (matchesAccessibilityModeComplete) |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 4389 | return false; |
| 4390 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4391 | gfx::Rect finger_rect( |
| 4392 | event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2, |
| 4393 | event.data.tap.width, event.data.tap.height); |
| 4394 | gfx::Rect zoom_rect; |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 4395 | float new_total_scale = |
| 4396 | DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( |
| 4397 | finger_rect, target_rects, GetSize(), |
| 4398 | gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(), |
| 4399 | device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect); |
| 4400 | if (!new_total_scale) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4401 | return false; |
| 4402 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 4403 | bool handled = false; |
| 4404 | switch (renderer_preferences_.tap_multiple_targets_strategy) { |
| 4405 | case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM: |
| 4406 | handled = webview()->zoomToMultipleTargetsRect(zoom_rect); |
| 4407 | break; |
| 4408 | case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: { |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 4409 | gfx::Size canvas_size = |
| 4410 | gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale)); |
| 4411 | TransportDIB* transport_dib = NULL; |
| 4412 | { |
| 4413 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 4414 | RenderProcess::current()->GetDrawingCanvas(&transport_dib, |
| 4415 | gfx::Rect(canvas_size))); |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 4416 | if (!canvas) { |
| 4417 | handled = false; |
| 4418 | break; |
| 4419 | } |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4420 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 4421 | // TODO(trchen): Cleanup the device scale factor mess. |
| 4422 | // device scale will be applied in WebKit |
| 4423 | // --> zoom_rect doesn't include device scale, |
| 4424 | // but WebKit will still draw on zoom_rect * device_scale_factor_ |
| 4425 | canvas->scale(new_total_scale / device_scale_factor_, |
| 4426 | new_total_scale / device_scale_factor_); |
| 4427 | canvas->translate(-zoom_rect.x() * device_scale_factor_, |
| 4428 | -zoom_rect.y() * device_scale_factor_); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4429 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 4430 | webwidget_->paint( |
| 4431 | canvas.get(), |
| 4432 | zoom_rect, |
| 4433 | WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent); |
| 4434 | } |
| 4435 | |
| 4436 | gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect( |
| 4437 | ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect))); |
| 4438 | Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_, |
| 4439 | physical_window_zoom_rect, |
| 4440 | canvas_size, |
| 4441 | transport_dib->id())); |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 4442 | handled = true; |
| 4443 | break; |
| 4444 | } |
| 4445 | case TAP_MULTIPLE_TARGETS_STRATEGY_NONE: |
| 4446 | // No-op. |
| 4447 | break; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4448 | } |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 4449 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 4450 | return handled; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4451 | } |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 4452 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4453 | |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 4454 | unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const { |
| 4455 | return history_list_length_; |
| 4456 | } |
| 4457 | |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 4458 | void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) { |
| 4459 | if (enable) { |
| 4460 | if (has_focus()) |
| 4461 | return; |
| 4462 | OnSetActive(true); |
| 4463 | OnSetFocus(true); |
| 4464 | } else { |
| 4465 | if (!has_focus()) |
| 4466 | return; |
| 4467 | OnSetFocus(false); |
| 4468 | OnSetActive(false); |
| 4469 | } |
| 4470 | } |
| 4471 | |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 4472 | void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) { |
[email protected] | b54fe45 | 2013-06-07 14:01:53 | [diff] [blame] | 4473 | ViewMsg_Resize_Params params; |
| 4474 | params.screen_info = screen_info_; |
| 4475 | params.screen_info.deviceScaleFactor = factor; |
| 4476 | params.new_size = size(); |
| 4477 | params.physical_backing_size = |
| 4478 | gfx::ToCeiledSize(gfx::ScaleSize(size(), factor)); |
| 4479 | params.overdraw_bottom_height = 0.f; |
| 4480 | params.resizer_rect = WebRect(); |
| 4481 | params.is_fullscreen = is_fullscreen(); |
| 4482 | OnResize(params); |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 4483 | } |
| 4484 | |
[email protected] | 9265016 | 2013-10-30 03:31:02 | [diff] [blame] | 4485 | void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) { |
| 4486 | gfx::Rect new_position(rootWindowRect().x, |
| 4487 | rootWindowRect().y, |
| 4488 | new_size.width(), |
| 4489 | new_size.height()); |
| 4490 | ResizeSynchronously(new_position); |
| 4491 | } |
| 4492 | |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 4493 | void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) { |
| 4494 | resizing_mode_selector_->set_is_synchronous_mode(enable); |
| 4495 | } |
| 4496 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 4497 | void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size, |
| 4498 | const gfx::Size& max_size) { |
| 4499 | OnEnableAutoResize(min_size, max_size); |
| 4500 | } |
| 4501 | |
| 4502 | void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) { |
| 4503 | OnDisableAutoResize(new_size); |
| 4504 | } |
| 4505 | |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 4506 | void RenderViewImpl::SetMediaStreamClientForTesting( |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 4507 | MediaStreamClient* media_stream_client) { |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 4508 | DCHECK(!media_stream_client_); |
| 4509 | DCHECK(!web_user_media_client_); |
| 4510 | media_stream_client_ = media_stream_client; |
| 4511 | } |
| 4512 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4513 | void RenderViewImpl::OnReleaseDisambiguationPopupDIB( |
| 4514 | TransportDIB::Handle dib_handle) { |
| 4515 | TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
| 4516 | RenderProcess::current()->ReleaseTransportDIB(dib); |
| 4517 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4518 | |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 4519 | void RenderViewImpl::DidCommitCompositorFrame() { |
| 4520 | RenderWidget::DidCommitCompositorFrame(); |
| 4521 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame()); |
| 4522 | } |
| 4523 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 4524 | void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) { |
| 4525 | if (!urls.empty()) |
| 4526 | Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls)); |
| 4527 | } |
| 4528 | |
| 4529 | void RenderViewImpl::DidStopLoadingIcons() { |
| 4530 | int icon_types = WebIconURL::TypeFavicon; |
| 4531 | if (TouchEnabled()) |
| 4532 | icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
| 4533 | |
| 4534 | WebVector<WebIconURL> icon_urls = |
| 4535 | webview()->mainFrame()->iconURLs(icon_types); |
| 4536 | |
| 4537 | std::vector<FaviconURL> urls; |
| 4538 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 4539 | WebURL url = icon_urls[i].iconURL(); |
[email protected] | f34ac13 | 2014-03-20 23:02:05 | [diff] [blame] | 4540 | std::vector<gfx::Size> sizes(icon_urls[i].sizes().size()); |
| 4541 | ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 4542 | if (!url.isEmpty()) |
[email protected] | f34ac13 | 2014-03-20 23:02:05 | [diff] [blame] | 4543 | urls.push_back( |
| 4544 | FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 4545 | } |
| 4546 | SendUpdateFaviconURL(urls); |
| 4547 | } |
| 4548 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4549 | } // namespace content |