[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] | f29efe6b | 2014-06-09 05:01:51 | [diff] [blame] | 23 | #include "base/metrics/field_trial.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 24 | #include "base/metrics/histogram.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] | cb189e06 | 2014-04-23 00:57:01 | [diff] [blame] | 37 | #include "content/child/child_shared_bitmap_manager.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 38 | #include "content/child/child_thread.h" |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 39 | #include "content/child/npapi/webplugin_delegate_impl.h" |
[email protected] | 541b7b0 | 2013-06-07 00:59:34 | [diff] [blame] | 40 | #include "content/child/request_extra_data.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 41 | #include "content/child/webmessageportchannel_impl.h" |
jinho.bang | 632a1a72 | 2014-09-18 03:02:56 | [diff] [blame] | 42 | #include "content/common/content_constants_internal.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 43 | #include "content/common/database_messages.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 44 | #include "content/common/dom_storage/dom_storage_types.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 45 | #include "content/common/drag_messages.h" |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 46 | #include "content/common/frame_messages.h" |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 47 | #include "content/common/frame_replication_state.h" |
[email protected] | c26ad88 | 2012-02-07 06:41:20 | [diff] [blame] | 48 | #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 49 | #include "content/common/input_messages.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 50 | #include "content/common/pepper_messages.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 51 | #include "content/common/ssl_status_serialization.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 52 | #include "content/common/view_messages.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 53 | #include "content/public/common/bindings_policy.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 54 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 55 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 56 | #include "content/public/common/content_switches.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 57 | #include "content/public/common/drop_data.h" |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 58 | #include "content/public/common/favicon_url.h" |
hirono | 570357bd | 2014-10-08 12:39:27 | [diff] [blame] | 59 | #include "content/public/common/file_chooser_file_info.h" |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 60 | #include "content/public/common/file_chooser_params.h" |
clamy | da97e832 | 2014-10-07 21:57:25 | [diff] [blame] | 61 | #include "content/public/common/page_state.h" |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 62 | #include "content/public/common/page_zoom.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 63 | #include "content/public/common/ssl_status.h" |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 64 | #include "content/public/common/three_d_api_types.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 65 | #include "content/public/common/url_constants.h" |
[email protected] | 3b366ae | 2013-05-17 21:16:58 | [diff] [blame] | 66 | #include "content/public/common/url_utils.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 67 | #include "content/public/common/web_preferences.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 68 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 69 | #include "content/public/renderer/document_state.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 70 | #include "content/public/renderer/navigation_state.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 71 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 72 | #include "content/public/renderer/render_view_visitor.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] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 75 | #include "content/renderer/devtools/devtools_agent.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 76 | #include "content/renderer/disambiguation_popup_helper.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 77 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 78 | #include "content/renderer/drop_data_builder.h" |
jochen | 26f63992 | 2014-10-23 21:59:57 | [diff] [blame] | 79 | #include "content/renderer/gpu/gpu_benchmarking_extension.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 80 | #include "content/renderer/gpu/render_widget_compositor.h" |
[email protected] | d473498 | 2014-04-15 02:05:55 | [diff] [blame] | 81 | #include "content/renderer/history_controller.h" |
[email protected] | dc06435 | 2014-04-25 08:36:38 | [diff] [blame] | 82 | #include "content/renderer/history_serialization.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] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 86 | #include "content/renderer/internal_document_state_data.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 87 | #include "content/renderer/media/audio_device_factory.h" |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 88 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | 3fad220d | 2014-01-23 11:30:06 | [diff] [blame] | 89 | #include "content/renderer/memory_benchmarking_extension.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 90 | #include "content/renderer/mhtml_generator.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 91 | #include "content/renderer/net_info_helper.h" |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 92 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 93 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 94 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 95 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 96 | #include "content/renderer/render_view_mouse_lock_dispatcher.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 97 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 98 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 99 | #include "content/renderer/resizing_mode_selector.h" |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 100 | #include "content/renderer/savable_resources.h" |
[email protected] | cdb6b1e | 2014-01-23 00:06:49 | [diff] [blame] | 101 | #include "content/renderer/skia_benchmarking_extension.h" |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 102 | #include "content/renderer/speech_recognition_dispatcher.h" |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 103 | #include "content/renderer/stats_collection_controller.h" |
| 104 | #include "content/renderer/stats_collection_observer.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 105 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 106 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 107 | #include "content/renderer/web_ui_extension.h" |
| 108 | #include "content/renderer/web_ui_extension_data.h" |
[email protected] | 1c142a5 | 2014-04-05 20:14:17 | [diff] [blame] | 109 | #include "content/renderer/web_ui_mojo.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 110 | #include "content/renderer/websharedworker_proxy.h" |
[email protected] | f596114 | 2013-04-17 23:09:42 | [diff] [blame] | 111 | #include "media/audio/audio_output_device.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 112 | #include "media/base/media_switches.h" |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 113 | #include "media/filters/audio_renderer_impl.h" |
[email protected] | 1cad880 | 2013-08-13 16:54:32 | [diff] [blame] | 114 | #include "media/filters/gpu_video_accelerator_factories.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 115 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 116 | #include "net/base/escape.h" |
| 117 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 118 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 119 | #include "net/http/http_util.h" |
luken | b171b53 | 2014-09-24 05:50:38 | [diff] [blame] | 120 | #include "skia/ext/platform_canvas.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 121 | #include "third_party/WebKit/public/platform/WebCString.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 122 | #include "third_party/WebKit/public/platform/WebConnectionType.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 123 | #include "third_party/WebKit/public/platform/WebDragData.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 124 | #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 125 | #include "third_party/WebKit/public/platform/WebImage.h" |
| 126 | #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 127 | #include "third_party/WebKit/public/platform/WebPoint.h" |
| 128 | #include "third_party/WebKit/public/platform/WebRect.h" |
| 129 | #include "third_party/WebKit/public/platform/WebSize.h" |
[email protected] | ec173b52 | 2013-11-14 11:01:18 | [diff] [blame] | 130 | #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 131 | #include "third_party/WebKit/public/platform/WebString.h" |
| 132 | #include "third_party/WebKit/public/platform/WebURL.h" |
| 133 | #include "third_party/WebKit/public/platform/WebURLError.h" |
| 134 | #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 135 | #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 136 | #include "third_party/WebKit/public/platform/WebVector.h" |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 137 | #include "third_party/WebKit/public/web/WebAXObject.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 138 | #include "third_party/WebKit/public/web/WebColorName.h" |
[email protected] | 8bc5ff0 | 2013-11-29 06:34:03 | [diff] [blame] | 139 | #include "third_party/WebKit/public/web/WebColorSuggestion.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 140 | #include "third_party/WebKit/public/web/WebDOMEvent.h" |
| 141 | #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" |
| 142 | #include "third_party/WebKit/public/web/WebDataSource.h" |
| 143 | #include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h" |
| 144 | #include "third_party/WebKit/public/web/WebDateTimeChooserParams.h" |
| 145 | #include "third_party/WebKit/public/web/WebDevToolsAgent.h" |
| 146 | #include "third_party/WebKit/public/web/WebDocument.h" |
| 147 | #include "third_party/WebKit/public/web/WebElement.h" |
| 148 | #include "third_party/WebKit/public/web/WebFileChooserParams.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 149 | #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 150 | #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 151 | #include "third_party/WebKit/public/web/WebFormElement.h" |
| 152 | #include "third_party/WebKit/public/web/WebFrame.h" |
[email protected] | 6bd867b | 2013-07-24 22:10:20 | [diff] [blame] | 153 | #include "third_party/WebKit/public/web/WebGlyphCache.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 154 | #include "third_party/WebKit/public/web/WebHistoryItem.h" |
[email protected] | 91dcc6d3 | 2014-07-30 00:01:33 | [diff] [blame] | 155 | #include "third_party/WebKit/public/web/WebHitTestResult.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 156 | #include "third_party/WebKit/public/web/WebInputElement.h" |
| 157 | #include "third_party/WebKit/public/web/WebInputEvent.h" |
[email protected] | afe7d90d | 2014-07-19 05:10:22 | [diff] [blame] | 158 | #include "third_party/WebKit/public/web/WebKit.h" |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 159 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 160 | #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" |
| 161 | #include "third_party/WebKit/public/web/WebNavigationPolicy.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 162 | #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 163 | #include "third_party/WebKit/public/web/WebNodeList.h" |
| 164 | #include "third_party/WebKit/public/web/WebPageSerializer.h" |
| 165 | #include "third_party/WebKit/public/web/WebPlugin.h" |
| 166 | #include "third_party/WebKit/public/web/WebPluginAction.h" |
| 167 | #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 168 | #include "third_party/WebKit/public/web/WebPluginDocument.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 169 | #include "third_party/WebKit/public/web/WebRange.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 170 | #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 171 | #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 172 | #include "third_party/WebKit/public/web/WebSearchableFormData.h" |
| 173 | #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 174 | #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 175 | #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
| 176 | #include "third_party/WebKit/public/web/WebSettings.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 177 | #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 178 | #include "third_party/WebKit/public/web/WebView.h" |
| 179 | #include "third_party/WebKit/public/web/WebWindowFeatures.h" |
| 180 | #include "third_party/WebKit/public/web/default/WebRenderTheme.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 181 | #include "third_party/icu/source/common/unicode/uchar.h" |
| 182 | #include "third_party/icu/source/common/unicode/uscript.h" |
[email protected] | 4ee6462 | 2014-03-21 22:34:15 | [diff] [blame] | 183 | #include "ui/base/clipboard/clipboard.h" |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 184 | #include "ui/base/ui_base_switches_util.h" |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 185 | #include "ui/events/latency_info.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 186 | #include "ui/gfx/geometry/point.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 187 | #include "ui/gfx/geometry/rect.h" |
| 188 | #include "ui/gfx/geometry/rect_conversions.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 189 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 190 | #include "ui/gfx/native_widget_types.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 191 | #include "v8/include/v8.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 192 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 193 | #if defined(OS_ANDROID) |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 194 | #include <cpu-features.h> |
| 195 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 196 | #include "content/renderer/android/address_detector.h" |
| 197 | #include "content/renderer/android/content_detector.h" |
| 198 | #include "content/renderer/android/email_detector.h" |
| 199 | #include "content/renderer/android/phone_number_detector.h" |
[email protected] | 74d9c524 | 2014-05-01 05:10:03 | [diff] [blame] | 200 | #include "net/android/network_library.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 201 | #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 202 | #include "third_party/WebKit/public/platform/WebFloatRect.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 203 | #include "ui/gfx/geometry/rect_f.h" |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 204 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 205 | #elif defined(OS_WIN) |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 206 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 207 | // * theming |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 208 | #include "ui/native_theme/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 209 | #elif defined(USE_X11) |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 210 | #include "ui/native_theme/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 211 | #elif defined(OS_MACOSX) |
| 212 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 213 | #endif |
| 214 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 215 | #if defined(ENABLE_PLUGINS) |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 216 | #include "content/renderer/npapi/webplugin_delegate_proxy.h" |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 217 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 218 | #include "content/renderer/pepper/pepper_plugin_registry.h" |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 219 | #endif |
| 220 | |
[email protected] | 9ac667e | 2013-09-09 12:49:21 | [diff] [blame] | 221 | #if defined(ENABLE_WEBRTC) |
| 222 | #include "content/renderer/media/rtc_peer_connection_handler.h" |
[email protected] | 22fe91d | 2014-08-12 17:07:12 | [diff] [blame] | 223 | #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
[email protected] | 9ac667e | 2013-09-09 12:49:21 | [diff] [blame] | 224 | #endif |
| 225 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 226 | using blink::WebAXObject; |
| 227 | using blink::WebApplicationCacheHost; |
| 228 | using blink::WebApplicationCacheHostClient; |
| 229 | using blink::WebCString; |
| 230 | using blink::WebColor; |
| 231 | using blink::WebColorName; |
| 232 | using blink::WebConsoleMessage; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 233 | using blink::WebData; |
| 234 | using blink::WebDataSource; |
| 235 | using blink::WebDocument; |
| 236 | using blink::WebDOMEvent; |
| 237 | using blink::WebDOMMessageEvent; |
| 238 | using blink::WebDragData; |
| 239 | using blink::WebDragOperation; |
| 240 | using blink::WebDragOperationsMask; |
| 241 | using blink::WebElement; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 242 | using blink::WebFileChooserCompletion; |
| 243 | using blink::WebFindOptions; |
| 244 | using blink::WebFormControlElement; |
| 245 | using blink::WebFormElement; |
| 246 | using blink::WebFrame; |
| 247 | using blink::WebGestureEvent; |
| 248 | using blink::WebHistoryItem; |
| 249 | using blink::WebHTTPBody; |
| 250 | using blink::WebIconURL; |
| 251 | using blink::WebImage; |
| 252 | using blink::WebInputElement; |
| 253 | using blink::WebInputEvent; |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 254 | using blink::WebLocalFrame; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 255 | using blink::WebMediaPlayerAction; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 256 | using blink::WebMouseEvent; |
| 257 | using blink::WebNavigationPolicy; |
| 258 | using blink::WebNavigationType; |
| 259 | using blink::WebNode; |
| 260 | using blink::WebPageSerializer; |
| 261 | using blink::WebPageSerializerClient; |
| 262 | using blink::WebPeerConnection00Handler; |
| 263 | using blink::WebPeerConnection00HandlerClient; |
| 264 | using blink::WebPeerConnectionHandler; |
| 265 | using blink::WebPeerConnectionHandlerClient; |
| 266 | using blink::WebPluginAction; |
| 267 | using blink::WebPluginContainer; |
| 268 | using blink::WebPluginDocument; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 269 | using blink::WebPoint; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 270 | using blink::WebRange; |
| 271 | using blink::WebRect; |
| 272 | using blink::WebReferrerPolicy; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 273 | using blink::WebScriptSource; |
| 274 | using blink::WebSearchableFormData; |
| 275 | using blink::WebSecurityOrigin; |
| 276 | using blink::WebSecurityPolicy; |
| 277 | using blink::WebSerializedScriptValue; |
| 278 | using blink::WebSettings; |
| 279 | using blink::WebSize; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 280 | using blink::WebStorageNamespace; |
| 281 | using blink::WebStorageQuotaCallbacks; |
| 282 | using blink::WebStorageQuotaError; |
| 283 | using blink::WebStorageQuotaType; |
| 284 | using blink::WebString; |
| 285 | using blink::WebTextAffinity; |
| 286 | using blink::WebTextDirection; |
| 287 | using blink::WebTouchEvent; |
| 288 | using blink::WebURL; |
| 289 | using blink::WebURLError; |
| 290 | using blink::WebURLRequest; |
| 291 | using blink::WebURLResponse; |
| 292 | using blink::WebUserGestureIndicator; |
| 293 | using blink::WebVector; |
| 294 | using blink::WebView; |
| 295 | using blink::WebWidget; |
| 296 | using blink::WebWindowFeatures; |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 297 | using blink::WebNetworkStateNotifier; |
| 298 | using blink::WebRuntimeFeatures; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 299 | using base::Time; |
| 300 | using base::TimeDelta; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 301 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 302 | #if defined(OS_ANDROID) |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 303 | using blink::WebContentDetectionResult; |
| 304 | using blink::WebFloatPoint; |
| 305 | using blink::WebFloatRect; |
| 306 | using blink::WebHitTestResult; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 307 | #endif |
| 308 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 309 | namespace content { |
| 310 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 311 | //----------------------------------------------------------------------------- |
| 312 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 313 | typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 314 | static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 315 | typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap; |
| 316 | static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map = |
| 317 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 318 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 319 | // Time, in seconds, we delay before sending content state changes (such as form |
| 320 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 321 | // spamming the browser. |
| 322 | // To avoid having tab/session restore require sending a message to get the |
| 323 | // current content state during tab closing we use a shorter timeout for the |
| 324 | // foreground renderer. This means there is a small window of time from which |
| 325 | // content state is modified and not sent to session restore, but this is |
| 326 | // better than having to wake up all renderers during shutdown. |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 327 | const int kDelaySecondsForContentStateSyncHidden = 5; |
| 328 | const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 329 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 330 | #if defined(OS_ANDROID) |
| 331 | // Delay between tapping in content and launching the associated android intent. |
| 332 | // Used to allow users see what has been recognized as content. |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 333 | const size_t kContentIntentDelayMilliseconds = 700; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 334 | #endif |
| 335 | |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 336 | static RenderViewImpl* (*g_create_render_view_impl)(const ViewMsg_New_Params&) = |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 337 | NULL; |
| 338 | |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 339 | // static |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 340 | bool RenderViewImpl::IsReload(FrameMsg_Navigate_Type::Value navigation_type) { |
| 341 | return navigation_type == FrameMsg_Navigate_Type::RELOAD || |
| 342 | navigation_type == FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE || |
| 343 | navigation_type == FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 344 | } |
| 345 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 346 | // static |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 347 | Referrer RenderViewImpl::GetReferrerFromRequest( |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 348 | WebFrame* frame, |
| 349 | const WebURLRequest& request) { |
| 350 | return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
[email protected] | cacbd7a | 2014-02-04 01:26:02 | [diff] [blame] | 351 | request.referrerPolicy()); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 352 | } |
| 353 | |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 354 | // static |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 355 | WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition( |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 356 | WebNavigationPolicy policy) { |
| 357 | switch (policy) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 358 | case blink::WebNavigationPolicyIgnore: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 359 | return IGNORE_ACTION; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 360 | case blink::WebNavigationPolicyDownload: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 361 | return SAVE_TO_DISK; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 362 | case blink::WebNavigationPolicyCurrentTab: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 363 | return CURRENT_TAB; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 364 | case blink::WebNavigationPolicyNewBackgroundTab: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 365 | return NEW_BACKGROUND_TAB; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 366 | case blink::WebNavigationPolicyNewForegroundTab: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 367 | return NEW_FOREGROUND_TAB; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 368 | case blink::WebNavigationPolicyNewWindow: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 369 | return NEW_WINDOW; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 370 | case blink::WebNavigationPolicyNewPopup: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 371 | return NEW_POPUP; |
| 372 | default: |
| 373 | NOTREACHED() << "Unexpected WebNavigationPolicy"; |
| 374 | return IGNORE_ACTION; |
| 375 | } |
| 376 | } |
| 377 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 378 | // Returns true if the device scale is high enough that losing subpixel |
| 379 | // antialiasing won't have a noticeable effect on text quality. |
| 380 | static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) { |
| 381 | #if defined(OS_ANDROID) |
| 382 | // On Android, we never have subpixel antialiasing. |
| 383 | return true; |
| 384 | #else |
| 385 | return device_scale_factor > 1.5f; |
| 386 | #endif |
| 387 | |
| 388 | } |
| 389 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 390 | static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps, |
| 391 | float device_scale_factor) { |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 392 | const base::CommandLine& command_line = |
| 393 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | b8ec111 | 2014-08-17 20:09:10 | [diff] [blame] | 394 | if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText)) |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 395 | return false; |
[email protected] | b8ec111 | 2014-08-17 20:09:10 | [diff] [blame] | 396 | if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText)) |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 397 | return true; |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 398 | if (!compositor_deps->IsLcdTextEnabled()) |
[email protected] | 10c1973 | 2014-08-18 19:39:23 | [diff] [blame] | 399 | return true; |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 400 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 401 | } |
| 402 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 403 | static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) { |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 404 | switch (type) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 405 | case blink::WebIconURL::TypeFavicon: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 406 | return FaviconURL::FAVICON; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 407 | case blink::WebIconURL::TypeTouch: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 408 | return FaviconURL::TOUCH_ICON; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 409 | case blink::WebIconURL::TypeTouchPrecomposed: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 410 | return FaviconURL::TOUCH_PRECOMPOSED_ICON; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 411 | case blink::WebIconURL::TypeInvalid: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 412 | return FaviconURL::INVALID_ICON; |
| 413 | } |
| 414 | return FaviconURL::INVALID_ICON; |
| 415 | } |
| 416 | |
[email protected] | f34ac13 | 2014-03-20 23:02:05 | [diff] [blame] | 417 | static void ConvertToFaviconSizes( |
| 418 | const blink::WebVector<blink::WebSize>& web_sizes, |
| 419 | std::vector<gfx::Size>* sizes) { |
[email protected] | 2bd262b | 2014-04-16 05:31:23 | [diff] [blame] | 420 | DCHECK(sizes->empty()); |
| 421 | sizes->reserve(web_sizes.size()); |
[email protected] | f34ac13 | 2014-03-20 23:02:05 | [diff] [blame] | 422 | for (size_t i = 0; i < web_sizes.size(); ++i) |
| 423 | sizes->push_back(gfx::Size(web_sizes[i])); |
| 424 | } |
| 425 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 426 | /////////////////////////////////////////////////////////////////////////////// |
| 427 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 428 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 429 | PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c) |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 430 | : params(p), |
| 431 | completion(c) { |
| 432 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 433 | FileChooserParams params; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 434 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 435 | }; |
| 436 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 437 | namespace { |
| 438 | |
| 439 | class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { |
| 440 | public: |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 441 | explicit WebWidgetLockTarget(blink::WebWidget* webwidget) |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 442 | : webwidget_(webwidget) {} |
| 443 | |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 444 | void OnLockMouseACK(bool succeeded) override { |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 445 | if (succeeded) |
| 446 | webwidget_->didAcquirePointerLock(); |
| 447 | else |
| 448 | webwidget_->didNotAcquirePointerLock(); |
| 449 | } |
| 450 | |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 451 | void OnMouseLockLost() override { webwidget_->didLosePointerLock(); } |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 452 | |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 453 | bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override { |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 454 | // The WebWidget handles mouse lock in WebKit's handleInputEvent(). |
| 455 | return false; |
| 456 | } |
| 457 | |
| 458 | private: |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 459 | blink::WebWidget* webwidget_; |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 460 | }; |
| 461 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 462 | bool TouchEnabled() { |
| 463 | // Based on the definition of chrome::kEnableTouchIcon. |
| 464 | #if defined(OS_ANDROID) |
| 465 | return true; |
| 466 | #else |
| 467 | return false; |
| 468 | #endif |
| 469 | } |
| 470 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 471 | WebDragData DropDataToWebDragData(const DropData& drop_data) { |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 472 | std::vector<WebDragData::Item> item_list; |
| 473 | |
| 474 | // These fields are currently unused when dragging into WebKit. |
| 475 | DCHECK(drop_data.download_metadata.empty()); |
| 476 | DCHECK(drop_data.file_contents.empty()); |
| 477 | DCHECK(drop_data.file_description_filename.empty()); |
| 478 | |
| 479 | if (!drop_data.text.is_null()) { |
| 480 | WebDragData::Item item; |
| 481 | item.storageType = WebDragData::Item::StorageTypeString; |
| 482 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| 483 | item.stringData = drop_data.text.string(); |
| 484 | item_list.push_back(item); |
| 485 | } |
| 486 | |
| 487 | // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it |
| 488 | // meaningful to write an empty URL to the clipboard? |
| 489 | if (!drop_data.url.is_empty()) { |
| 490 | WebDragData::Item item; |
| 491 | item.storageType = WebDragData::Item::StorageTypeString; |
| 492 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 493 | item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
| 494 | item.title = drop_data.url_title; |
| 495 | item_list.push_back(item); |
| 496 | } |
| 497 | |
| 498 | if (!drop_data.html.is_null()) { |
| 499 | WebDragData::Item item; |
| 500 | item.storageType = WebDragData::Item::StorageTypeString; |
| 501 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 502 | item.stringData = drop_data.html.string(); |
| 503 | item.baseURL = drop_data.html_base_url; |
| 504 | item_list.push_back(item); |
| 505 | } |
| 506 | |
[email protected] | 17ea0ae2 | 2014-03-28 21:54:46 | [diff] [blame] | 507 | for (std::vector<ui::FileInfo>::const_iterator it = |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 508 | drop_data.filenames.begin(); |
| 509 | it != drop_data.filenames.end(); |
| 510 | ++it) { |
| 511 | WebDragData::Item item; |
| 512 | item.storageType = WebDragData::Item::StorageTypeFilename; |
[email protected] | 17ea0ae2 | 2014-03-28 21:54:46 | [diff] [blame] | 513 | item.filenameData = it->path.AsUTF16Unsafe(); |
| 514 | item.displayNameData = it->display_name.AsUTF16Unsafe(); |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 515 | item_list.push_back(item); |
| 516 | } |
| 517 | |
[email protected] | 60ed95f | 2014-04-23 12:19:48 | [diff] [blame] | 518 | for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = |
| 519 | drop_data.file_system_files.begin(); |
| 520 | it != drop_data.file_system_files.end(); |
| 521 | ++it) { |
| 522 | WebDragData::Item item; |
| 523 | item.storageType = WebDragData::Item::StorageTypeFileSystemFile; |
| 524 | item.fileSystemURL = it->url; |
| 525 | item.fileSystemFileSize = it->size; |
| 526 | item_list.push_back(item); |
| 527 | } |
| 528 | |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 529 | for (std::map<base::string16, base::string16>::const_iterator it = |
| 530 | drop_data.custom_data.begin(); |
| 531 | it != drop_data.custom_data.end(); |
| 532 | ++it) { |
| 533 | WebDragData::Item item; |
| 534 | item.storageType = WebDragData::Item::StorageTypeString; |
| 535 | item.stringType = it->first; |
| 536 | item.stringData = it->second; |
| 537 | item_list.push_back(item); |
| 538 | } |
| 539 | |
| 540 | WebDragData result; |
| 541 | result.initialize(); |
| 542 | result.setItems(item_list); |
| 543 | result.setFilesystemId(drop_data.filesystem_id); |
| 544 | return result; |
| 545 | } |
| 546 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 547 | typedef void (*SetFontFamilyWrapper)(blink::WebSettings*, |
| 548 | const base::string16&, |
| 549 | UScriptCode); |
| 550 | |
| 551 | void SetStandardFontFamilyWrapper(WebSettings* settings, |
| 552 | const base::string16& font, |
| 553 | UScriptCode script) { |
| 554 | settings->setStandardFontFamily(font, script); |
| 555 | } |
| 556 | |
| 557 | void SetFixedFontFamilyWrapper(WebSettings* settings, |
| 558 | const base::string16& font, |
| 559 | UScriptCode script) { |
| 560 | settings->setFixedFontFamily(font, script); |
| 561 | } |
| 562 | |
| 563 | void SetSerifFontFamilyWrapper(WebSettings* settings, |
| 564 | const base::string16& font, |
| 565 | UScriptCode script) { |
| 566 | settings->setSerifFontFamily(font, script); |
| 567 | } |
| 568 | |
| 569 | void SetSansSerifFontFamilyWrapper(WebSettings* settings, |
| 570 | const base::string16& font, |
| 571 | UScriptCode script) { |
| 572 | settings->setSansSerifFontFamily(font, script); |
| 573 | } |
| 574 | |
| 575 | void SetCursiveFontFamilyWrapper(WebSettings* settings, |
| 576 | const base::string16& font, |
| 577 | UScriptCode script) { |
| 578 | settings->setCursiveFontFamily(font, script); |
| 579 | } |
| 580 | |
| 581 | void SetFantasyFontFamilyWrapper(WebSettings* settings, |
| 582 | const base::string16& font, |
| 583 | UScriptCode script) { |
| 584 | settings->setFantasyFontFamily(font, script); |
| 585 | } |
| 586 | |
| 587 | void SetPictographFontFamilyWrapper(WebSettings* settings, |
| 588 | const base::string16& font, |
| 589 | UScriptCode script) { |
| 590 | settings->setPictographFontFamily(font, script); |
| 591 | } |
| 592 | |
| 593 | // If |scriptCode| is a member of a family of "similar" script codes, returns |
| 594 | // the script code in that family that is used by WebKit for font selection |
| 595 | // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are |
| 596 | // considered equivalent for the purposes of font selection. WebKit uses the |
| 597 | // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is |
| 598 | // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit |
| 599 | // uses different scripts than the ones in Chrome pref names because the version |
| 600 | // of ICU included on certain ports does not have some of the newer scripts. If |
| 601 | // |scriptCode| is not a member of such a family, returns |scriptCode|. |
| 602 | UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) { |
| 603 | switch (scriptCode) { |
| 604 | case USCRIPT_HIRAGANA: |
| 605 | case USCRIPT_KATAKANA: |
| 606 | case USCRIPT_JAPANESE: |
| 607 | return USCRIPT_KATAKANA_OR_HIRAGANA; |
| 608 | case USCRIPT_KOREAN: |
| 609 | return USCRIPT_HANGUL; |
| 610 | default: |
| 611 | return scriptCode; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | void ApplyFontsFromMap(const ScriptFontFamilyMap& map, |
| 616 | SetFontFamilyWrapper setter, |
| 617 | WebSettings* settings) { |
| 618 | for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end(); |
| 619 | ++it) { |
| 620 | int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str()); |
| 621 | if (script >= 0 && script < USCRIPT_CODE_LIMIT) { |
| 622 | UScriptCode code = static_cast<UScriptCode>(script); |
| 623 | (*setter)(settings, it->second, GetScriptForWebSettings(code)); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 628 | } // namespace |
| 629 | |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 630 | RenderViewImpl::RenderViewImpl(const ViewMsg_New_Params& params) |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 631 | : RenderWidget(blink::WebPopupTypeNone, |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 632 | params.initial_size.screen_info, |
| 633 | params.swapped_out, |
| 634 | params.hidden, |
| 635 | params.never_visible), |
| 636 | webkit_preferences_(params.web_preferences), |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 637 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 638 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 639 | send_preferred_size_changes_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 640 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 641 | opened_by_user_gesture_(true), |
| 642 | opener_suppressed_(false), |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 643 | suppress_dialogs_until_swap_out_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 644 | page_id_(-1), |
| 645 | last_page_id_sent_to_browser_(-1), |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 646 | next_page_id_(params.next_page_id), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 647 | history_list_offset_(-1), |
| 648 | history_list_length_(0), |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 649 | frames_in_progress_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 650 | target_url_status_(TARGET_NONE), |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 651 | uses_temporary_zoom_level_(false), |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 652 | #if defined(OS_ANDROID) |
| 653 | top_controls_constraints_(cc::BOTH), |
| 654 | #endif |
[email protected] | 1875bc0 | 2014-03-14 06:33:59 | [diff] [blame] | 655 | has_scrolled_focused_editable_node_into_rect_(false), |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 656 | speech_recognition_dispatcher_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 657 | devtools_agent_(NULL), |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 658 | mouse_lock_dispatcher_(NULL), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 659 | #if defined(OS_ANDROID) |
| 660 | expected_content_intent_id_(0), |
[email protected] | a756427 | 2013-04-19 14:24:46 | [diff] [blame] | 661 | #endif |
| 662 | #if defined(OS_WIN) |
| 663 | focused_plugin_id_(-1), |
| 664 | #endif |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 665 | #if defined(ENABLE_PLUGINS) |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 666 | plugin_find_handler_(NULL), |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 667 | focused_pepper_plugin_(NULL), |
| 668 | pepper_last_mouse_event_target_(NULL), |
| 669 | #endif |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 670 | enumeration_completion_id_(0), |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 671 | session_storage_namespace_id_(params.session_storage_namespace_id), |
[email protected] | f2c530d | 2014-02-20 20:15:30 | [diff] [blame] | 672 | next_snapshot_id_(0) { |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 673 | } |
| 674 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 675 | void RenderViewImpl::Initialize(const ViewMsg_New_Params& params, |
| 676 | CompositorDependencies* compositor_deps, |
| 677 | bool was_created_by_renderer) { |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 678 | routing_id_ = params.view_id; |
| 679 | surface_id_ = params.surface_id; |
| 680 | if (params.opener_route_id != MSG_ROUTING_NONE && was_created_by_renderer) |
| 681 | opener_id_ = params.opener_route_id; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 682 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 683 | // Ensure we start with a valid next_page_id_ from the browser. |
| 684 | DCHECK_GE(next_page_id_, 0); |
| 685 | |
[email protected] | 8eae080 | 2014-06-02 21:35:55 | [diff] [blame] | 686 | main_render_frame_.reset(RenderFrameImpl::Create( |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 687 | this, params.main_frame_routing_id)); |
[email protected] | 34f288c | 2014-04-28 16:25:37 | [diff] [blame] | 688 | // The main frame WebLocalFrame object is closed by |
| 689 | // RenderFrameImpl::frameDetached(). |
[email protected] | 8eae080 | 2014-06-02 21:35:55 | [diff] [blame] | 690 | WebLocalFrame* web_frame = WebLocalFrame::create(main_render_frame_.get()); |
| 691 | main_render_frame_->SetWebFrame(web_frame); |
[email protected] | 34f288c | 2014-04-28 16:25:37 | [diff] [blame] | 692 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 693 | compositor_deps_ = compositor_deps; |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 694 | webwidget_ = WebView::create(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 695 | webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 696 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 697 | const base::CommandLine& command_line = |
| 698 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 699 | |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 700 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 701 | stats_collection_observer_.reset(new StatsCollectionObserver(this)); |
| 702 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 703 | #if defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 704 | const std::string region_code = |
| 705 | command_line.HasSwitch(switches::kNetworkCountryIso) |
| 706 | ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) |
wangxianzhu | 4e645e9 | 2014-10-08 01:01:07 | [diff] [blame] | 707 | : net::android::GetTelephonyNetworkCountryIso(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 708 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 709 | new AddressDetector())); |
qinmin | 0d5560df | 2014-11-12 19:03:39 | [diff] [blame] | 710 | if (!region_code.empty()) { |
| 711 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 712 | new PhoneNumberDetector(region_code))); |
| 713 | } |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 714 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 715 | new EmailDetector())); |
| 716 | #endif |
| 717 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 718 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 719 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 720 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 721 | AddRef(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 722 | if (RenderThreadImpl::current()) { |
| 723 | RenderThreadImpl::current()->WidgetCreated(); |
| 724 | if (is_hidden_) |
| 725 | RenderThreadImpl::current()->WidgetHidden(); |
| 726 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 727 | |
| 728 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 729 | // completing initialization. Otherwise, we can finish it now. |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 730 | if (opener_id_ == MSG_ROUTING_NONE) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 731 | did_show_ = true; |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 732 | CompleteInit(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 733 | } |
| 734 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 735 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 736 | g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this)); |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 737 | webview()->setDeviceScaleFactor(device_scale_factor_); |
[email protected] | b8ec111 | 2014-08-17 20:09:10 | [diff] [blame] | 738 | webview()->settings()->setPreferCompositingToLCDTextEnabled( |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 739 | PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); |
jdduke | 2eee6cb | 2014-09-25 17:02:21 | [diff] [blame] | 740 | webview()->settings()->setThreadedScrollingEnabled( |
| 741 | !command_line.HasSwitch(switches::kDisableThreadedScrolling)); |
skobes | 92ed7d46 | 2014-11-05 22:05:23 | [diff] [blame] | 742 | webview()->settings()->setRootLayerScrolls( |
| 743 | command_line.HasSwitch(switches::kRootLayerScrolls)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 744 | |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 745 | ApplyWebPreferences(webkit_preferences_, webview()); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 746 | |
[email protected] | 7fe71f0 | 2014-04-26 00:47:56 | [diff] [blame] | 747 | webview()->settings()->setAllowConnectingInsecureWebSocket( |
| 748 | command_line.HasSwitch(switches::kAllowInsecureWebSocketFromHttpsOrigin)); |
| 749 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 750 | RenderFrameProxy* proxy = NULL; |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 751 | if (params.proxy_routing_id != MSG_ROUTING_NONE) { |
| 752 | CHECK(params.swapped_out); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 753 | proxy = RenderFrameProxy::CreateProxyToReplaceFrame( |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 754 | main_render_frame_.get(), params.proxy_routing_id); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 755 | main_render_frame_->set_render_frame_proxy(proxy); |
| 756 | } |
| 757 | |
| 758 | // In --site-per-process, just use the WebRemoteFrame as the main frame. |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 759 | if (command_line.HasSwitch(switches::kSitePerProcess) && proxy) { |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 760 | webview()->setMainFrame(proxy->web_frame()); |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 761 | // Initialize the WebRemoteFrame with information replicated from the |
| 762 | // browser process. |
| 763 | proxy->SetReplicatedState(params.replicated_frame_state); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 764 | } else { |
| 765 | webview()->setMainFrame(main_render_frame_->GetWebFrame()); |
| 766 | } |
[email protected] | 0287e76 | 2014-04-11 13:07:58 | [diff] [blame] | 767 | main_render_frame_->Initialize(); |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 768 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 769 | if (switches::IsTouchDragDropEnabled()) |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 770 | webview()->settings()->setTouchDragDropEnabled(true); |
| 771 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 772 | if (switches::IsTouchEditingEnabled()) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 773 | webview()->settings()->setTouchEditingEnabled(true); |
| 774 | |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 775 | if (!params.frame_name.empty()) |
| 776 | webview()->mainFrame()->setName(params.frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 777 | |
[email protected] | c7c0d82 | 2014-04-16 20:19:49 | [diff] [blame] | 778 | // TODO(davidben): Move this state from Blink into content. |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 779 | if (params.window_was_created_with_opener) |
[email protected] | c7c0d82 | 2014-04-16 20:19:49 | [diff] [blame] | 780 | webview()->setOpenedByDOM(); |
| 781 | |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 782 | OnSetRendererPrefs(params.renderer_preferences); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 783 | |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 784 | if (!params.enable_auto_resize) { |
| 785 | OnResize(params.initial_size); |
mkosiba | 58fa72f0 | 2014-11-12 01:21:36 | [diff] [blame] | 786 | } else { |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 787 | OnEnableAutoResize(params.min_size, params.max_size); |
mkosiba | 58fa72f0 | 2014-11-12 01:21:36 | [diff] [blame] | 788 | } |
| 789 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 790 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 791 | #if defined(OS_MACOSX) |
| 792 | new TextInputClientObserver(this); |
| 793 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 794 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 795 | // The next group of objects all implement RenderViewObserver, so are deleted |
| 796 | // along with the RenderView automatically. |
yurys | 65e008f | 2014-11-25 11:29:49 | [diff] [blame] | 797 | devtools_agent_ = new DevToolsAgent(main_render_frame_.get()); |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 798 | if (RenderWidgetCompositor* rwc = compositor()) { |
| 799 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 800 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 801 | mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 802 | |
[email protected] | d473498 | 2014-04-15 02:05:55 | [diff] [blame] | 803 | history_controller_.reset(new HistoryController(this)); |
| 804 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 805 | new IdleUserDetector(this); |
| 806 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 807 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 808 | enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION; |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 809 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 810 | enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION; |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 811 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 812 | GetContentClient()->renderer()->RenderViewCreated(this); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 813 | |
| 814 | // If we have an opener_id but we weren't created by a renderer, then |
| 815 | // it's the browser asking us to set our opener to another RenderView. |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 816 | if (params.opener_route_id != MSG_ROUTING_NONE && !was_created_by_renderer) { |
| 817 | RenderViewImpl* opener_view = FromRoutingID(params.opener_route_id); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 818 | if (opener_view) |
| 819 | webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | // If we are initially swapped out, navigate to kSwappedOutURL. |
| 823 | // This ensures we are in a unique origin that others cannot script. |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 824 | if (is_swapped_out_ && webview()->mainFrame()->isWebLocalFrame()) |
nasko | 78f06bc | 2014-11-18 18:18:57 | [diff] [blame] | 825 | main_render_frame_->NavigateToSwappedOutURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 826 | } |
| 827 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 828 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | cb189e06 | 2014-04-23 00:57:01 | [diff] [blame] | 829 | for (BitmapMap::iterator it = disambiguation_bitmaps_.begin(); |
| 830 | it != disambiguation_bitmaps_.end(); |
| 831 | ++it) |
| 832 | delete it->second; |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 833 | base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_); |
| 834 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 835 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 836 | while (!file_chooser_completions_.empty()) { |
| 837 | if (file_chooser_completions_.front()->completion) { |
| 838 | file_chooser_completions_.front()->completion->didChooseFile( |
| 839 | WebVector<WebString>()); |
| 840 | } |
| 841 | file_chooser_completions_.pop_front(); |
| 842 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 843 | |
[email protected] | 8ed1d3f | 2013-02-20 11:45:55 | [diff] [blame] | 844 | #if defined(OS_ANDROID) |
| 845 | // The date/time picker client is both a scoped_ptr member of this class and |
| 846 | // a RenderViewObserver. Reset it to prevent double deletion. |
| 847 | date_time_picker_client_.reset(); |
| 848 | #endif |
| 849 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 850 | #ifndef NDEBUG |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 851 | // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 852 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 853 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 854 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 855 | RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 856 | for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 857 | it != routing_id_views->end(); ++it) |
| 858 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 859 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 860 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 861 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 862 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 866 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 867 | ViewMap* views = g_view_map.Pointer(); |
| 868 | ViewMap::iterator it = views->find(webview); |
| 869 | return it == views->end() ? NULL : it->second; |
| 870 | } |
| 871 | |
| 872 | /*static*/ |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 873 | RenderView* RenderView::FromWebView(blink::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 874 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | /*static*/ |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 878 | RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) { |
| 879 | RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
| 880 | RoutingIDViewMap::iterator it = views->find(routing_id); |
| 881 | return it == views->end() ? NULL : it->second; |
| 882 | } |
| 883 | |
| 884 | /*static*/ |
| 885 | RenderView* RenderView::FromRoutingID(int routing_id) { |
| 886 | return RenderViewImpl::FromRoutingID(routing_id); |
| 887 | } |
| 888 | |
[email protected] | f3a9531 | 2014-06-12 16:46:58 | [diff] [blame] | 889 | /* static */ |
| 890 | size_t RenderViewImpl::GetRenderViewCount() { |
| 891 | return g_view_map.Get().size(); |
| 892 | } |
| 893 | |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 894 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 895 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 896 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 897 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 898 | if (!visitor->Visit(it->second)) |
| 899 | return; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | /*static*/ |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 904 | void RenderView::ApplyWebPreferences(const WebPreferences& prefs, |
| 905 | WebView* web_view) { |
| 906 | WebSettings* settings = web_view->settings(); |
| 907 | ApplyFontsFromMap(prefs.standard_font_family_map, |
| 908 | SetStandardFontFamilyWrapper, settings); |
| 909 | ApplyFontsFromMap(prefs.fixed_font_family_map, |
| 910 | SetFixedFontFamilyWrapper, settings); |
| 911 | ApplyFontsFromMap(prefs.serif_font_family_map, |
| 912 | SetSerifFontFamilyWrapper, settings); |
| 913 | ApplyFontsFromMap(prefs.sans_serif_font_family_map, |
| 914 | SetSansSerifFontFamilyWrapper, settings); |
| 915 | ApplyFontsFromMap(prefs.cursive_font_family_map, |
| 916 | SetCursiveFontFamilyWrapper, settings); |
| 917 | ApplyFontsFromMap(prefs.fantasy_font_family_map, |
| 918 | SetFantasyFontFamilyWrapper, settings); |
| 919 | ApplyFontsFromMap(prefs.pictograph_font_family_map, |
| 920 | SetPictographFontFamilyWrapper, settings); |
| 921 | settings->setDefaultFontSize(prefs.default_font_size); |
| 922 | settings->setDefaultFixedFontSize(prefs.default_fixed_font_size); |
| 923 | settings->setMinimumFontSize(prefs.minimum_font_size); |
| 924 | settings->setMinimumLogicalFontSize(prefs.minimum_logical_font_size); |
| 925 | settings->setDefaultTextEncodingName( |
| 926 | base::ASCIIToUTF16(prefs.default_encoding)); |
| 927 | settings->setJavaScriptEnabled(prefs.javascript_enabled); |
| 928 | settings->setWebSecurityEnabled(prefs.web_security_enabled); |
| 929 | settings->setJavaScriptCanOpenWindowsAutomatically( |
| 930 | prefs.javascript_can_open_windows_automatically); |
| 931 | settings->setLoadsImagesAutomatically(prefs.loads_images_automatically); |
| 932 | settings->setImagesEnabled(prefs.images_enabled); |
| 933 | settings->setPluginsEnabled(prefs.plugins_enabled); |
| 934 | settings->setDOMPasteAllowed(prefs.dom_paste_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 935 | settings->setShrinksStandaloneImagesToFit( |
| 936 | prefs.shrinks_standalone_images_to_fit); |
| 937 | settings->setUsesEncodingDetector(prefs.uses_universal_detector); |
| 938 | settings->setTextAreasAreResizable(prefs.text_areas_are_resizable); |
| 939 | settings->setAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows); |
| 940 | settings->setDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled); |
| 941 | settings->setJavaScriptCanAccessClipboard( |
| 942 | prefs.javascript_can_access_clipboard); |
| 943 | WebRuntimeFeatures::enableXSLT(prefs.xslt_enabled); |
leviw | b6fdf887 | 2014-10-28 17:46:52 | [diff] [blame] | 944 | WebRuntimeFeatures::enableSlimmingPaint(prefs.slimming_paint_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 945 | settings->setXSSAuditorEnabled(prefs.xss_auditor_enabled); |
| 946 | settings->setDNSPrefetchingEnabled(prefs.dns_prefetching_enabled); |
| 947 | settings->setLocalStorageEnabled(prefs.local_storage_enabled); |
| 948 | settings->setSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled); |
| 949 | WebRuntimeFeatures::enableDatabase(prefs.databases_enabled); |
| 950 | settings->setOfflineWebApplicationCacheEnabled( |
| 951 | prefs.application_cache_enabled); |
| 952 | settings->setCaretBrowsingEnabled(prefs.caret_browsing_enabled); |
| 953 | settings->setHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled); |
| 954 | settings->setCookieEnabled(prefs.cookie_enabled); |
| 955 | settings->setNavigateOnDragDrop(prefs.navigate_on_drag_drop); |
| 956 | |
| 957 | settings->setJavaEnabled(prefs.java_enabled); |
| 958 | |
| 959 | // By default, allow_universal_access_from_file_urls is set to false and thus |
| 960 | // we mitigate attacks from local HTML files by not granting file:// URLs |
| 961 | // universal access. Only test shell will enable this. |
| 962 | settings->setAllowUniversalAccessFromFileURLs( |
| 963 | prefs.allow_universal_access_from_file_urls); |
| 964 | settings->setAllowFileAccessFromFileURLs( |
| 965 | prefs.allow_file_access_from_file_urls); |
| 966 | |
| 967 | // Enable the web audio API if requested on the command line. |
| 968 | settings->setWebAudioEnabled(prefs.webaudio_enabled); |
| 969 | |
| 970 | // Enable experimental WebGL support if requested on command line |
| 971 | // and support is compiled in. |
| 972 | settings->setExperimentalWebGLEnabled(prefs.experimental_webgl_enabled); |
| 973 | |
| 974 | // Disable GL multisampling if requested on command line. |
| 975 | settings->setOpenGLMultisamplingEnabled(prefs.gl_multisampling_enabled); |
| 976 | |
| 977 | // Enable WebGL errors to the JS console if requested. |
| 978 | settings->setWebGLErrorsToConsoleEnabled( |
| 979 | prefs.webgl_errors_to_console_enabled); |
| 980 | |
| 981 | // Uses the mock theme engine for scrollbars. |
| 982 | settings->setMockScrollbarsEnabled(prefs.mock_scrollbars_enabled); |
| 983 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 984 | // Enable gpu-accelerated 2d canvas if requested on the command line. |
| 985 | settings->setAccelerated2dCanvasEnabled(prefs.accelerated_2d_canvas_enabled); |
| 986 | |
| 987 | settings->setMinimumAccelerated2dCanvasSize( |
| 988 | prefs.minimum_accelerated_2d_canvas_size); |
| 989 | |
| 990 | // Disable antialiasing for 2d canvas if requested on the command line. |
| 991 | settings->setAntialiased2dCanvasEnabled( |
| 992 | !prefs.antialiased_2d_canvas_disabled); |
| 993 | |
robertphillips | e25137b | 2014-10-20 13:44:34 | [diff] [blame] | 994 | // Enabled antialiasing of clips for 2d canvas if requested on the command |
| 995 | // line. |
| 996 | settings->setAntialiasedClips2dCanvasEnabled( |
| 997 | prefs.antialiased_clips_2d_canvas_enabled); |
| 998 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 999 | // Set MSAA sample count for 2d canvas if requested on the command line (or |
| 1000 | // default value if not). |
| 1001 | settings->setAccelerated2dCanvasMSAASampleCount( |
| 1002 | prefs.accelerated_2d_canvas_msaa_sample_count); |
| 1003 | |
fmalita | 6d3d8f11 | 2014-10-08 01:58:06 | [diff] [blame] | 1004 | WebRuntimeFeatures::enableTextBlobs(prefs.text_blobs_enabled); |
| 1005 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1006 | settings->setAsynchronousSpellCheckingEnabled( |
| 1007 | prefs.asynchronous_spell_checking_enabled); |
| 1008 | settings->setUnifiedTextCheckerEnabled(prefs.unified_textchecker_enabled); |
| 1009 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1010 | // Tabs to link is not part of the settings. WebCore calls |
| 1011 | // ChromeClient::tabsToLinks which is part of the glue code. |
| 1012 | web_view->setTabsToLinks(prefs.tabs_to_links); |
| 1013 | |
| 1014 | settings->setAllowDisplayOfInsecureContent( |
| 1015 | prefs.allow_displaying_insecure_content); |
| 1016 | settings->setAllowRunningOfInsecureContent( |
| 1017 | prefs.allow_running_insecure_content); |
mkwst | 772ce814 | 2015-01-16 13:28:07 | [diff] [blame] | 1018 | settings->setDisableReadingFromCanvas(prefs.disable_reading_from_canvas); |
mkwst | 2fc2c4f | 2015-01-08 08:29:18 | [diff] [blame] | 1019 | settings->setStrictMixedContentChecking(prefs.strict_mixed_content_checking); |
mkwst | 673a452f | 2015-01-10 14:41:50 | [diff] [blame] | 1020 | settings->setStrictPowerfulFeatureRestrictions( |
| 1021 | prefs.strict_powerful_feature_restrictions); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1022 | settings->setPasswordEchoEnabled(prefs.password_echo_enabled); |
| 1023 | settings->setShouldPrintBackgrounds(prefs.should_print_backgrounds); |
| 1024 | settings->setShouldClearDocumentBackground( |
| 1025 | prefs.should_clear_document_background); |
| 1026 | settings->setEnableScrollAnimator(prefs.enable_scroll_animator); |
| 1027 | |
| 1028 | settings->setRegionBasedColumnsEnabled(prefs.region_based_columns_enabled); |
| 1029 | |
| 1030 | WebRuntimeFeatures::enableTouch(prefs.touch_enabled); |
| 1031 | settings->setMaxTouchPoints(prefs.pointer_events_max_touch_points); |
mustaq | 29eb709 | 2014-11-14 00:32:12 | [diff] [blame] | 1032 | settings->setAvailablePointerTypes(prefs.available_pointer_types); |
| 1033 | settings->setPrimaryPointerType( |
| 1034 | static_cast<WebSettings::PointerType>(prefs.primary_pointer_type)); |
| 1035 | settings->setAvailableHoverTypes(prefs.available_hover_types); |
| 1036 | settings->setPrimaryHoverType( |
| 1037 | static_cast<WebSettings::HoverType>(prefs.primary_hover_type)); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1038 | settings->setDeviceSupportsTouch(prefs.device_supports_touch); |
| 1039 | settings->setDeviceSupportsMouse(prefs.device_supports_mouse); |
| 1040 | settings->setEnableTouchAdjustment(prefs.touch_adjustment_enabled); |
| 1041 | |
| 1042 | settings->setDeferredImageDecodingEnabled( |
| 1043 | prefs.deferred_image_decoding_enabled); |
noel | f552c517 | 2014-11-05 22:53:21 | [diff] [blame] | 1044 | WebRuntimeFeatures::enableImageColorProfiles( |
| 1045 | prefs.image_color_profiles_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1046 | settings->setShouldRespectImageOrientation( |
| 1047 | prefs.should_respect_image_orientation); |
| 1048 | |
| 1049 | settings->setUnsafePluginPastingEnabled(false); |
| 1050 | settings->setEditingBehavior( |
| 1051 | static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior)); |
| 1052 | |
| 1053 | settings->setSupportsMultipleWindows(prefs.supports_multiple_windows); |
| 1054 | |
| 1055 | settings->setViewportEnabled(prefs.viewport_enabled); |
| 1056 | settings->setLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale); |
| 1057 | settings->setViewportMetaEnabled(prefs.viewport_meta_enabled); |
| 1058 | settings->setMainFrameResizesAreOrientationChanges( |
| 1059 | prefs.main_frame_resizes_are_orientation_changes); |
| 1060 | |
| 1061 | settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled); |
| 1062 | |
| 1063 | settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled); |
| 1064 | |
| 1065 | settings->setSelectionIncludesAltImageText(true); |
| 1066 | |
[email protected] | 35103c0 | 2014-08-12 15:08:47 | [diff] [blame] | 1067 | settings->setV8CacheOptions( |
| 1068 | static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options)); |
| 1069 | |
marja | aaf6266 | 2014-09-18 08:51:47 | [diff] [blame] | 1070 | settings->setV8ScriptStreamingEnabled(prefs.v8_script_streaming_enabled); |
marja | e1c3b8b | 2014-11-03 11:29:03 | [diff] [blame] | 1071 | settings->setV8ScriptStreamingMode( |
| 1072 | static_cast<WebSettings::V8ScriptStreamingMode>( |
| 1073 | prefs.v8_script_streaming_mode)); |
marja | aaf6266 | 2014-09-18 08:51:47 | [diff] [blame] | 1074 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1075 | #if defined(OS_ANDROID) |
| 1076 | settings->setAllowCustomScrollbarInMainFrame(false); |
| 1077 | settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled); |
| 1078 | settings->setAccessibilityFontScaleFactor(prefs.font_scale_factor); |
| 1079 | settings->setDeviceScaleAdjustment(prefs.device_scale_adjustment); |
[email protected] | 023fed31 | 2014-08-11 16:13:05 | [diff] [blame] | 1080 | settings->setFullscreenSupported(prefs.fullscreen_supported); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1081 | web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom); |
| 1082 | settings->setAutoZoomFocusedNodeToLegibleScale(true); |
| 1083 | settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled); |
| 1084 | settings->setMediaControlsOverlayPlayButtonEnabled(true); |
| 1085 | settings->setMediaPlaybackRequiresUserGesture( |
| 1086 | prefs.user_gesture_required_for_media_playback); |
| 1087 | settings->setDefaultVideoPosterURL( |
| 1088 | base::ASCIIToUTF16(prefs.default_video_poster_url.spec())); |
| 1089 | settings->setSupportDeprecatedTargetDensityDPI( |
| 1090 | prefs.support_deprecated_target_density_dpi); |
| 1091 | settings->setUseLegacyBackgroundSizeShorthandBehavior( |
| 1092 | prefs.use_legacy_background_size_shorthand_behavior); |
| 1093 | settings->setWideViewportQuirkEnabled(prefs.wide_viewport_quirk); |
| 1094 | settings->setUseWideViewport(prefs.use_wide_viewport); |
[email protected] | 9954ea9 | 2014-08-12 15:48:45 | [diff] [blame] | 1095 | settings->setForceZeroLayoutHeight(prefs.force_zero_layout_height); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1096 | settings->setViewportMetaLayoutSizeQuirk( |
| 1097 | prefs.viewport_meta_layout_size_quirk); |
| 1098 | settings->setViewportMetaMergeContentQuirk( |
| 1099 | prefs.viewport_meta_merge_content_quirk); |
| 1100 | settings->setViewportMetaNonUserScalableQuirk( |
| 1101 | prefs.viewport_meta_non_user_scalable_quirk); |
| 1102 | settings->setViewportMetaZeroValuesQuirk( |
| 1103 | prefs.viewport_meta_zero_values_quirk); |
| 1104 | settings->setClobberUserAgentInitialScaleQuirk( |
| 1105 | prefs.clobber_user_agent_initial_scale_quirk); |
| 1106 | settings->setIgnoreMainFrameOverflowHiddenQuirk( |
| 1107 | prefs.ignore_main_frame_overflow_hidden_quirk); |
| 1108 | settings->setReportScreenSizeInPhysicalPixelsQuirk( |
| 1109 | prefs.report_screen_size_in_physical_pixels_quirk); |
timav | 7a5032e | 2014-12-05 01:59:43 | [diff] [blame] | 1110 | |
| 1111 | bool record_full_layer = |
| 1112 | RenderViewImpl::FromWebView(web_view) |
| 1113 | ? RenderViewImpl::FromWebView(web_view)->DoesRecordFullLayer() |
| 1114 | : false; |
| 1115 | settings->setMainFrameClipsContent(!record_full_layer); |
| 1116 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1117 | settings->setShrinksStandaloneImagesToFit(false); |
| 1118 | settings->setShrinksViewportContentToFit(true); |
| 1119 | #endif |
| 1120 | |
| 1121 | WebNetworkStateNotifier::setOnLine(prefs.is_online); |
| 1122 | WebNetworkStateNotifier::setWebConnectionType( |
| 1123 | NetConnectionTypeToWebConnectionType(prefs.connection_type)); |
| 1124 | settings->setPinchVirtualViewportEnabled( |
| 1125 | prefs.pinch_virtual_viewport_enabled); |
| 1126 | |
| 1127 | settings->setPinchOverlayScrollbarThickness( |
| 1128 | prefs.pinch_overlay_scrollbar_thickness); |
ccameron | 0ffe215 | 2014-11-14 22:31:26 | [diff] [blame] | 1129 | settings->setRubberBandingOnCompositorThread( |
| 1130 | prefs.rubber_banding_on_compositor_thread); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1131 | settings->setUseSolidColorScrollbars(prefs.use_solid_color_scrollbars); |
jinho.bang | 8f11ffa | 2014-12-04 06:03:03 | [diff] [blame] | 1132 | |
| 1133 | #if defined(OS_WIN) |
| 1134 | settings->setShowContextMenuOnMouseUp(true); |
| 1135 | #endif |
bokan | 28eb1a56 | 2015-01-16 02:09:20 | [diff] [blame] | 1136 | |
| 1137 | web_view->setDefaultPageScaleLimits( |
| 1138 | prefs.default_minimum_page_scale_factor, |
| 1139 | prefs.default_maximum_page_scale_factor); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | /*static*/ |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1143 | RenderViewImpl* RenderViewImpl::Create(const ViewMsg_New_Params& params, |
| 1144 | CompositorDependencies* compositor_deps, |
| 1145 | bool was_created_by_renderer) { |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 1146 | DCHECK(params.view_id != MSG_ROUTING_NONE); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1147 | RenderViewImpl* render_view = NULL; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1148 | if (g_create_render_view_impl) |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 1149 | render_view = g_create_render_view_impl(params); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1150 | else |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 1151 | render_view = new RenderViewImpl(params); |
[email protected] | 0287e76 | 2014-04-11 13:07:58 | [diff] [blame] | 1152 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1153 | render_view->Initialize(params, compositor_deps, was_created_by_renderer); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1154 | return render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | // static |
| 1158 | void RenderViewImpl::InstallCreateHook( |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 1159 | RenderViewImpl* (*create_render_view_impl)(const ViewMsg_New_Params&)) { |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1160 | CHECK(!g_create_render_view_impl); |
| 1161 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1162 | } |
| 1163 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1164 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1165 | observers_.AddObserver(observer); |
| 1166 | } |
| 1167 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1168 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 1169 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1170 | observers_.RemoveObserver(observer); |
| 1171 | } |
| 1172 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1173 | blink::WebView* RenderViewImpl::webview() const { |
| 1174 | return static_cast<blink::WebView*>(webwidget()); |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 1175 | } |
| 1176 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 1177 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 1178 | void RenderViewImpl::PepperInstanceCreated( |
| 1179 | PepperPluginInstanceImpl* instance) { |
| 1180 | active_pepper_instances_.insert(instance); |
| 1181 | } |
| 1182 | |
| 1183 | void RenderViewImpl::PepperInstanceDeleted( |
| 1184 | PepperPluginInstanceImpl* instance) { |
| 1185 | active_pepper_instances_.erase(instance); |
| 1186 | |
| 1187 | if (pepper_last_mouse_event_target_ == instance) |
| 1188 | pepper_last_mouse_event_target_ = NULL; |
| 1189 | if (focused_pepper_plugin_ == instance) |
| 1190 | PepperFocusChanged(instance, false); |
| 1191 | } |
| 1192 | |
| 1193 | void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance, |
| 1194 | bool focused) { |
| 1195 | if (focused) |
| 1196 | focused_pepper_plugin_ = instance; |
| 1197 | else if (focused_pepper_plugin_ == instance) |
| 1198 | focused_pepper_plugin_ = NULL; |
| 1199 | |
shuchen | 3517bb6 | 2014-10-15 03:55:57 | [diff] [blame] | 1200 | UpdateTextInputType(); |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 1201 | UpdateSelectionBounds(); |
| 1202 | } |
| 1203 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1204 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1205 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1206 | // If the renderer is visible, set initial visibility and focus state. |
| 1207 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1208 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1209 | delegate->SetContainerVisibility(true); |
| 1210 | if (webview() && webview()->isActive()) |
| 1211 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1212 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1213 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1214 | // Plugins start assuming the content has focus (so that they work in |
| 1215 | // environments where RenderView isn't hosting them), so we always have to |
| 1216 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 1217 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1218 | } |
| 1219 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1220 | void RenderViewImpl::UnregisterPluginDelegate( |
| 1221 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1222 | plugin_delegates_.erase(delegate); |
| 1223 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1224 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 1225 | #if defined(OS_WIN) |
| 1226 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1227 | if (focused) |
| 1228 | focused_plugin_id_ = plugin_id; |
| 1229 | else |
| 1230 | focused_plugin_id_ = -1; |
| 1231 | } |
| 1232 | #endif |
| 1233 | |
| 1234 | #if defined(OS_MACOSX) |
| 1235 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1236 | Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); |
| 1237 | } |
| 1238 | |
[email protected] | 7411a3c | 2014-08-15 05:20:19 | [diff] [blame] | 1239 | void RenderViewImpl::OnGetRenderedText() { |
| 1240 | if (!webview()) |
| 1241 | return; |
| 1242 | // Get rendered text from WebLocalFrame. |
| 1243 | // TODO: Currently IPC truncates any data that has a |
| 1244 | // size > kMaximumMessageSize. May be split the text into smaller chunks and |
| 1245 | // send back using multiple IPC. See http://crbug.com/393444. |
| 1246 | static const size_t kMaximumMessageSize = 8 * 1024 * 1024; |
| 1247 | std::string text = webview()->mainFrame()->contentAsText( |
| 1248 | kMaximumMessageSize).utf8(); |
| 1249 | |
| 1250 | Send(new ViewMsg_GetRenderedTextCompleted(routing_id(), text)); |
| 1251 | } |
| 1252 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 1253 | void RenderViewImpl::StartPluginIme() { |
| 1254 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
| 1255 | // This message can be sent during event-handling, and needs to be delivered |
| 1256 | // within that context. |
| 1257 | msg->set_unblock(true); |
| 1258 | Send(msg); |
| 1259 | } |
| 1260 | #endif // defined(OS_MACOSX) |
| 1261 | |
| 1262 | #endif // ENABLE_PLUGINS |
| 1263 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 1264 | void RenderViewImpl::TransferActiveWheelFlingAnimation( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1265 | const blink::WebActiveWheelFlingParameters& params) { |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 1266 | if (webview()) |
| 1267 | webview()->transferActiveWheelFlingAnimation(params); |
| 1268 | } |
| 1269 | |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 1270 | bool RenderViewImpl::HasIMETextFocus() { |
| 1271 | return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
| 1272 | } |
| 1273 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1274 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1275 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 1276 | if (main_frame && main_frame->isWebLocalFrame()) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1277 | GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1278 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1279 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 1280 | RenderViewObserver* observer; |
| 1281 | while ((observer = it.GetNext()) != NULL) |
| 1282 | if (observer->OnMessageReceived(message)) |
| 1283 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1284 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1285 | bool handled = true; |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 1286 | IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1287 | IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand) |
| 1288 | IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1289 | IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect, |
| 1290 | OnScrollFocusedEditableNodeIntoRect) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1291 | IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent, |
| 1292 | OnSetEditCommandsForNextKeyEvent) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1293 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 6a6fa3e | 2014-05-09 06:57:18 | [diff] [blame] | 1294 | IPC_MESSAGE_HANDLER(ViewMsg_SaveImageAt, OnSaveImageAt) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1295 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 1296 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 1297 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1298 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 1299 | OnSetZoomLevelForLoadingURL) |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 1300 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForView, |
| 1301 | OnSetZoomLevelForView) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1302 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1303 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 1304 | OnResetPageEncodingToDefault) |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 1305 | IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1306 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 1307 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 1308 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 1309 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
[email protected] | 7a6d773f | 2014-04-04 01:25:09 | [diff] [blame] | 1310 | IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1311 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 1312 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 1313 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1314 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1315 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 1316 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1317 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 1318 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1319 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 1320 | IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut, |
| 1321 | OnSuppressDialogsUntilSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1322 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 1323 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1324 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | ab6c911 | 2014-02-27 00:20:58 | [diff] [blame] | 1325 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement, OnClearFocusedElement) |
[email protected] | 61f9183 | 2014-05-13 01:24:42 | [diff] [blame] | 1326 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 1327 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 1328 | OnEnablePreferredSizeChangedMode) |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1329 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1330 | IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 1331 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 1332 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1333 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 1334 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1335 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 1336 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 1337 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 1338 | OnGetAllSavableResourceLinksForCurrentPage) |
| 1339 | IPC_MESSAGE_HANDLER( |
| 1340 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 1341 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 1342 | IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 1343 | // TODO(viettrungluu): Move to a separate message filter. |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 1344 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryOffsetAndLength, |
| 1345 | OnSetHistoryOffsetAndLength) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 1346 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | cb189e06 | 2014-04-23 00:57:01 | [diff] [blame] | 1347 | IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupBitmap, |
| 1348 | OnReleaseDisambiguationPopupBitmap) |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 1349 | IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, |
| 1350 | OnWindowSnapshotCompleted) |
[email protected] | 506563d | 2014-06-23 12:22:41 | [diff] [blame] | 1351 | IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw, OnForceRedraw) |
[email protected] | 4dda6a6c | 2014-05-17 15:35:04 | [diff] [blame] | 1352 | IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1353 | #if defined(OS_ANDROID) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1354 | IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult, |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1355 | OnActivateNearestFindResult) |
| 1356 | IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects) |
[email protected] | 452b4a9 | 2013-03-28 21:24:38 | [diff] [blame] | 1357 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState, |
| 1358 | OnUpdateTopControlsState) |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 1359 | IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData, OnExtractSmartClipData) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1360 | #elif defined(OS_MACOSX) |
[email protected] | 7411a3c | 2014-08-15 05:20:19 | [diff] [blame] | 1361 | IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText, |
| 1362 | OnGetRenderedText) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1363 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 1364 | OnPluginImeCompositionCompleted) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1365 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1366 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| 1367 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| 1368 | #endif |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 1369 | // Adding a new message? Add platform independent ones first, then put the |
| 1370 | // platform specific ones at the end. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1371 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1372 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1373 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1374 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1375 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1376 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1377 | } |
| 1378 | |
[email protected] | 4dda6a6c | 2014-05-17 15:35:04 | [diff] [blame] | 1379 | void RenderViewImpl::OnSelectWordAroundCaret() { |
| 1380 | if (!webview()) |
| 1381 | return; |
| 1382 | |
| 1383 | handling_input_event_ = true; |
| 1384 | webview()->focusedFrame()->selectWordAroundCaret(); |
| 1385 | handling_input_event_ = false; |
| 1386 | } |
| 1387 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1388 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1389 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1390 | } |
| 1391 | |
[email protected] | 6a6fa3e | 2014-05-09 06:57:18 | [diff] [blame] | 1392 | void RenderViewImpl::OnSaveImageAt(int x, int y) { |
| 1393 | webview()->saveImageAt(WebPoint(x, y)); |
| 1394 | } |
| 1395 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1396 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1397 | // Check if there is a targeturl waiting to be sent. |
avi | 450ce00e | 2014-09-24 01:58:52 | [diff] [blame] | 1398 | if (target_url_status_ == TARGET_PENDING) |
| 1399 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, pending_target_url_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1400 | |
| 1401 | target_url_status_ = TARGET_NONE; |
| 1402 | } |
| 1403 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1404 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
| 1405 | const std::string& value) { |
| 1406 | if (!webview() || !webview()->focusedFrame()) |
| 1407 | return; |
| 1408 | |
| 1409 | webview()->focusedFrame()->executeCommand( |
| 1410 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
| 1411 | } |
| 1412 | |
| 1413 | void RenderViewImpl::OnMoveCaret(const gfx::Point& point) { |
| 1414 | if (!webview()) |
| 1415 | return; |
| 1416 | |
christiank | aeed986 | 2014-11-05 10:49:14 | [diff] [blame] | 1417 | Send(new InputHostMsg_MoveCaret_ACK(routing_id_)); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1418 | |
[email protected] | b74d4064d | 2013-11-27 01:45:09 | [diff] [blame] | 1419 | webview()->focusedFrame()->moveCaretSelection(point); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1420 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1421 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1422 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1423 | const gfx::Rect& rect) { |
[email protected] | 1875bc0 | 2014-03-14 06:33:59 | [diff] [blame] | 1424 | if (has_scrolled_focused_editable_node_into_rect_ && |
| 1425 | rect == rect_for_scrolled_focused_editable_node_) { |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 1426 | FocusChangeComplete(); |
[email protected] | 1875bc0 | 2014-03-14 06:33:59 | [diff] [blame] | 1427 | return; |
| 1428 | } |
| 1429 | |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 1430 | blink::WebElement element = GetFocusedElement(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 1431 | bool will_animate = false; |
[email protected] | 1875bc0 | 2014-03-14 06:33:59 | [diff] [blame] | 1432 | if (!element.isNull() && IsEditableNode(element)) { |
| 1433 | rect_for_scrolled_focused_editable_node_ = rect; |
| 1434 | has_scrolled_focused_editable_node_into_rect_ = true; |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 1435 | will_animate = webview()->scrollFocusedNodeIntoRect(rect); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1436 | } |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 1437 | |
| 1438 | if (!will_animate) |
| 1439 | FocusChangeComplete(); |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1440 | } |
| 1441 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1442 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
| 1443 | const EditCommands& edit_commands) { |
| 1444 | edit_commands_ = edit_commands; |
| 1445 | } |
| 1446 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 1447 | void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset, |
| 1448 | int history_length) { |
| 1449 | DCHECK_GE(history_offset, -1); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1450 | DCHECK_GE(history_length, 0); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1451 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 1452 | history_list_offset_ = history_offset; |
| 1453 | history_list_length_ = history_length; |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1454 | } |
| 1455 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1456 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1457 | if (!webview()) |
| 1458 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1459 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1460 | } |
| 1461 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1462 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1463 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1464 | if (!webview()) |
| 1465 | return; |
| 1466 | if (in_live_resize) |
| 1467 | webview()->willStartLiveResize(); |
| 1468 | else |
| 1469 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1470 | } |
| 1471 | #endif |
| 1472 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1473 | /////////////////////////////////////////////////////////////////////////////// |
| 1474 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1475 | // Sends the current history state to the browser so it will be saved before we |
| 1476 | // navigate to a new page. |
| 1477 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
| 1478 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1479 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1480 | // there is no past session history to record. |
| 1481 | if (page_id_ == -1) |
| 1482 | return; |
| 1483 | SendUpdateState(history_controller_->GetCurrentEntry()); |
| 1484 | } |
| 1485 | |
| 1486 | void RenderViewImpl::SendUpdateState(HistoryEntry* entry) { |
| 1487 | if (!entry) |
| 1488 | return; |
| 1489 | |
| 1490 | // Don't send state updates for kSwappedOutURL. |
| 1491 | if (entry->root().urlString() == WebString::fromUTF8(kSwappedOutURL)) |
| 1492 | return; |
| 1493 | |
| 1494 | Send(new ViewHostMsg_UpdateState( |
| 1495 | routing_id_, page_id_, HistoryEntryToPageState(entry))); |
| 1496 | } |
| 1497 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1498 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1499 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1500 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1501 | // it is particularly important that we do not call willEnterModalLoop as |
| 1502 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1503 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 1504 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1505 | |
| 1506 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1507 | return Send(message); |
| 1508 | } |
| 1509 | |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 1510 | void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) { |
| 1511 | int id = next_snapshot_id_++; |
| 1512 | pending_snapshots_.insert(std::make_pair(id, callback)); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1513 | ui::LatencyInfo latency_info; |
[email protected] | 506563d | 2014-06-23 12:22:41 | [diff] [blame] | 1514 | latency_info.AddLatencyNumber(ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
| 1515 | 0, |
| 1516 | id); |
| 1517 | scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor; |
| 1518 | if (RenderWidgetCompositor* rwc = compositor()) { |
| 1519 | latency_info_swap_promise_monitor = |
| 1520 | rwc->CreateLatencyInfoSwapPromiseMonitor(&latency_info).Pass(); |
| 1521 | } |
| 1522 | ScheduleCompositeWithForcedRedraw(); |
| 1523 | } |
| 1524 | |
| 1525 | void RenderViewImpl::OnForceRedraw(int id) { |
| 1526 | ui::LatencyInfo latency_info; |
[email protected] | f9f3fac | 2014-08-05 00:47:59 | [diff] [blame] | 1527 | if (id) { |
| 1528 | latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
| 1529 | 0, |
| 1530 | id); |
| 1531 | } |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 1532 | scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor; |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1533 | if (RenderWidgetCompositor* rwc = compositor()) { |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 1534 | latency_info_swap_promise_monitor = |
| 1535 | rwc->CreateLatencyInfoSwapPromiseMonitor(&latency_info).Pass(); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1536 | } |
| 1537 | ScheduleCompositeWithForcedRedraw(); |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, |
| 1541 | const gfx::Size& size, const std::vector<unsigned char>& png) { |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 1542 | |
| 1543 | // Any pending snapshots with a lower ID than the one received are considered |
| 1544 | // to be implicitly complete, and returned the same snapshot data. |
| 1545 | PendingSnapshotMap::iterator it = pending_snapshots_.begin(); |
| 1546 | while(it != pending_snapshots_.end()) { |
| 1547 | if (it->first <= snapshot_id) { |
| 1548 | it->second.Run(size, png); |
| 1549 | pending_snapshots_.erase(it++); |
| 1550 | } else { |
| 1551 | ++it; |
| 1552 | } |
| 1553 | } |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 1554 | } |
| 1555 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1556 | // blink::WebViewClient ------------------------------------------------------ |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1557 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 1558 | WebView* RenderViewImpl::createView(WebLocalFrame* creator, |
| 1559 | const WebURLRequest& request, |
| 1560 | const WebWindowFeatures& features, |
| 1561 | const WebString& frame_name, |
| 1562 | WebNavigationPolicy policy, |
| 1563 | bool suppress_opener) { |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1564 | ViewHostMsg_CreateWindow_Params params; |
| 1565 | params.opener_id = routing_id_; |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 1566 | params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame] | 1567 | if (GetContentClient()->renderer()->AllowPopup()) |
| 1568 | params.user_gesture = true; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1569 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1570 | params.session_storage_namespace_id = session_storage_namespace_id_; |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 1571 | if (frame_name != "_blank") |
| 1572 | params.frame_name = frame_name; |
[email protected] | a7531d77 | 2014-03-25 16:15:07 | [diff] [blame] | 1573 | params.opener_render_frame_id = |
[email protected] | 501052ff | 2014-02-21 22:19:07 | [diff] [blame] | 1574 | RenderFrameImpl::FromWebFrame(creator)->GetRoutingID(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1575 | params.opener_url = creator->document().url(); |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 1576 | params.opener_top_level_frame_url = creator->top()->document().url(); |
[email protected] | 6c53a7f | 2014-03-31 16:56:28 | [diff] [blame] | 1577 | GURL security_url(creator->document().securityOrigin().toString()); |
[email protected] | 7f48b71 | 2013-01-25 01:48:30 | [diff] [blame] | 1578 | if (!security_url.is_valid()) |
| 1579 | security_url = GURL(); |
| 1580 | params.opener_security_origin = security_url; |
[email protected] | 147b2bf | 2013-11-05 04:00:04 | [diff] [blame] | 1581 | params.opener_suppressed = suppress_opener; |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 1582 | params.disposition = NavigationPolicyToDisposition(policy); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 1583 | if (!request.isNull()) { |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1584 | params.target_url = request.url(); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 1585 | params.referrer = GetReferrerFromRequest(creator, request); |
| 1586 | } |
[email protected] | 453c1b2 | 2013-07-23 09:31:48 | [diff] [blame] | 1587 | params.features = features; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1588 | |
[email protected] | 22217ed3 | 2013-11-18 18:40:23 | [diff] [blame] | 1589 | for (size_t i = 0; i < features.additionalFeatures.size(); ++i) |
| 1590 | params.additional_features.push_back(features.additionalFeatures[i]); |
| 1591 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1592 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1593 | int32 main_frame_routing_id = MSG_ROUTING_NONE; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1594 | int32 surface_id = 0; |
[email protected] | 176fe9a | 2014-07-08 02:31:53 | [diff] [blame] | 1595 | int64 cloned_session_storage_namespace_id = 0; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1596 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1597 | RenderThread::Get()->Send(new ViewHostMsg_CreateWindow( |
| 1598 | params, &routing_id, &main_frame_routing_id, &surface_id, |
| 1599 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1600 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1601 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1602 | |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 1603 | WebUserGestureIndicator::consumeUserGesture(); |
[email protected] | c5926242 | 2012-11-30 21:20:52 | [diff] [blame] | 1604 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 1605 | // While this view may be a background extension page, it can spawn a visible |
| 1606 | // render view. So we just assume that the new one is not another background |
| 1607 | // page instead of passing on our own value. |
| 1608 | // TODO(vangelis): Can we tell if the new view will be a background page? |
| 1609 | bool never_visible = false; |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 1610 | |
mkosiba | 58fa72f0 | 2014-11-12 01:21:36 | [diff] [blame] | 1611 | ViewMsg_Resize_Params initial_size = ViewMsg_Resize_Params(); |
| 1612 | initial_size.screen_info = screen_info_; |
| 1613 | |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 1614 | // The initial hidden state for the RenderViewImpl here has to match what the |
| 1615 | // browser will eventually decide for the given disposition. Since we have to |
| 1616 | // return from this call synchronously, we just have to make our best guess |
| 1617 | // and rely on the browser sending a WasHidden / WasShown message if it |
| 1618 | // disagrees. |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 1619 | ViewMsg_New_Params view_params; |
| 1620 | view_params.opener_route_id = routing_id_; |
| 1621 | view_params.window_was_created_with_opener = true; |
| 1622 | view_params.renderer_preferences = renderer_preferences_; |
| 1623 | view_params.web_preferences = webkit_preferences_; |
| 1624 | view_params.view_id = routing_id; |
| 1625 | view_params.main_frame_routing_id = main_frame_routing_id; |
| 1626 | view_params.surface_id = surface_id; |
| 1627 | view_params.session_storage_namespace_id = |
| 1628 | cloned_session_storage_namespace_id; |
| 1629 | // WebCore will take care of setting the correct name. |
| 1630 | view_params.frame_name = base::string16(); |
| 1631 | view_params.swapped_out = false; |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 1632 | view_params.replicated_frame_state = FrameReplicationState(); |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 1633 | view_params.proxy_routing_id = MSG_ROUTING_NONE; |
| 1634 | view_params.hidden = (params.disposition == NEW_BACKGROUND_TAB); |
| 1635 | view_params.never_visible = never_visible; |
| 1636 | view_params.next_page_id = 1; |
| 1637 | view_params.initial_size = initial_size; |
| 1638 | view_params.enable_auto_resize = false; |
| 1639 | view_params.min_size = gfx::Size(); |
| 1640 | view_params.max_size = gfx::Size(); |
| 1641 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1642 | RenderViewImpl* view = |
| 1643 | RenderViewImpl::Create(view_params, compositor_deps_, true); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1644 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1645 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1646 | // Record whether the creator frame is trying to suppress the opener field. |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 1647 | view->opener_suppressed_ = params.opener_suppressed; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1648 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1649 | return view->webview(); |
| 1650 | } |
| 1651 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1652 | WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) { |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1653 | RenderWidget* widget = RenderWidget::Create(routing_id_, compositor_deps_, |
| 1654 | popup_type, screen_info_); |
[email protected] | 3b78ec1 | 2014-03-04 05:18:28 | [diff] [blame] | 1655 | if (!widget) |
| 1656 | return NULL; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1657 | if (screen_metrics_emulator_) { |
| 1658 | widget->SetPopupOriginAdjustmentsForEmulation( |
| 1659 | screen_metrics_emulator_.get()); |
| 1660 | } |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1661 | return widget->webwidget(); |
| 1662 | } |
| 1663 | |
[email protected] | 2336748 | 2013-06-27 21:06:54 | [diff] [blame] | 1664 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() { |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 1665 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1666 | return new WebStorageNamespaceImpl(session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1667 | } |
| 1668 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 1669 | void RenderViewImpl::printPage(WebLocalFrame* frame) { |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 1670 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 1671 | PrintPage(frame, handling_input_event_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1672 | } |
| 1673 | |
jinho.bang | 632a1a72 | 2014-09-18 03:02:56 | [diff] [blame] | 1674 | void RenderViewImpl::saveImageFromDataURL(const blink::WebString& data_url) { |
| 1675 | // Note: We should basically send GURL but we use size-limited string instead |
| 1676 | // in order to send a larger data url to save a image for <canvas> or <img>. |
| 1677 | if (data_url.length() < kMaxLengthOfDataURLString) |
| 1678 | Send(new ViewHostMsg_SaveImageFromDataURL(routing_id_, data_url.utf8())); |
| 1679 | } |
| 1680 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1681 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1682 | const WebString& path, |
| 1683 | WebFileChooserCompletion* chooser_completion) { |
| 1684 | int id = enumeration_completion_id_++; |
| 1685 | enumeration_completions_[id] = chooser_completion; |
| 1686 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 1687 | routing_id_, |
| 1688 | id, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 1689 | base::FilePath::FromUTF16Unsafe(path))); |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1690 | } |
| 1691 | |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1692 | void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) { |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1693 | DCHECK_GE(frames_in_progress_, 0); |
| 1694 | if (frames_in_progress_ == 0) |
| 1695 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
| 1696 | frames_in_progress_++; |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 1697 | } |
| 1698 | |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1699 | void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) { |
[email protected] | eb47377 | 2014-04-11 20:54:33 | [diff] [blame] | 1700 | // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes |
| 1701 | // calls DidStopLoading() without a matching DidStartLoading(). |
| 1702 | if (frames_in_progress_ == 0) |
| 1703 | return; |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1704 | frames_in_progress_--; |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1705 | if (frames_in_progress_ == 0) { |
| 1706 | DidStopLoadingIcons(); |
| 1707 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
| 1708 | } |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1709 | } |
| 1710 | |
[email protected] | 550b0c9 | 2013-02-04 05:09:15 | [diff] [blame] | 1711 | void RenderViewImpl::didCancelCompositionOnSelectionChange() { |
[email protected] | a2214eb | 2014-06-23 18:31:22 | [diff] [blame] | 1712 | Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
[email protected] | 550b0c9 | 2013-02-04 05:09:15 | [diff] [blame] | 1713 | } |
| 1714 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1715 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1716 | if (edit_commands_.empty()) |
| 1717 | return false; |
| 1718 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1719 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1720 | if (!frame) |
| 1721 | return false; |
| 1722 | |
| 1723 | EditCommands::iterator it = edit_commands_.begin(); |
| 1724 | EditCommands::iterator end = edit_commands_.end(); |
| 1725 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1726 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1727 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 1728 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 1729 | // key (but it's the exception). Once one edit command is not executed, it |
| 1730 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1731 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 1732 | WebString::fromUTF8(it->value), |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 1733 | GetFocusedElement())) |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1734 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1735 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1736 | } |
| 1737 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1738 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1739 | } |
| 1740 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1741 | bool RenderViewImpl::runFileChooser( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1742 | const blink::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1743 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 1744 | // Do not open the file dialog in a hidden RenderView. |
| 1745 | if (is_hidden()) |
| 1746 | return false; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1747 | FileChooserParams ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1748 | if (params.directory) |
[email protected] | 6bedbef | 2013-07-31 06:33:49 | [diff] [blame] | 1749 | ipc_params.mode = FileChooserParams::UploadFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1750 | else if (params.multiSelect) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1751 | ipc_params.mode = FileChooserParams::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame] | 1752 | else if (params.saveAs) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1753 | ipc_params.mode = FileChooserParams::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1754 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1755 | ipc_params.mode = FileChooserParams::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1756 | ipc_params.title = params.title; |
| 1757 | ipc_params.default_file_name = |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 1758 | base::FilePath::FromUTF16Unsafe(params.initialValue); |
[email protected] | f9a4c41a | 2012-05-30 00:05:32 | [diff] [blame] | 1759 | ipc_params.accept_types.reserve(params.acceptTypes.size()); |
| 1760 | for (size_t i = 0; i < params.acceptTypes.size(); ++i) |
| 1761 | ipc_params.accept_types.push_back(params.acceptTypes[i]); |
hirono | e9f2732b | 2014-10-22 08:06:41 | [diff] [blame] | 1762 | ipc_params.need_local_path = params.needLocalPath; |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 1763 | #if defined(OS_ANDROID) |
[email protected] | b7b4beb | 2013-07-09 14:06:50 | [diff] [blame] | 1764 | ipc_params.capture = params.useMediaCapture; |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 1765 | #endif |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1766 | |
| 1767 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1768 | } |
| 1769 | |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1770 | void RenderViewImpl::SetValidationMessageDirection( |
| 1771 | base::string16* wrapped_main_text, |
| 1772 | blink::WebTextDirection main_text_hint, |
| 1773 | base::string16* wrapped_sub_text, |
| 1774 | blink::WebTextDirection sub_text_hint) { |
| 1775 | if (main_text_hint == blink::WebTextDirectionLeftToRight) { |
| 1776 | *wrapped_main_text = |
| 1777 | base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text); |
| 1778 | } else if (main_text_hint == blink::WebTextDirectionRightToLeft && |
| 1779 | !base::i18n::IsRTL()) { |
| 1780 | base::i18n::WrapStringWithRTLFormatting(wrapped_main_text); |
| 1781 | } |
| 1782 | |
| 1783 | if (!wrapped_sub_text->empty()) { |
| 1784 | if (sub_text_hint == blink::WebTextDirectionLeftToRight) { |
| 1785 | *wrapped_sub_text = |
| 1786 | base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text); |
| 1787 | } else if (sub_text_hint == blink::WebTextDirectionRightToLeft) { |
| 1788 | base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text); |
| 1789 | } |
| 1790 | } |
| 1791 | } |
| 1792 | |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1793 | void RenderViewImpl::showValidationMessage( |
| 1794 | const blink::WebRect& anchor_in_root_view, |
| 1795 | const blink::WebString& main_text, |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1796 | blink::WebTextDirection main_text_hint, |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1797 | const blink::WebString& sub_text, |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1798 | blink::WebTextDirection sub_text_hint) { |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1799 | base::string16 wrapped_main_text = main_text; |
| 1800 | base::string16 wrapped_sub_text = sub_text; |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1801 | |
| 1802 | SetValidationMessageDirection( |
| 1803 | &wrapped_main_text, main_text_hint, &wrapped_sub_text, sub_text_hint); |
| 1804 | |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1805 | Send(new ViewHostMsg_ShowValidationMessage( |
[email protected] | 2d6836f4 | 2014-07-02 17:25:31 | [diff] [blame] | 1806 | routing_id(), AdjustValidationMessageAnchor(anchor_in_root_view), |
| 1807 | wrapped_main_text, wrapped_sub_text)); |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | void RenderViewImpl::hideValidationMessage() { |
| 1811 | Send(new ViewHostMsg_HideValidationMessage(routing_id())); |
| 1812 | } |
| 1813 | |
| 1814 | void RenderViewImpl::moveValidationMessage( |
| 1815 | const blink::WebRect& anchor_in_root_view) { |
[email protected] | 2d6836f4 | 2014-07-02 17:25:31 | [diff] [blame] | 1816 | Send(new ViewHostMsg_MoveValidationMessage( |
| 1817 | routing_id(), AdjustValidationMessageAnchor(anchor_in_root_view))); |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1818 | } |
| 1819 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1820 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1821 | } |
| 1822 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1823 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 1824 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 1825 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1826 | if (latest_url == target_url_) |
| 1827 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1828 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1829 | // Tell the browser to display a destination link. |
| 1830 | if (target_url_status_ == TARGET_INFLIGHT || |
| 1831 | target_url_status_ == TARGET_PENDING) { |
| 1832 | // If we have a request in-flight, save the URL to be sent when we |
| 1833 | // receive an ACK to the in-flight request. We can happily overwrite |
| 1834 | // any existing pending sends. |
| 1835 | pending_target_url_ = latest_url; |
| 1836 | target_url_status_ = TARGET_PENDING; |
| 1837 | } else { |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 1838 | // URLs larger than |MaxURLChars()| cannot be sent through IPC - |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 1839 | // see |ParamTraits<GURL>|. |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 1840 | if (latest_url.possibly_invalid_spec().size() > GetMaxURLChars()) |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 1841 | latest_url = GURL(); |
avi | 450ce00e | 2014-09-24 01:58:52 | [diff] [blame] | 1842 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, latest_url)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1843 | target_url_ = latest_url; |
| 1844 | target_url_status_ = TARGET_INFLIGHT; |
| 1845 | } |
| 1846 | } |
| 1847 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 1848 | gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect( |
| 1849 | const gfx::RectF& rect) const { |
| 1850 | gfx::RectF window_rect = rect; |
| 1851 | window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor()); |
| 1852 | return window_rect; |
| 1853 | } |
| 1854 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1855 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
| 1856 | // No need to update state if no page has committed yet. |
[email protected] | a183fb8 | 2012-12-14 04:46:22 | [diff] [blame] | 1857 | if (page_id_ == -1) |
| 1858 | return; |
| 1859 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1860 | int delay; |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1861 | if (send_content_state_immediately_) |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1862 | delay = 0; |
| 1863 | else if (is_hidden()) |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1864 | delay = kDelaySecondsForContentStateSyncHidden; |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1865 | else |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1866 | delay = kDelaySecondsForContentStateSync; |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1867 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1868 | if (nav_state_sync_timer_.IsRunning()) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1869 | // The timer is already running. If the delay of the timer maches the amount |
| 1870 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 1871 | // gets started with the right delay. |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1872 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1873 | return; |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1874 | nav_state_sync_timer_.Stop(); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1875 | } |
| 1876 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1877 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
| 1878 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1879 | } |
| 1880 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1881 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1882 | mouse_over_url_ = GURL(url); |
| 1883 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 1884 | } |
| 1885 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1886 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1887 | focus_url_ = GURL(url); |
| 1888 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 1889 | } |
| 1890 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 1891 | void RenderViewImpl::startDragging(WebLocalFrame* frame, |
[email protected] | 0407e42 | 2012-05-18 19:51:25 | [diff] [blame] | 1892 | const WebDragData& data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1893 | WebDragOperationsMask mask, |
| 1894 | const WebImage& image, |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 1895 | const WebPoint& webImageOffset) { |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 1896 | DropData drop_data(DropDataBuilder::Build(data)); |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 1897 | drop_data.referrer_policy = frame->document().referrerPolicy(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 1898 | gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1899 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 1900 | drop_data, |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1901 | mask, |
[email protected] | 97612707 | 2012-05-10 20:08:11 | [diff] [blame] | 1902 | image.getSkBitmap(), |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 1903 | imageOffset, |
| 1904 | possible_drag_event_info_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1905 | } |
| 1906 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1907 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 1908 | return renderer_preferences_.can_accept_load_drops; |
| 1909 | } |
| 1910 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1911 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1912 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 1913 | } |
| 1914 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1915 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1916 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 1917 | } |
| 1918 | |
estade | 31c5434 | 2015-01-23 03:34:36 | [diff] [blame^] | 1919 | void RenderViewImpl::focusedNodeChanged(const WebNode& fromNode, |
| 1920 | const WebNode& toNode) { |
[email protected] | 1875bc0 | 2014-03-14 06:33:59 | [diff] [blame] | 1921 | has_scrolled_focused_editable_node_into_rect_ = false; |
| 1922 | |
jennyz | 399d6e6 | 2014-12-16 01:40:05 | [diff] [blame] | 1923 | gfx::Rect node_bounds; |
estade | 31c5434 | 2015-01-23 03:34:36 | [diff] [blame^] | 1924 | if (!toNode.isNull() && toNode.isElementNode()) { |
| 1925 | WebNode web_node = const_cast<WebNode&>(toNode); |
jennyz | 399d6e6 | 2014-12-16 01:40:05 | [diff] [blame] | 1926 | node_bounds = gfx::Rect(web_node.to<WebElement>().boundsInViewportSpace()); |
| 1927 | } |
estade | 31c5434 | 2015-01-23 03:34:36 | [diff] [blame^] | 1928 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(toNode), |
jennyz | 399d6e6 | 2014-12-16 01:40:05 | [diff] [blame] | 1929 | node_bounds)); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 1930 | |
estade | 31c5434 | 2015-01-23 03:34:36 | [diff] [blame^] | 1931 | // TODO(estade): remove. |
| 1932 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(toNode)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1933 | |
estade | 31c5434 | 2015-01-23 03:34:36 | [diff] [blame^] | 1934 | RenderFrameImpl* previous_frame = nullptr; |
| 1935 | if (!fromNode.isNull()) |
| 1936 | previous_frame = RenderFrameImpl::FromWebFrame(fromNode.document().frame()); |
| 1937 | RenderFrameImpl* new_frame = nullptr; |
| 1938 | if (!toNode.isNull()) |
| 1939 | new_frame = RenderFrameImpl::FromWebFrame(toNode.document().frame()); |
| 1940 | |
| 1941 | if (previous_frame && previous_frame != new_frame) |
| 1942 | previous_frame->FocusedNodeChanged(WebNode()); |
| 1943 | if (new_frame) |
| 1944 | new_frame->FocusedNodeChanged(toNode); |
| 1945 | |
| 1946 | // TODO(dmazzoni): remove once there's a separate a11y tree per frame. |
| 1947 | GetMainRenderFrame()->FocusedNodeChangedForAccessibility(toNode); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 1948 | } |
| 1949 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 1950 | void RenderViewImpl::didUpdateLayout() { |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 1951 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout()); |
| 1952 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 1953 | // We don't always want to set up a timer, only if we've been put in that |
| 1954 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 1955 | // message. |
| 1956 | if (!send_preferred_size_changes_ || !webview()) |
| 1957 | return; |
| 1958 | |
| 1959 | if (check_preferred_size_timer_.IsRunning()) |
| 1960 | return; |
| 1961 | check_preferred_size_timer_.Start(FROM_HERE, |
| 1962 | TimeDelta::FromMilliseconds(0), this, |
| 1963 | &RenderViewImpl::CheckPreferredSize); |
| 1964 | } |
| 1965 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1966 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1967 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 1968 | } |
| 1969 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1970 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1971 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1972 | } |
| 1973 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1974 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1975 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1976 | } |
| 1977 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1978 | // blink::WebWidgetClient ---------------------------------------------------- |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1979 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1980 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1981 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 1982 | // we won't have to test for user gesture anymore and we can |
| 1983 | // move that code back to render_widget.cc |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 1984 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 1985 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 1986 | Send(new ViewHostMsg_Focus(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1987 | } |
| 1988 | } |
| 1989 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1990 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1991 | // TODO(jcivelli): see TODO above in didFocus(). |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 1992 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 1993 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 1994 | Send(new ViewHostMsg_Blur(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1995 | } |
| 1996 | } |
| 1997 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1998 | // 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] | 1999 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2000 | // point to dispatch the ShowView message. |
| 2001 | // |
| 2002 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 2003 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2004 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2005 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2006 | if (did_show_) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2007 | // When supports_multiple_windows is disabled, popups are reusing |
| 2008 | // the same view. In some scenarios, this makes WebKit to call show() twice. |
[email protected] | c9edabd | 2013-05-23 13:56:24 | [diff] [blame] | 2009 | if (webkit_preferences_.supports_multiple_windows) |
| 2010 | NOTREACHED() << "received extraneous Show call"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2011 | return; |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2012 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2013 | did_show_ = true; |
| 2014 | |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2015 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2016 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2017 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2018 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2019 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2020 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2021 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2022 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2023 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2024 | } |
| 2025 | |
[email protected] | dd48d49 | 2014-03-16 05:04:39 | [diff] [blame] | 2026 | void RenderViewImpl::runModal() { |
| 2027 | DCHECK(did_show_) << "should already have shown the view"; |
| 2028 | |
| 2029 | // Don't allow further dialogs if we are waiting to swap out, since the |
| 2030 | // PageGroupLoadDeferrer in our stack prevents it. |
| 2031 | if (suppress_dialogs_until_swap_out_) |
| 2032 | return; |
| 2033 | |
| 2034 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2035 | // showModalDialog to function properly. |
| 2036 | // |
| 2037 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2038 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2039 | // handed manner. |
| 2040 | // |
| 2041 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2042 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
| 2043 | |
| 2044 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal( |
| 2045 | routing_id_, opener_id_)); |
| 2046 | } |
| 2047 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 2048 | bool RenderViewImpl::requestPointerLock() { |
| 2049 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2050 | } |
| 2051 | |
| 2052 | void RenderViewImpl::requestPointerUnlock() { |
| 2053 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2054 | } |
| 2055 | |
| 2056 | bool RenderViewImpl::isPointerLocked() { |
| 2057 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2058 | webwidget_mouse_lock_target_.get()); |
| 2059 | } |
| 2060 | |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2061 | void RenderViewImpl::didHandleGestureEvent( |
| 2062 | const WebGestureEvent& event, |
| 2063 | bool event_cancelled) { |
| 2064 | RenderWidget::didHandleGestureEvent(event, event_cancelled); |
[email protected] | bb37b65 | 2013-11-27 23:47:11 | [diff] [blame] | 2065 | |
[email protected] | 91dcc6d3 | 2014-07-30 00:01:33 | [diff] [blame] | 2066 | if (!event_cancelled) { |
| 2067 | FOR_EACH_OBSERVER( |
| 2068 | RenderViewObserver, observers_, DidHandleGestureEvent(event)); |
| 2069 | } |
| 2070 | |
jdduke | 45762d2 | 2014-10-07 04:19:08 | [diff] [blame] | 2071 | // TODO(ananta): Piggyback off existing IPCs to communicate this information, |
| 2072 | // crbug/420130. |
| 2073 | #if defined(OS_WIN) |
[email protected] | bb37b65 | 2013-11-27 23:47:11 | [diff] [blame] | 2074 | if (event.type != blink::WebGestureEvent::GestureTap) |
| 2075 | return; |
| 2076 | |
[email protected] | 91dcc6d3 | 2014-07-30 00:01:33 | [diff] [blame] | 2077 | // TODO(estade): hit test the event against focused node to make sure |
| 2078 | // the tap actually hit the focused node. |
[email protected] | bb37b65 | 2013-11-27 23:47:11 | [diff] [blame] | 2079 | blink::WebTextInputType text_input_type = |
| 2080 | GetWebView()->textInputInfo().type; |
| 2081 | |
| 2082 | Send(new ViewHostMsg_FocusedNodeTouched( |
| 2083 | routing_id(), text_input_type != blink::WebTextInputTypeNone)); |
jdduke | 45762d2 | 2014-10-07 04:19:08 | [diff] [blame] | 2084 | #endif |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2085 | } |
| 2086 | |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 2087 | void RenderViewImpl::initializeLayerTreeView() { |
| 2088 | RenderWidget::initializeLayerTreeView(); |
| 2089 | RenderWidgetCompositor* rwc = compositor(); |
[email protected] | 9f7638f4 | 2014-05-30 01:51:16 | [diff] [blame] | 2090 | if (!rwc) |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 2091 | return; |
[email protected] | 9f7638f4 | 2014-05-30 01:51:16 | [diff] [blame] | 2092 | if (webview() && webview()->devToolsAgent()) |
| 2093 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 2094 | |
ccameron | 1f89c00 | 2014-10-21 06:19:05 | [diff] [blame] | 2095 | bool use_threaded_event_handling = true; |
| 2096 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 2097 | // Disable threaded event handling if content is not handling the elastic |
| 2098 | // overscroll effect. This includes the cases where the elastic overscroll |
| 2099 | // effect is being handled by Blink (because of command line flags) and older |
| 2100 | // operating system versions which do not have an elastic overscroll effect |
| 2101 | // (SnowLeopard, which has Aqua scrollbars which need synchronous updates). |
| 2102 | use_threaded_event_handling = compositor_deps_->IsElasticOverscrollEnabled(); |
[email protected] | 9f7638f4 | 2014-05-30 01:51:16 | [diff] [blame] | 2103 | #endif |
ccameron | 1f89c00 | 2014-10-21 06:19:05 | [diff] [blame] | 2104 | if (use_threaded_event_handling) { |
| 2105 | RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 2106 | // render_thread may be NULL in tests. |
| 2107 | InputHandlerManager* input_handler_manager = |
| 2108 | render_thread ? render_thread->input_handler_manager() : NULL; |
| 2109 | if (input_handler_manager) { |
| 2110 | input_handler_manager->AddInputHandler( |
| 2111 | routing_id_, rwc->GetInputHandler(), AsWeakPtr()); |
| 2112 | } |
| 2113 | } |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 2114 | } |
| 2115 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2116 | // blink::WebFrameClient ----------------------------------------------------- |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2117 | |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2118 | void RenderViewImpl::Repaint(const gfx::Size& size) { |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 2119 | OnRepaint(size); |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2120 | } |
| 2121 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 2122 | void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name, |
| 2123 | const std::string& value) { |
| 2124 | EditCommands edit_commands; |
| 2125 | edit_commands.push_back(EditCommand(name, value)); |
| 2126 | OnSetEditCommandsForNextKeyEvent(edit_commands); |
| 2127 | } |
| 2128 | |
| 2129 | void RenderViewImpl::ClearEditCommands() { |
| 2130 | edit_commands_.clear(); |
| 2131 | } |
| 2132 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2133 | SSLStatus RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame* frame) const { |
[email protected] | 83c0abca | 2013-07-23 20:09:42 | [diff] [blame] | 2134 | std::string security_info; |
| 2135 | if (frame && frame->dataSource()) |
| 2136 | security_info = frame->dataSource()->response().securityInfo(); |
| 2137 | |
| 2138 | SSLStatus ssl_status; |
| 2139 | DeserializeSecurityInfo(security_info, |
| 2140 | &ssl_status.cert_id, |
| 2141 | &ssl_status.cert_status, |
| 2142 | &ssl_status.security_bits, |
[email protected] | 0bbd63b | 2013-11-29 00:02:12 | [diff] [blame] | 2143 | &ssl_status.connection_status, |
| 2144 | &ssl_status.signed_certificate_timestamp_ids); |
[email protected] | 83c0abca | 2013-07-23 20:09:42 | [diff] [blame] | 2145 | return ssl_status; |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 2146 | } |
| 2147 | |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 2148 | const std::string& RenderViewImpl::GetAcceptLanguages() const { |
| 2149 | return renderer_preferences_.accept_languages; |
| 2150 | } |
| 2151 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2152 | void RenderViewImpl::didCreateDataSource(WebLocalFrame* frame, |
| 2153 | WebDataSource* ds) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2154 | bool content_initiated = !pending_navigation_params_.get(); |
| 2155 | |
[email protected] | f887290 | 2013-10-30 03:18:57 | [diff] [blame] | 2156 | // Make sure any previous redirect URLs end up in our new data source. |
| 2157 | if (pending_navigation_params_.get()) { |
| 2158 | for (std::vector<GURL>::const_iterator i = |
| 2159 | pending_navigation_params_->redirects.begin(); |
| 2160 | i != pending_navigation_params_->redirects.end(); ++i) { |
| 2161 | ds->appendRedirect(*i); |
| 2162 | } |
| 2163 | } |
| 2164 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2165 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 2166 | if (!document_state) { |
| 2167 | document_state = new DocumentState; |
| 2168 | ds->setExtraData(document_state); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2169 | if (!content_initiated) |
| 2170 | PopulateDocumentStateFromPending(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2171 | } |
| 2172 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2173 | // Carry over the user agent override flag, if it exists. |
| 2174 | if (content_initiated && webview() && webview()->mainFrame() && |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 2175 | webview()->mainFrame()->isWebLocalFrame() && |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2176 | webview()->mainFrame()->dataSource()) { |
| 2177 | DocumentState* old_document_state = |
| 2178 | DocumentState::FromDataSource(webview()->mainFrame()->dataSource()); |
| 2179 | if (old_document_state) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2180 | InternalDocumentStateData* internal_data = |
| 2181 | InternalDocumentStateData::FromDocumentState(document_state); |
| 2182 | InternalDocumentStateData* old_internal_data = |
| 2183 | InternalDocumentStateData::FromDocumentState(old_document_state); |
| 2184 | internal_data->set_is_overriding_user_agent( |
| 2185 | old_internal_data->is_overriding_user_agent()); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2189 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2190 | // non-null NavigationState. |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 2191 | if (content_initiated) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2192 | document_state->set_navigation_state( |
| 2193 | NavigationState::CreateContentInitiated()); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 2194 | } else { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2195 | document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 2196 | pending_navigation_params_.reset(); |
| 2197 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2198 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2199 | // DocumentState::referred_by_prefetcher_ is true if we are |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2200 | // navigating from a page that used prefetching using a link on that |
| 2201 | // page. We are early enough in the request process here that we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2202 | // can still see the DocumentState of the previous page and set |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2203 | // this value appropriately. |
| 2204 | // TODO(gavinp): catch the important case of navigation in a new |
| 2205 | // renderer process. |
| 2206 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2207 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2208 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2209 | const GURL referrer( |
| 2210 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 2211 | if (!referrer.is_empty() && old_frame->isWebLocalFrame() && |
| 2212 | DocumentState::FromDataSource(old_frame->dataSource()) |
| 2213 | ->was_prefetcher()) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2214 | for (; old_frame; old_frame = old_frame->traverseNext(false)) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2215 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 2216 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2217 | document_state->set_was_referred_by_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2218 | break; |
| 2219 | } |
| 2220 | } |
| 2221 | } |
| 2222 | } |
| 2223 | } |
| 2224 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2225 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2226 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2227 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2228 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2229 | document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2230 | break; |
| 2231 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
[email protected] | 2249206 | 2014-06-04 13:31:17 | [diff] [blame] | 2232 | case WebURLRequest::ReloadBypassingCache: // end-to-end reload. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2233 | document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2234 | break; |
| 2235 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2236 | document_state->set_load_type( |
| 2237 | DocumentState::LINK_LOAD_CACHE_STALE_OK); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2238 | break; |
| 2239 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2240 | document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2241 | break; |
[email protected] | 82f0e6c9 | 2014-06-02 08:18:39 | [diff] [blame] | 2242 | default: |
| 2243 | NOTREACHED(); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2244 | } |
| 2245 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2246 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 2247 | FOR_EACH_OBSERVER( |
| 2248 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2249 | } |
| 2250 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2251 | void RenderViewImpl::PopulateDocumentStateFromPending( |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2252 | DocumentState* document_state) { |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 2253 | const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2254 | document_state->set_request_time(params.request_time); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2255 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2256 | InternalDocumentStateData* internal_data = |
| 2257 | InternalDocumentStateData::FromDocumentState(document_state); |
| 2258 | |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 2259 | if (!params.common_params.url.SchemeIs(url::kJavaScriptScheme) && |
| 2260 | params.common_params.navigation_type == FrameMsg_Navigate_Type::RESTORE) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2261 | // We're doing a load of a page that was restored from the last session. By |
| 2262 | // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which |
| 2263 | // can result in stale data for pages that are set to expire. We explicitly |
| 2264 | // override that by setting the policy here so that as necessary we load |
| 2265 | // from the network. |
[email protected] | a8ff8ed | 2014-01-09 07:32:26 | [diff] [blame] | 2266 | // |
| 2267 | // TODO(davidben): Remove this in favor of passing a cache policy to the |
| 2268 | // loadHistoryItem call in OnNavigate. That requires not overloading |
| 2269 | // UseProtocolCachePolicy to mean both "normal load" and "determine cache |
| 2270 | // policy based on load type, etc". |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2271 | internal_data->set_cache_policy_override( |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2272 | WebURLRequest::UseProtocolCachePolicy); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2273 | } |
| 2274 | |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 2275 | if (IsReload(params.common_params.navigation_type)) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2276 | document_state->set_load_type(DocumentState::RELOAD); |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 2277 | else if (params.commit_params.page_state.IsValid()) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2278 | document_state->set_load_type(DocumentState::HISTORY_LOAD); |
| 2279 | else |
| 2280 | document_state->set_load_type(DocumentState::NORMAL_LOAD); |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 2281 | |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 2282 | internal_data->set_is_overriding_user_agent( |
| 2283 | params.commit_params.is_overriding_user_agent); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2284 | internal_data->set_must_reset_scroll_and_scale_state( |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 2285 | params.common_params.navigation_type == |
| 2286 | FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 2287 | document_state->set_can_load_local_resources(params.can_load_local_resources); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2288 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2289 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2290 | NavigationState* RenderViewImpl::CreateNavigationStateFromPending() { |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 2291 | const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2292 | NavigationState* navigation_state = NULL; |
| 2293 | |
| 2294 | // A navigation resulting from loading a javascript URL should not be treated |
| 2295 | // as a browser initiated event. Instead, we want it to look as if the page |
| 2296 | // initiated any load resulting from JS execution. |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 2297 | if (!params.common_params.url.SchemeIs(url::kJavaScriptScheme)) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2298 | navigation_state = NavigationState::CreateBrowserInitiated( |
| 2299 | params.page_id, |
| 2300 | params.pending_history_list_offset, |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 2301 | params.should_clear_history_list, |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 2302 | params.common_params.transition); |
[email protected] | 4972fc8 | 2013-11-19 04:33:42 | [diff] [blame] | 2303 | navigation_state->set_should_replace_current_entry( |
| 2304 | params.should_replace_current_entry); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2305 | navigation_state->set_transferred_request_child_id( |
| 2306 | params.transferred_request_child_id); |
| 2307 | navigation_state->set_transferred_request_request_id( |
| 2308 | params.transferred_request_request_id); |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 2309 | navigation_state->set_allow_download(params.common_params.allow_download); |
| 2310 | navigation_state->set_extra_headers(params.request_params.extra_headers); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2311 | } else { |
| 2312 | navigation_state = NavigationState::CreateContentInitiated(); |
| 2313 | } |
| 2314 | return navigation_state; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2315 | } |
| 2316 | |
[email protected] | 06181e5 | 2014-05-10 11:59:09 | [diff] [blame] | 2317 | void RenderViewImpl::didClearWindowObject(WebLocalFrame* frame) { |
| 2318 | FOR_EACH_OBSERVER( |
| 2319 | RenderViewObserver, observers_, DidClearWindowObject(frame)); |
[email protected] | 2904308 | 2014-01-22 21:53:51 | [diff] [blame] | 2320 | |
[email protected] | f5c9f088 | 2014-02-16 22:19:32 | [diff] [blame] | 2321 | if (enabled_bindings_& BINDINGS_POLICY_WEB_UI) |
| 2322 | WebUIExtension::Install(frame); |
| 2323 | |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 2324 | if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) |
| 2325 | StatsCollectionController::Install(frame); |
[email protected] | cdb6b1e | 2014-01-23 00:06:49 | [diff] [blame] | 2326 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 2327 | const base::CommandLine& command_line = |
| 2328 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | cdb6b1e | 2014-01-23 00:06:49 | [diff] [blame] | 2329 | |
| 2330 | if (command_line.HasSwitch(switches::kEnableSkiaBenchmarking)) |
| 2331 | SkiaBenchmarking::Install(frame); |
[email protected] | 3fad220d | 2014-01-23 11:30:06 | [diff] [blame] | 2332 | |
jochen | 26f63992 | 2014-10-23 21:59:57 | [diff] [blame] | 2333 | if (command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) |
| 2334 | GpuBenchmarking::Install(frame); |
| 2335 | |
[email protected] | 3fad220d | 2014-01-23 11:30:06 | [diff] [blame] | 2336 | if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking)) |
| 2337 | MemoryBenchmarkingExtension::Install(frame); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2338 | } |
| 2339 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2340 | void RenderViewImpl::didChangeIcon(WebLocalFrame* frame, |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 2341 | WebIconURL::Type icon_type) { |
| 2342 | if (frame->parent()) |
| 2343 | return; |
| 2344 | |
| 2345 | if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon) |
| 2346 | return; |
| 2347 | |
| 2348 | WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
| 2349 | std::vector<FaviconURL> urls; |
| 2350 | for (size_t i = 0; i < icon_urls.size(); i++) { |
[email protected] | 2bd262b | 2014-04-16 05:31:23 | [diff] [blame] | 2351 | std::vector<gfx::Size> sizes; |
[email protected] | f34ac13 | 2014-03-20 23:02:05 | [diff] [blame] | 2352 | ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); |
| 2353 | urls.push_back(FaviconURL( |
| 2354 | icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes)); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 2355 | } |
| 2356 | SendUpdateFaviconURL(urls); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 2357 | } |
| 2358 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2359 | void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) { |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 2360 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 2361 | } |
| 2362 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2363 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 2364 | // We don't always want to send the change messages over IPC, only if we've |
| 2365 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 2366 | // message. |
| 2367 | if (!send_preferred_size_changes_ || !webview()) |
| 2368 | return; |
| 2369 | |
[email protected] | e76b797 | 2013-06-06 02:58:48 | [diff] [blame] | 2370 | gfx::Size size = webview()->contentsPreferredMinimumSize(); |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 2371 | if (size == preferred_size_) |
| 2372 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2373 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 2374 | preferred_size_ = size; |
| 2375 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 2376 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2377 | } |
| 2378 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 2379 | void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) { |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 2380 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2381 | } |
| 2382 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2383 | void RenderViewImpl::SendFindReply(int request_id, |
| 2384 | int match_count, |
| 2385 | int ordinal, |
| 2386 | const WebRect& selection_rect, |
| 2387 | bool final_status_update) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2388 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 2389 | request_id, |
| 2390 | match_count, |
| 2391 | selection_rect, |
| 2392 | ordinal, |
| 2393 | final_status_update)); |
| 2394 | } |
| 2395 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2396 | blink::WebString RenderViewImpl::acceptLanguages() { |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame] | 2397 | return WebString::fromUTF8(renderer_preferences_.accept_languages); |
| 2398 | } |
| 2399 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2400 | // blink::WebPageSerializerClient implementation ------------------------------ |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 2401 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2402 | void RenderViewImpl::didSerializeDataForFrame( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 2403 | const WebURL& frame_url, |
| 2404 | const WebCString& data, |
| 2405 | WebPageSerializerClient::PageSerializationStatus status) { |
| 2406 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 2407 | routing_id(), |
| 2408 | frame_url, |
| 2409 | data.data(), |
| 2410 | static_cast<int32>(status))); |
| 2411 | } |
| 2412 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2413 | // RenderView implementation --------------------------------------------------- |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2414 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2415 | bool RenderViewImpl::Send(IPC::Message* message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2416 | return RenderWidget::Send(message); |
| 2417 | } |
| 2418 | |
mostynb | c3335323 | 2014-09-12 09:38:31 | [diff] [blame] | 2419 | RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() { |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 2420 | return main_render_frame_.get(); |
| 2421 | } |
| 2422 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2423 | int RenderViewImpl::GetRoutingID() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2424 | return routing_id_; |
| 2425 | } |
| 2426 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2427 | gfx::Size RenderViewImpl::GetSize() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2428 | return size(); |
| 2429 | } |
| 2430 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2431 | WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2432 | return webkit_preferences_; |
| 2433 | } |
| 2434 | |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 2435 | void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) { |
| 2436 | OnUpdateWebPreferences(preferences); |
| 2437 | } |
| 2438 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2439 | blink::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2440 | return webview(); |
| 2441 | } |
| 2442 | |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2443 | blink::WebElement RenderViewImpl::GetFocusedElement() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2444 | if (!webview()) |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2445 | return WebElement(); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2446 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 2447 | if (focused_frame) { |
| 2448 | WebDocument doc = focused_frame->document(); |
| 2449 | if (!doc.isNull()) |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2450 | return doc.focusedElement(); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2451 | } |
| 2452 | |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2453 | return WebElement(); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2454 | } |
| 2455 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2456 | bool RenderViewImpl::IsEditableNode(const WebNode& node) const { |
| 2457 | if (node.isNull()) |
| 2458 | return false; |
| 2459 | |
| 2460 | if (node.isContentEditable()) |
| 2461 | return true; |
| 2462 | |
| 2463 | if (node.isElementNode()) { |
| 2464 | const WebElement& element = node.toConst<WebElement>(); |
ajith.v | e77498c3 | 2014-10-22 05:32:29 | [diff] [blame] | 2465 | if (element.isTextFormControlElement()) { |
| 2466 | if (!(element.hasAttribute("readonly") || |
| 2467 | element.hasAttribute("disabled"))) |
| 2468 | return true; |
| 2469 | } |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2470 | |
| 2471 | // Also return true if it has an ARIA role of 'textbox'. |
| 2472 | for (unsigned i = 0; i < element.attributeCount(); ++i) { |
[email protected] | df80704 | 2014-08-13 16:48:41 | [diff] [blame] | 2473 | if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) { |
| 2474 | if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox")) |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2475 | return true; |
| 2476 | break; |
| 2477 | } |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2478 | } |
| 2479 | } |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2480 | |
| 2481 | return false; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2482 | } |
| 2483 | |
[email protected] | 91dcc6d3 | 2014-07-30 00:01:33 | [diff] [blame] | 2484 | bool RenderViewImpl::NodeContainsPoint(const WebNode& node, |
| 2485 | const gfx::Point& point) const { |
| 2486 | blink::WebHitTestResult hit_test = |
| 2487 | webview()->hitTestResultAt(WebPoint(point.x(), point.y())); |
| 2488 | return node.containsIncludingShadowDOM(hit_test.node()); |
| 2489 | } |
| 2490 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2491 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2492 | return (!send_preferred_size_changes_ || |
| 2493 | (disable_scrollbars_size_limit_.width() <= width || |
| 2494 | disable_scrollbars_size_limit_.height() <= height)); |
| 2495 | } |
| 2496 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2497 | int RenderViewImpl::GetEnabledBindings() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2498 | return enabled_bindings_; |
| 2499 | } |
| 2500 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 2501 | bool RenderViewImpl::GetContentStateImmediately() const { |
| 2502 | return send_content_state_immediately_; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2503 | } |
| 2504 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2505 | blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2506 | return visibilityState(); |
| 2507 | } |
| 2508 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2509 | void RenderViewImpl::DidStartLoading() { |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 2510 | main_render_frame_->didStartLoading(true); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | void RenderViewImpl::DidStopLoading() { |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 2514 | main_render_frame_->didStopLoading(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2515 | } |
| 2516 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 2517 | void RenderViewImpl::SyncNavigationState() { |
| 2518 | if (!webview()) |
| 2519 | return; |
| 2520 | SendUpdateState(history_controller_->GetCurrentEntry()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2521 | } |
| 2522 | |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2523 | blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() { |
| 2524 | if (!webview()) |
| 2525 | return NULL; |
| 2526 | |
| 2527 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 2528 | if (main_frame->isWebLocalFrame() && |
| 2529 | main_frame->document().isPluginDocument()) |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2530 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
| 2531 | |
| 2532 | #if defined(ENABLE_PLUGINS) |
| 2533 | if (plugin_find_handler_) |
| 2534 | return plugin_find_handler_->container()->plugin(); |
| 2535 | #endif |
| 2536 | |
| 2537 | return NULL; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2538 | } |
| 2539 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2540 | void RenderViewImpl::OnFind(int request_id, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 2541 | const base::string16& search_text, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2542 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2543 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2544 | blink::WebPlugin* plugin = GetWebPluginForFind(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 2545 | // Check if the plugin still exists in the document. |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2546 | if (plugin) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2547 | if (options.findNext) { |
| 2548 | // Just navigate back/forward. |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2549 | plugin->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2550 | } else { |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2551 | if (!plugin->startFind( |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 2552 | search_text, options.matchCase, request_id)) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 2553 | // Send "no results". |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2554 | SendFindReply(request_id, 0, 0, gfx::Rect(), true); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2555 | } |
| 2556 | } |
| 2557 | return; |
| 2558 | } |
| 2559 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 2560 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2561 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2562 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 2563 | |
| 2564 | bool multi_frame = (frame_after_main != main_frame); |
| 2565 | |
| 2566 | // If we have multiple frames, we don't want to wrap the search within the |
| 2567 | // frame, so we check here if we only have main_frame in the chain. |
| 2568 | bool wrap_within_frame = !multi_frame; |
| 2569 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 2570 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2571 | bool result = false; |
| 2572 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 2573 | // If something is selected when we start searching it means we cannot just |
| 2574 | // increment the current match ordinal; we need to re-generate it. |
| 2575 | WebRange current_selection = focused_frame->selectionRange(); |
| 2576 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2577 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2578 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2579 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2580 | |
| 2581 | if (!result) { |
| 2582 | // don't leave text selected as you move to the next frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 2583 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2584 | GetFocusedElement()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2585 | |
| 2586 | // Find the next frame, but skip the invisible ones. |
| 2587 | do { |
| 2588 | // What is the next frame to search? (we might be going backwards). Note |
| 2589 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2590 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 2591 | search_frame->traverseNext(true) : |
| 2592 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2593 | } while (!search_frame->hasVisibleContent() && |
| 2594 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2595 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 2596 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 2597 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2598 | GetFocusedElement()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2599 | |
| 2600 | // If we have multiple frames and we have wrapped back around to the |
| 2601 | // focused frame, we need to search it once more allowing wrap within |
| 2602 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 2603 | // reported matches, but no frames after the focused_frame contain a |
| 2604 | // match for the search word(s). |
| 2605 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2606 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2607 | request_id, search_text, options, true, // Force wrapping. |
| 2608 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2612 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2613 | } while (!result && search_frame != focused_frame); |
| 2614 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 2615 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2616 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2617 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2618 | } else { |
| 2619 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 2620 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 2621 | // yet what is active. |
| 2622 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 2623 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2624 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2625 | // If we find no matches then this will be our last status update. |
| 2626 | // Otherwise the scoping effort will send more results. |
| 2627 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2628 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2629 | SendFindReply(request_id, match_count, ordinal, selection_rect, |
| 2630 | final_status_update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2631 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2632 | // Scoping effort begins, starting with the mainframe. |
| 2633 | search_frame = main_frame; |
| 2634 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2635 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2636 | |
| 2637 | do { |
| 2638 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2639 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2640 | |
| 2641 | // We don't start another scoping effort unless at least one match has |
| 2642 | // been found. |
| 2643 | if (result) { |
| 2644 | // Start new scoping request. If the scoping function determines that it |
| 2645 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2646 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2647 | search_text, |
| 2648 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2649 | true); // reset the tickmarks |
| 2650 | } |
| 2651 | |
| 2652 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 2653 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 2654 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2655 | } while (search_frame != main_frame); |
| 2656 | } |
| 2657 | } |
| 2658 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2659 | void RenderViewImpl::OnStopFinding(StopFindAction action) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2660 | WebView* view = webview(); |
| 2661 | if (!view) |
| 2662 | return; |
| 2663 | |
[email protected] | 54ea9ff | 2014-03-20 00:27:54 | [diff] [blame] | 2664 | blink::WebPlugin* plugin = GetWebPluginForFind(); |
| 2665 | if (plugin) { |
| 2666 | plugin->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2667 | return; |
| 2668 | } |
| 2669 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2670 | bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 2671 | if (clear_selection) { |
| 2672 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2673 | GetFocusedElement()); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 2674 | } |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2675 | |
| 2676 | WebFrame* frame = view->mainFrame(); |
| 2677 | while (frame) { |
| 2678 | frame->stopFinding(clear_selection); |
| 2679 | frame = frame->traverseNext(false); |
| 2680 | } |
| 2681 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2682 | if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2683 | WebFrame* focused_frame = view->focusedFrame(); |
| 2684 | if (focused_frame) { |
| 2685 | WebDocument doc = focused_frame->document(); |
| 2686 | if (!doc.isNull()) { |
[email protected] | c39f744 | 2014-02-27 03:33:17 | [diff] [blame] | 2687 | WebElement element = doc.focusedElement(); |
| 2688 | if (!element.isNull()) |
| 2689 | element.simulateClick(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 2690 | } |
| 2691 | } |
| 2692 | } |
| 2693 | } |
| 2694 | |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 2695 | #if defined(OS_ANDROID) |
| 2696 | void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| 2697 | float x, float y) { |
| 2698 | if (!webview()) |
| 2699 | return; |
| 2700 | |
| 2701 | WebFrame* main_frame = webview()->mainFrame(); |
| 2702 | WebRect selection_rect; |
| 2703 | int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), |
| 2704 | &selection_rect); |
| 2705 | if (ordinal == -1) { |
| 2706 | // Something went wrong, so send a no-op reply (force the main_frame to |
| 2707 | // report the current match count) in case the host is waiting for a |
| 2708 | // response due to rate-limiting). |
| 2709 | main_frame->increaseMatchCount(0, request_id); |
| 2710 | return; |
| 2711 | } |
| 2712 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 2713 | SendFindReply(request_id, |
| 2714 | -1 /* number_of_matches */, |
| 2715 | ordinal, |
| 2716 | selection_rect, |
| 2717 | true /* final_update */); |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | void RenderViewImpl::OnFindMatchRects(int current_version) { |
| 2721 | if (!webview()) |
| 2722 | return; |
| 2723 | |
| 2724 | WebFrame* main_frame = webview()->mainFrame(); |
| 2725 | std::vector<gfx::RectF> match_rects; |
| 2726 | |
| 2727 | int rects_version = main_frame->findMatchMarkersVersion(); |
| 2728 | if (current_version != rects_version) { |
| 2729 | WebVector<WebFloatRect> web_match_rects; |
| 2730 | main_frame->findMatchRects(web_match_rects); |
| 2731 | match_rects.reserve(web_match_rects.size()); |
| 2732 | for (size_t i = 0; i < web_match_rects.size(); ++i) |
| 2733 | match_rects.push_back(gfx::RectF(web_match_rects[i])); |
| 2734 | } |
| 2735 | |
| 2736 | gfx::RectF active_rect = main_frame->activeFindMatchRect(); |
| 2737 | Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_, |
| 2738 | rects_version, |
| 2739 | match_rects, |
| 2740 | active_rect)); |
| 2741 | } |
| 2742 | #endif |
| 2743 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2744 | void RenderViewImpl::OnZoom(PageZoom zoom) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2745 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 2746 | return; |
| 2747 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 2748 | webview()->hidePopups(); |
[email protected] | 854ab546 | 2011-11-22 20:48:10 | [diff] [blame] | 2749 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2750 | double old_zoom_level = webview()->zoomLevel(); |
| 2751 | double zoom_level; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2752 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2753 | zoom_level = 0; |
| 2754 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 2755 | // Previous zoom level is a whole number, so just increment/decrement. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 2756 | zoom_level = old_zoom_level + zoom; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2757 | } else { |
| 2758 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 2759 | // not a whole number, or a plugin changed it to a custom value. We want |
| 2760 | // to go to the next whole number so that the user can always get back to |
| 2761 | // 100% with the keyboard/menu. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 2762 | if ((old_zoom_level > 1 && zoom > 0) || |
| 2763 | (old_zoom_level < 1 && zoom < 0)) { |
| 2764 | zoom_level = static_cast<int>(old_zoom_level + zoom); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2765 | } else { |
| 2766 | // We're going towards 100%, so first go to the next whole number. |
| 2767 | zoom_level = static_cast<int>(old_zoom_level); |
| 2768 | } |
| 2769 | } |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 2770 | webview()->setZoomLevel(zoom_level); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 2771 | zoomLevelChanged(); |
| 2772 | } |
| 2773 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2774 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 2775 | double zoom_level) { |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 2776 | #if !defined(OS_ANDROID) |
| 2777 | // On Android, page zoom isn't used, and in case of WebView, text zoom is used |
| 2778 | // for legacy WebView text scaling emulation. Thus, the code that resets |
| 2779 | // the zoom level from this map will be effectively resetting text zoom level. |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 2780 | host_zoom_levels_[url] = zoom_level; |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 2781 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2782 | } |
| 2783 | |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 2784 | void RenderViewImpl::OnSetZoomLevelForView(bool uses_temporary_zoom_level, |
| 2785 | double level) { |
| 2786 | uses_temporary_zoom_level_ = uses_temporary_zoom_level; |
| 2787 | |
| 2788 | webview()->hidePopups(); |
| 2789 | webview()->setZoomLevel(level); |
| 2790 | } |
| 2791 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2792 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2793 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2794 | } |
| 2795 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2796 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2797 | WebString no_encoding; |
| 2798 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 2799 | } |
| 2800 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2801 | void RenderViewImpl::OnPostMessageEvent( |
| 2802 | const ViewMsg_PostMessage_Params& params) { |
[email protected] | bf4a231 | 2013-04-23 00:32:11 | [diff] [blame] | 2803 | // TODO(nasko): Support sending to subframes. |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 2804 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2805 | |
| 2806 | // Find the source frame if it exists. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2807 | WebFrame* source_frame = NULL; |
| 2808 | if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 2809 | RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
| 2810 | if (source_view) |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 2811 | source_frame = source_view->webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2812 | } |
| 2813 | |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 2814 | // If the message contained MessagePorts, create the corresponding endpoints. |
| 2815 | DCHECK_EQ(params.message_port_ids.size(), params.new_routing_ids.size()); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2816 | blink::WebMessagePortChannelArray channels(params.message_port_ids.size()); |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 2817 | for (size_t i = 0; |
| 2818 | i < params.message_port_ids.size() && i < params.new_routing_ids.size(); |
| 2819 | ++i) { |
| 2820 | channels[i] = |
| 2821 | new WebMessagePortChannelImpl(params.new_routing_ids[i], |
| 2822 | params.message_port_ids[i], |
| 2823 | base::MessageLoopProxy::current().get()); |
| 2824 | } |
| 2825 | |
[email protected] | afe7d90d | 2014-07-19 05:10:22 | [diff] [blame] | 2826 | WebSerializedScriptValue serialized_script_value; |
| 2827 | if (params.is_data_raw_string) { |
| 2828 | v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
| 2829 | v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 2830 | v8::Context::Scope context_scope(context); |
| 2831 | V8ValueConverterImpl converter; |
| 2832 | converter.SetDateAllowed(true); |
| 2833 | converter.SetRegExpAllowed(true); |
| 2834 | scoped_ptr<base::Value> value(new base::StringValue(params.data)); |
| 2835 | v8::Handle<v8::Value> result_value = converter.ToV8Value(value.get(), |
| 2836 | context); |
| 2837 | serialized_script_value = WebSerializedScriptValue::serialize(result_value); |
| 2838 | } else { |
| 2839 | serialized_script_value = WebSerializedScriptValue::fromString(params.data); |
| 2840 | } |
| 2841 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2842 | // Create an event with the message. The final parameter to initMessageEvent |
| 2843 | // is the last event ID, which is not used with postMessage. |
| 2844 | WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
| 2845 | WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 2846 | msg_event.initMessageEvent("message", |
| 2847 | // |canBubble| and |cancellable| are always false |
| 2848 | false, false, |
[email protected] | afe7d90d | 2014-07-19 05:10:22 | [diff] [blame] | 2849 | serialized_script_value, |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 2850 | params.source_origin, source_frame, "", channels); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2851 | |
| 2852 | // We must pass in the target_origin to do the security check on this side, |
| 2853 | // since it may have changed since the original postMessage call was made. |
| 2854 | WebSecurityOrigin target_origin; |
| 2855 | if (!params.target_origin.empty()) { |
| 2856 | target_origin = |
| 2857 | WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 2858 | } |
| 2859 | frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 2860 | } |
| 2861 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2862 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 2863 | if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && |
| 2864 | !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { |
[email protected] | 69a0a13 | 2014-03-26 16:45:02 | [diff] [blame] | 2865 | // WebUIExtensionData deletes itself when we're destroyed. |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 2866 | new WebUIExtensionData(this); |
[email protected] | 69a0a13 | 2014-03-26 16:45:02 | [diff] [blame] | 2867 | // WebUIMojo deletes itself when we're destroyed. |
| 2868 | new WebUIMojo(this); |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 2869 | } |
| 2870 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 2871 | enabled_bindings_ |= enabled_bindings_flags; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2872 | |
| 2873 | // Keep track of the total bindings accumulated in this process. |
| 2874 | RenderProcess::current()->AddBindings(enabled_bindings_flags); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2875 | } |
| 2876 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 2877 | void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2878 | const gfx::Point& client_point, |
| 2879 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 2880 | WebDragOperationsMask ops, |
| 2881 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2882 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 2883 | DropDataToWebDragData(drop_data), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2884 | client_point, |
| 2885 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 2886 | ops, |
| 2887 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2888 | |
| 2889 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 2890 | } |
| 2891 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2892 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 2893 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 2894 | WebDragOperationsMask ops, |
| 2895 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2896 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 2897 | client_point, |
| 2898 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 2899 | ops, |
| 2900 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2901 | |
| 2902 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 2903 | } |
| 2904 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2905 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2906 | webview()->dragTargetDragLeave(); |
| 2907 | } |
| 2908 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2909 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 2910 | const gfx::Point& screen_point, |
| 2911 | int key_modifiers) { |
| 2912 | webview()->dragTargetDrop(client_point, screen_point, key_modifiers); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 2913 | |
| 2914 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2915 | } |
| 2916 | |
[email protected] | 7a6d773f | 2014-04-04 01:25:09 | [diff] [blame] | 2917 | void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point, |
| 2918 | const gfx::Point& screen_point, |
| 2919 | WebDragOperation op) { |
| 2920 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2921 | } |
| 2922 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2923 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2924 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2925 | } |
| 2926 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2927 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 2928 | webkit_preferences_ = prefs; |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 2929 | ApplyWebPreferences(webkit_preferences_, webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2930 | } |
| 2931 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2932 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 2933 | int id, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 2934 | const std::vector<base::FilePath>& paths) { |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 2935 | if (!enumeration_completions_[id]) |
| 2936 | return; |
| 2937 | |
| 2938 | WebVector<WebString> ws_file_names(paths.size()); |
| 2939 | for (size_t i = 0; i < paths.size(); ++i) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 2940 | ws_file_names[i] = paths[i].AsUTF16Unsafe(); |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 2941 | |
| 2942 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 2943 | enumeration_completions_.erase(id); |
| 2944 | } |
| 2945 | |
[email protected] | fb11b6a4 | 2012-03-14 07:25:12 | [diff] [blame] | 2946 | void RenderViewImpl::OnFileChooserResponse( |
hirono | 570357bd | 2014-10-08 12:39:27 | [diff] [blame] | 2947 | const std::vector<content::FileChooserFileInfo>& files) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 2948 | // This could happen if we navigated to a different page before the user |
| 2949 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2950 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 2951 | return; |
| 2952 | |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 2953 | // Convert Chrome's SelectedFileInfo list to WebKit's. |
| 2954 | WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files( |
| 2955 | files.size()); |
| 2956 | for (size_t i = 0; i < files.size(); ++i) { |
| 2957 | WebFileChooserCompletion::SelectedFileInfo selected_file; |
hirono | 570357bd | 2014-10-08 12:39:27 | [diff] [blame] | 2958 | selected_file.path = files[i].file_path.AsUTF16Unsafe(); |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 2959 | selected_file.displayName = |
| 2960 | base::FilePath(files[i].display_name).AsUTF16Unsafe(); |
hirono | e9f2732b | 2014-10-22 08:06:41 | [diff] [blame] | 2961 | if (files[i].file_system_url.is_valid()) { |
| 2962 | selected_file.fileSystemURL = files[i].file_system_url; |
| 2963 | selected_file.length = files[i].length; |
| 2964 | selected_file.modificationTime = files[i].modification_time.ToDoubleT(); |
| 2965 | selected_file.isDirectory = files[i].is_directory; |
| 2966 | } |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 2967 | selected_files[i] = selected_file; |
| 2968 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2969 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2970 | if (file_chooser_completions_.front()->completion) |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 2971 | file_chooser_completions_.front()->completion->didChooseFile( |
| 2972 | selected_files); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2973 | file_chooser_completions_.pop_front(); |
| 2974 | |
| 2975 | // If there are more pending file chooser requests, schedule one now. |
| 2976 | if (!file_chooser_completions_.empty()) { |
| 2977 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 2978 | file_chooser_completions_.front()->params)); |
| 2979 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2980 | } |
| 2981 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 2982 | void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
| 2983 | const gfx::Size& max_size) { |
| 2984 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 2985 | if (!webview()) |
| 2986 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 2987 | auto_resize_mode_ = true; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 2988 | webview()->enableAutoResizeMode(min_size, max_size); |
| 2989 | } |
| 2990 | |
| 2991 | void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) { |
| 2992 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 2993 | if (!webview()) |
| 2994 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 2995 | auto_resize_mode_ = false; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 2996 | webview()->disableAutoResizeMode(); |
| 2997 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 2998 | if (!new_size.IsEmpty()) { |
| 2999 | Resize(new_size, |
| 3000 | physical_backing_size_, |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3001 | top_controls_shrink_blink_size_, |
| 3002 | top_controls_height_, |
[email protected] | bb6378fe | 2014-04-28 21:19:44 | [diff] [blame] | 3003 | visible_viewport_size_, |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 3004 | resizer_rect_, |
| 3005 | is_fullscreen_, |
| 3006 | NO_RESIZE_ACK); |
| 3007 | } |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 3008 | } |
| 3009 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 3010 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 3011 | if (send_preferred_size_changes_) |
| 3012 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 3013 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 3014 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 3015 | // Start off with an initial preferred size notification (in case |
| 3016 | // |didUpdateLayout| was already called). |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 3017 | didUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 3018 | } |
| 3019 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3020 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3021 | const gfx::Size& disable_scrollbar_size_limit) { |
| 3022 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 3023 | } |
| 3024 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3025 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3026 | const RendererPreferences& renderer_prefs) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 3027 | double old_zoom_level = renderer_preferences_.default_zoom_level; |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 3028 | std::string old_accept_languages = renderer_preferences_.accept_languages; |
| 3029 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3030 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 3031 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 3032 | |
[email protected] | dcc29777 | 2014-04-10 22:20:52 | [diff] [blame] | 3033 | #if defined(USE_DEFAULT_RENDER_THEME) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 3034 | if (renderer_prefs.use_custom_colors) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3035 | WebColorName name = blink::WebColorWebkitFocusRingColor; |
| 3036 | blink::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
| 3037 | blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 3038 | |
| 3039 | if (webview()) { |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 3040 | webview()->setSelectionColors( |
| 3041 | renderer_prefs.active_selection_bg_color, |
| 3042 | renderer_prefs.active_selection_fg_color, |
| 3043 | renderer_prefs.inactive_selection_bg_color, |
| 3044 | renderer_prefs.inactive_selection_fg_color); |
| 3045 | webview()->themeChanged(); |
| 3046 | } |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3047 | } |
[email protected] | c997bc4 | 2014-04-11 18:25:58 | [diff] [blame] | 3048 | #endif // defined(USE_DEFAULT_RENDER_THEME) |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 3049 | |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 3050 | // If the zoom level for this page matches the old zoom default, and this |
| 3051 | // is not a plugin, update the zoom level to match the new default. |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 3052 | if (webview() && webview()->mainFrame()->isWebLocalFrame() && |
| 3053 | !webview()->mainFrame()->document().isPluginDocument() && |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 3054 | !ZoomValuesEqual(old_zoom_level, |
| 3055 | renderer_preferences_.default_zoom_level) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3056 | ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) { |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 3057 | webview()->setZoomLevel(renderer_preferences_.default_zoom_level); |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 3058 | zoomLevelChanged(); |
| 3059 | } |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 3060 | |
| 3061 | if (webview() && |
| 3062 | old_accept_languages != renderer_preferences_.accept_languages) { |
| 3063 | webview()->acceptLanguagesChanged(); |
| 3064 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3065 | } |
| 3066 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3067 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 3068 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 3069 | if (webview()) |
| 3070 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 3071 | } |
| 3072 | |
[email protected] | fcdc564 | 2014-05-09 14:32:24 | [diff] [blame] | 3073 | void RenderViewImpl::OnOrientationChange() { |
dcheng | ed9f6c1c | 2014-09-23 06:13:13 | [diff] [blame] | 3074 | webview()->mainFrame()->toWebLocalFrame()->sendOrientationChangeEvent(); |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 3075 | } |
| 3076 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 3077 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 3078 | const WebPluginAction& action) { |
| 3079 | if (webview()) |
| 3080 | webview()->performPluginAction(action, location); |
| 3081 | } |
| 3082 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3083 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3084 | const GURL& page_url) { |
| 3085 | // Prepare list to storage all savable resource links. |
| 3086 | std::vector<GURL> resources_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 3087 | std::vector<GURL> referrer_urls_list; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3088 | std::vector<blink::WebReferrerPolicy> referrer_policies_list; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3089 | std::vector<GURL> frames_list; |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 3090 | SavableResourcesResult result(&resources_list, |
| 3091 | &referrer_urls_list, |
| 3092 | &referrer_policies_list, |
| 3093 | &frames_list); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3094 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3095 | // webkit/ doesn't know about Referrer. |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 3096 | if (!GetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3097 | webview(), |
| 3098 | page_url, |
| 3099 | &result, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3100 | const_cast<const char**>(GetSavableSchemes()))) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3101 | // If something is wrong when collecting all savable resource links, |
| 3102 | // send empty list to embedder(browser) to tell it failed. |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 3103 | referrer_urls_list.clear(); |
| 3104 | referrer_policies_list.clear(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3105 | resources_list.clear(); |
| 3106 | frames_list.clear(); |
| 3107 | } |
| 3108 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3109 | std::vector<Referrer> referrers_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 3110 | CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size()); |
| 3111 | for (unsigned i = 0; i < referrer_urls_list.size(); ++i) { |
| 3112 | referrers_list.push_back( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3113 | Referrer(referrer_urls_list[i], referrer_policies_list[i])); |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 3114 | } |
| 3115 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3116 | // Send result of all savable resource links to embedder. |
| 3117 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 3118 | resources_list, |
| 3119 | referrers_list, |
| 3120 | frames_list)); |
| 3121 | } |
| 3122 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3123 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3124 | const std::vector<GURL>& links, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 3125 | const std::vector<base::FilePath>& local_paths, |
| 3126 | const base::FilePath& local_directory_name) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3127 | |
| 3128 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 3129 | WebVector<WebURL> weburl_links(links); |
| 3130 | |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 3131 | // Convert std::vector of base::FilePath to WebVector<WebString> |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3132 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 3133 | for (size_t i = 0; i < local_paths.size(); i++) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 3134 | webstring_paths[i] = local_paths[i].AsUTF16Unsafe(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3135 | |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 3136 | WebPageSerializer::serialize(webview()->mainFrame()->toWebLocalFrame(), |
| 3137 | true, |
| 3138 | this, |
| 3139 | weburl_links, |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3140 | webstring_paths, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 3141 | local_directory_name.AsUTF16Unsafe()); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3142 | } |
| 3143 | |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 3144 | void RenderViewImpl::OnSuppressDialogsUntilSwapOut() { |
| 3145 | // Don't show any more dialogs until we finish OnSwapOut. |
| 3146 | suppress_dialogs_until_swap_out_ = true; |
| 3147 | } |
| 3148 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3149 | void RenderViewImpl::OnClosePage() { |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 3150 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3151 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 3152 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 3153 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 3154 | // calling the FrameLoader's CloseURL method directly. This should be |
| 3155 | // revisited to avoid having two ways to close a page. Having a single way |
| 3156 | // to close that can run onunload is also useful for fixing |
| 3157 | // http://b/issue?id=753080. |
[email protected] | 11fd5db | 2014-04-02 03:49:46 | [diff] [blame] | 3158 | webview()->mainFrame()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3159 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3160 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3161 | } |
| 3162 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3163 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 3164 | #if defined(USE_AURA) |
| 3165 | // Aura doesn't care if we switch themes. |
| 3166 | #elif defined(OS_WIN) |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 3167 | ui::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 3168 | if (webview()) |
| 3169 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 3170 | #else // defined(OS_WIN) |
| 3171 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 3172 | NOTIMPLEMENTED(); |
| 3173 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3174 | } |
| 3175 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3176 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 3177 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 3178 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 3179 | } |
| 3180 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 3181 | void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) { |
[email protected] | 189a886 | 2014-07-18 00:27:53 | [diff] [blame] | 3182 | TRACE_EVENT0("renderer", "RenderViewImpl::OnResize"); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3183 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 3184 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3185 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 3186 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 3187 | ShouldDisplayScrollbars(params.new_size.width(), |
| 3188 | params.new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
[email protected] | cbbdeef | 2014-05-26 15:57:36 | [diff] [blame] | 3192 | gfx::Size old_visible_viewport_size = visible_viewport_size_; |
| 3193 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 3194 | RenderWidget::OnResize(params); |
[email protected] | cbbdeef | 2014-05-26 15:57:36 | [diff] [blame] | 3195 | |
| 3196 | if (old_visible_viewport_size != visible_viewport_size_) |
| 3197 | has_scrolled_focused_editable_node_into_rect_ = false; |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 3198 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 3199 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3200 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3201 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3202 | // Notify all instances that we painted. The same caveats apply as for |
| 3203 | // ViewFlushedPaint regarding instances closing themselves, so we take |
| 3204 | // similar precautions. |
| 3205 | PepperPluginSet plugins = active_pepper_instances_; |
| 3206 | for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) { |
| 3207 | if (active_pepper_instances_.find(*i) != active_pepper_instances_.end()) |
| 3208 | (*i)->ViewInitiatedPaint(); |
| 3209 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3210 | #endif |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3211 | } |
| 3212 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3213 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | 5b1dec8c | 2012-02-07 04:35:38 | [diff] [blame] | 3214 | // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 3215 | // See crbug.com/112921. |
| 3216 | if (!webview()) |
| 3217 | return; |
| 3218 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3219 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 3220 | for (WebFrame* frame = main_frame; frame; |
| 3221 | frame = frame->traverseNext(false)) { |
pmeenan | dcc725b | 2014-10-22 18:04:11 | [diff] [blame] | 3222 | // TODO(nasko): This is a hack for the case in which the top-level |
| 3223 | // frame is being rendered in another process. It will not |
| 3224 | // behave correctly for out of process iframes. |
| 3225 | if (frame->isWebLocalFrame()) { |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 3226 | main_frame = frame; |
pmeenan | dcc725b | 2014-10-22 18:04:11 | [diff] [blame] | 3227 | break; |
| 3228 | } |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 3229 | } |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3230 | |
| 3231 | // If we have a provisional frame we are between the start and commit stages |
| 3232 | // of loading and we don't want to save stats. |
| 3233 | if (!main_frame->provisionalDataSource()) { |
| 3234 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3235 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 3236 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3237 | // TODO(jar): The following code should all be inside a method, probably in |
| 3238 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3239 | Time now = Time::Now(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3240 | if (document_state->first_paint_time().is_null()) { |
| 3241 | document_state->set_first_paint_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3242 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3243 | if (document_state->first_paint_after_load_time().is_null() && |
| 3244 | !document_state->finish_load_time().is_null()) { |
| 3245 | document_state->set_first_paint_after_load_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3246 | } |
| 3247 | } |
| 3248 | } |
| 3249 | |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 3250 | gfx::Vector2d RenderViewImpl::GetScrollOffset() { |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 3251 | WebFrame* main_frame = webview()->mainFrame(); |
| 3252 | for (WebFrame* frame = main_frame; frame; |
| 3253 | frame = frame->traverseNext(false)) { |
| 3254 | // TODO(nasko): This is a hack for the case in which the top-level |
| 3255 | // frame is being rendered in another process. It will not |
| 3256 | // behave correctly for out of process iframes. |
| 3257 | if (frame->isWebLocalFrame()) { |
| 3258 | main_frame = frame; |
| 3259 | break; |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | WebSize scroll_offset = main_frame->scrollOffset(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 3264 | return gfx::Vector2d(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 3265 | } |
| 3266 | |
[email protected] | ab6c911 | 2014-02-27 00:20:58 | [diff] [blame] | 3267 | void RenderViewImpl::OnClearFocusedElement() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 3268 | if (webview()) |
[email protected] | ab6c911 | 2014-02-27 00:20:58 | [diff] [blame] | 3269 | webview()->clearFocusedElement(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 3270 | } |
| 3271 | |
[email protected] | 61f9183 | 2014-05-13 01:24:42 | [diff] [blame] | 3272 | void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 3273 | if (webview()) |
[email protected] | 61f9183 | 2014-05-13 01:24:42 | [diff] [blame] | 3274 | webview()->setIsTransparent(!opaque); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 3275 | if (compositor_) |
[email protected] | 61f9183 | 2014-05-13 01:24:42 | [diff] [blame] | 3276 | compositor_->setHasTransparentBackground(!opaque); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 3277 | } |
| 3278 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3279 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 3280 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3281 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 3282 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3283 | #if defined(ENABLE_PLUGINS) && defined(OS_MACOSX) |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 3284 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3285 | for (plugin_it = plugin_delegates_.begin(); |
| 3286 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3287 | (*plugin_it)->SetWindowFocus(active); |
| 3288 | } |
| 3289 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 3290 | } |
| 3291 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 3292 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3293 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3294 | #if defined(ENABLE_PLUGINS) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 3295 | // Inform plugins that their container has changed visibility. |
| 3296 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3297 | for (plugin_it = plugin_delegates_.begin(); |
| 3298 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3299 | (*plugin_it)->SetContainerVisibility(visible); |
| 3300 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3301 | #endif |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 3302 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3303 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3304 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 3305 | const gfx::Rect& view_frame) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3306 | #if defined(ENABLE_PLUGINS) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3307 | // Inform plugins that their window's frame has changed. |
| 3308 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3309 | for (plugin_it = plugin_delegates_.begin(); |
| 3310 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3311 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 3312 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3313 | #endif |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3314 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 3315 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3316 | void RenderViewImpl::OnPluginImeCompositionCompleted(const base::string16& text, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3317 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 3318 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 3319 | // applies to it or not, so inform all the delegates. |
| 3320 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3321 | for (plugin_it = plugin_delegates_.begin(); |
| 3322 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 3323 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 3324 | } |
| 3325 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 3326 | #endif // OS_MACOSX |
| 3327 | |
[email protected] | 6de7fc48 | 2014-06-06 10:46:44 | [diff] [blame] | 3328 | void RenderViewImpl::OnClose() { |
| 3329 | if (closing_) |
| 3330 | RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id_)); |
| 3331 | RenderWidget::OnClose(); |
| 3332 | } |
| 3333 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3334 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 3335 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 3336 | WebView* doomed = webview(); |
| 3337 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 3338 | g_view_map.Get().erase(doomed); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 3339 | g_routing_id_view_map.Get().erase(routing_id_); |
[email protected] | 6de7fc48 | 2014-06-06 10:46:44 | [diff] [blame] | 3340 | RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id_)); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 3341 | } |
| 3342 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3343 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 3344 | ClearEditCommands(); |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 3345 | } |
| 3346 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3347 | bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent& event) { |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 3348 | possible_drag_event_info_.event_source = |
| 3349 | ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 3350 | possible_drag_event_info_.event_location = |
| 3351 | gfx::Point(event.globalX, event.globalY); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3352 | |
| 3353 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3354 | // This method is called for every mouse event that the render view receives. |
| 3355 | // And then the mouse event is forwarded to WebKit, which dispatches it to the |
| 3356 | // event target. Potentially a Pepper plugin will receive the event. |
| 3357 | // In order to tell whether a plugin gets the last mouse event and which it |
| 3358 | // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets |
| 3359 | // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 3360 | // |pepper_last_mouse_event_target_|. |
| 3361 | pepper_last_mouse_event_target_ = NULL; |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3362 | #endif |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 3363 | |
| 3364 | // If the mouse is locked, only the current owner of the mouse lock can |
| 3365 | // process mouse events. |
| 3366 | return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 3367 | } |
| 3368 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 3369 | bool RenderViewImpl::WillHandleGestureEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3370 | const blink::WebGestureEvent& event) { |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 3371 | possible_drag_event_info_.event_source = |
| 3372 | ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH; |
| 3373 | possible_drag_event_info_.event_location = |
| 3374 | gfx::Point(event.globalX, event.globalY); |
| 3375 | return false; |
| 3376 | } |
| 3377 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 3378 | void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3379 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3380 | } |
| 3381 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3382 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 3383 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 3384 | } |
| 3385 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 3386 | bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const { |
| 3387 | if (!webview()) |
| 3388 | return false; |
| 3389 | return webview()->hasTouchEventHandlersAt(point); |
| 3390 | } |
| 3391 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3392 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3393 | RenderWidget::OnWasHidden(); |
| 3394 | |
[email protected] | 68877c28 | 2013-09-20 05:52:42 | [diff] [blame] | 3395 | #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 3396 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 3397 | SuspendDevices(true); |
[email protected] | e976c3c5 | 2014-07-24 17:41:55 | [diff] [blame] | 3398 | if (speech_recognition_dispatcher_) |
| 3399 | speech_recognition_dispatcher_->AbortAllRecognitions(); |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 3400 | #endif |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 3401 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 3402 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 3403 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3404 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3405 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3406 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 3407 | i != active_pepper_instances_.end(); ++i) |
| 3408 | (*i)->PageVisibilityChanged(false); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 3409 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3410 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 3411 | // Inform NPAPI plugins that their container is no longer visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3412 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3413 | for (plugin_it = plugin_delegates_.begin(); |
| 3414 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3415 | (*plugin_it)->SetContainerVisibility(false); |
| 3416 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3417 | #endif // OS_MACOSX |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3418 | #endif // ENABLE_PLUGINS |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3419 | } |
| 3420 | |
[email protected] | 3399dd82 | 2014-08-09 11:14:24 | [diff] [blame] | 3421 | void RenderViewImpl::OnWasShown(bool needs_repainting, |
| 3422 | const ui::LatencyInfo& latency_info) { |
| 3423 | RenderWidget::OnWasShown(needs_repainting, latency_info); |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3424 | |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 3425 | #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 3426 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 3427 | SuspendDevices(false); |
| 3428 | #endif |
| 3429 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 3430 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 3431 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3432 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3433 | #if defined(ENABLE_PLUGINS) |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3434 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 3435 | i != active_pepper_instances_.end(); ++i) |
| 3436 | (*i)->PageVisibilityChanged(true); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 3437 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3438 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 3439 | // Inform NPAPI plugins that their container is now visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3440 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3441 | for (plugin_it = plugin_delegates_.begin(); |
| 3442 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 3443 | (*plugin_it)->SetContainerVisibility(true); |
| 3444 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 3445 | #endif // OS_MACOSX |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3446 | #endif // ENABLE_PLUGINS |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 3447 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3448 | |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 3449 | GURL RenderViewImpl::GetURLForGraphicsContext3D() { |
| 3450 | DCHECK(webview()); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 3451 | if (webview()->mainFrame()->isWebLocalFrame()) |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 3452 | return GURL(webview()->mainFrame()->document().url()); |
| 3453 | else |
| 3454 | return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 3455 | } |
| 3456 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3457 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3458 | RenderWidget::OnSetFocus(enable); |
| 3459 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3460 | #if defined(ENABLE_PLUGINS) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 3461 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 3462 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3463 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 3464 | for (plugin_it = plugin_delegates_.begin(); |
| 3465 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 3466 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 3467 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 3468 | // activation state to change just like a call to setIsActive. |
| 3469 | if (enable) |
| 3470 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 3471 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 3472 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3473 | } |
| 3474 | } |
[email protected] | a99a3880 | 2014-01-14 15:46:57 | [diff] [blame] | 3475 | // Notify all Pepper plugins. |
| 3476 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 3477 | i != active_pepper_instances_.end(); ++i) |
| 3478 | (*i)->SetContentAreaFocus(enable); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3479 | #endif |
[email protected] | 32103299 | 2012-11-08 01:01:27 | [diff] [blame] | 3480 | // Notify all BrowserPlugins of the RenderView's focus state. |
fsamuel | 6c1dfeb | 2014-12-18 19:21:33 | [diff] [blame] | 3481 | if (BrowserPluginManager::Get()) |
| 3482 | BrowserPluginManager::Get()->UpdateFocusState(); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 3483 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 3484 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3485 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3486 | const base::string16& text, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3487 | const std::vector<blink::WebCompositionUnderline>& underlines, |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3488 | int selection_start, |
| 3489 | int selection_end) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3490 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3491 | if (focused_pepper_plugin_) { |
| 3492 | focused_pepper_plugin_->render_frame()->OnImeSetComposition( |
[email protected] | 7a4e253 | 2013-12-02 21:30:02 | [diff] [blame] | 3493 | text, underlines, selection_start, selection_end); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3494 | return; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3495 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3496 | |
| 3497 | #if defined(OS_WIN) |
| 3498 | // When a plug-in has focus, we create platform-specific IME data used by |
| 3499 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 3500 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 3501 | // instance ID is the same one as the specified ID.) |
| 3502 | if (focused_plugin_id_ >= 0) { |
| 3503 | std::vector<int> clauses; |
| 3504 | std::vector<int> target; |
| 3505 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 3506 | clauses.push_back(underlines[i].startOffset); |
| 3507 | clauses.push_back(underlines[i].endOffset); |
| 3508 | if (underlines[i].thick) { |
| 3509 | target.clear(); |
| 3510 | target.push_back(underlines[i].startOffset); |
| 3511 | target.push_back(underlines[i].endOffset); |
| 3512 | } |
| 3513 | } |
| 3514 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 3515 | for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) { |
| 3516 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 3517 | focused_plugin_id_); |
| 3518 | } |
| 3519 | return; |
| 3520 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3521 | #endif // OS_WIN |
| 3522 | #endif // ENABLE_PLUGINS |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3523 | RenderWidget::OnImeSetComposition(text, |
| 3524 | underlines, |
| 3525 | selection_start, |
| 3526 | selection_end); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3527 | } |
| 3528 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 3529 | void RenderViewImpl::OnImeConfirmComposition( |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3530 | const base::string16& text, |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 3531 | const gfx::Range& replacement_range, |
| 3532 | bool keep_selection) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3533 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3534 | if (focused_pepper_plugin_) { |
| 3535 | focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( |
[email protected] | 7a4e253 | 2013-12-02 21:30:02 | [diff] [blame] | 3536 | text, replacement_range, keep_selection); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3537 | return; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3538 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3539 | #if defined(OS_WIN) |
| 3540 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 3541 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 3542 | // it to WebKit to prevent WebKit from controlling IMEs. |
| 3543 | // TODO(thakis): Honor |replacement_range| for plugins? |
| 3544 | if (focused_plugin_id_ >= 0) { |
| 3545 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 3546 | for (it = plugin_delegates_.begin(); |
| 3547 | it != plugin_delegates_.end(); ++it) { |
| 3548 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 3549 | } |
| 3550 | return; |
| 3551 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 3552 | #endif // OS_WIN |
| 3553 | #endif // ENABLE_PLUGINS |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3554 | if (replacement_range.IsValid() && webview()) { |
| 3555 | // Select the text in |replacement_range|, it will then be replaced by |
| 3556 | // text added by the call to RenderWidget::OnImeConfirmComposition(). |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 3557 | if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3558 | WebRange webrange = WebRange::fromDocumentRange( |
| 3559 | frame, replacement_range.start(), replacement_range.length()); |
| 3560 | if (!webrange.isNull()) |
| 3561 | frame->selectRange(webrange); |
| 3562 | } |
| 3563 | } |
| 3564 | RenderWidget::OnImeConfirmComposition(text, |
| 3565 | replacement_range, |
| 3566 | keep_selection); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3567 | } |
| 3568 | |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 3569 | void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) { |
| 3570 | RenderWidget::SetDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 3571 | if (webview()) { |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 3572 | webview()->setDeviceScaleFactor(device_scale_factor); |
[email protected] | b8ec111 | 2014-08-17 20:09:10 | [diff] [blame] | 3573 | webview()->settings()->setPreferCompositingToLCDTextEnabled( |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 3574 | PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 3575 | } |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 3576 | if (auto_resize_mode_) |
| 3577 | AutoResizeCompositor(); |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 3578 | |
fsamuel | 6c1dfeb | 2014-12-18 19:21:33 | [diff] [blame] | 3579 | if (BrowserPluginManager::Get()) |
| 3580 | BrowserPluginManager::Get()->UpdateDeviceScaleFactor(); |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 3581 | } |
| 3582 | |
[email protected] | 28ed6b3 | 2014-06-08 02:16:27 | [diff] [blame] | 3583 | bool RenderViewImpl::SetDeviceColorProfile( |
| 3584 | const std::vector<char>& profile) { |
| 3585 | bool changed = RenderWidget::SetDeviceColorProfile(profile); |
| 3586 | if (changed && webview()) { |
noel | c76aa4c | 2014-09-25 01:08:56 | [diff] [blame] | 3587 | WebVector<char> colorProfile = profile; |
| 3588 | webview()->setDeviceColorProfile(colorProfile); |
[email protected] | 28ed6b3 | 2014-06-08 02:16:27 | [diff] [blame] | 3589 | } |
| 3590 | return changed; |
| 3591 | } |
| 3592 | |
noel | db4df15 | 2014-09-16 17:45:20 | [diff] [blame] | 3593 | void RenderViewImpl::ResetDeviceColorProfileForTesting() { |
| 3594 | RenderWidget::ResetDeviceColorProfileForTesting(); |
| 3595 | if (webview()) |
| 3596 | webview()->resetDeviceColorProfile(); |
| 3597 | } |
| 3598 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3599 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3600 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3601 | if (focused_pepper_plugin_) |
| 3602 | return focused_pepper_plugin_->text_input_type(); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3603 | #endif |
| 3604 | return RenderWidget::GetTextInputType(); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 3605 | } |
| 3606 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 3607 | void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3608 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3609 | if (focused_pepper_plugin_) { |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 3610 | // TODO(kinaba) http://crbug.com/101101 |
| 3611 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 3612 | // use the caret position as an empty range for now. It will be updated |
| 3613 | // after Pepper API equips features related to surrounding text retrieval. |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3614 | gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds(); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 3615 | *start = caret; |
| 3616 | *end = caret; |
| 3617 | return; |
| 3618 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3619 | #endif |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 3620 | RenderWidget::GetSelectionBounds(start, end); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 3621 | } |
| 3622 | |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 3623 | void RenderViewImpl::FocusChangeComplete() { |
| 3624 | RenderWidget::FocusChangeComplete(); |
| 3625 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusChangeComplete()); |
| 3626 | } |
| 3627 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 3628 | void RenderViewImpl::GetCompositionCharacterBounds( |
| 3629 | std::vector<gfx::Rect>* bounds) { |
| 3630 | DCHECK(bounds); |
| 3631 | bounds->clear(); |
| 3632 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3633 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3634 | if (focused_pepper_plugin_) { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 3635 | return; |
| 3636 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3637 | #endif |
| 3638 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 3639 | if (!webview()) |
| 3640 | return; |
| 3641 | size_t start_offset = 0; |
| 3642 | size_t character_count = 0; |
| 3643 | if (!webview()->compositionRange(&start_offset, &character_count)) |
| 3644 | return; |
| 3645 | if (character_count == 0) |
| 3646 | return; |
| 3647 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3648 | blink::WebFrame* frame = webview()->focusedFrame(); |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 3649 | if (!frame) |
| 3650 | return; |
| 3651 | |
| 3652 | bounds->reserve(character_count); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3653 | blink::WebRect webrect; |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 3654 | for (size_t i = 0; i < character_count; ++i) { |
| 3655 | if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { |
| 3656 | DLOG(ERROR) << "Could not retrieve character rectangle at " << i; |
| 3657 | bounds->clear(); |
| 3658 | return; |
| 3659 | } |
| 3660 | bounds->push_back(webrect); |
| 3661 | } |
| 3662 | } |
| 3663 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 3664 | void RenderViewImpl::GetCompositionRange(gfx::Range* range) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3665 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3666 | if (focused_pepper_plugin_) { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 3667 | return; |
| 3668 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3669 | #endif |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 3670 | RenderWidget::GetCompositionRange(range); |
| 3671 | } |
| 3672 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3673 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3674 | #if defined(ENABLE_PLUGINS) |
[email protected] | e16c7a1 | 2013-12-05 16:30:08 | [diff] [blame] | 3675 | if (focused_pepper_plugin_) |
| 3676 | return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents(); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 3677 | #endif |
| 3678 | return true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 3679 | } |
| 3680 | |
[email protected] | 3300477 | 2013-11-12 09:49:23 | [diff] [blame] | 3681 | void RenderViewImpl::InstrumentWillBeginFrame(int frame_id) { |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 3682 | if (!webview()) |
| 3683 | return; |
| 3684 | if (!webview()->devToolsAgent()) |
| 3685 | return; |
[email protected] | 3300477 | 2013-11-12 09:49:23 | [diff] [blame] | 3686 | webview()->devToolsAgent()->didBeginFrame(frame_id); |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | void RenderViewImpl::InstrumentDidBeginFrame() { |
| 3690 | if (!webview()) |
| 3691 | return; |
| 3692 | if (!webview()->devToolsAgent()) |
| 3693 | return; |
| 3694 | // TODO(jamesr/caseq): Decide if this needs to be renamed. |
| 3695 | webview()->devToolsAgent()->didComposite(); |
| 3696 | } |
| 3697 | |
| 3698 | void RenderViewImpl::InstrumentDidCancelFrame() { |
| 3699 | if (!webview()) |
| 3700 | return; |
| 3701 | if (!webview()->devToolsAgent()) |
| 3702 | return; |
| 3703 | webview()->devToolsAgent()->didCancelFrame(); |
| 3704 | } |
| 3705 | |
| 3706 | void RenderViewImpl::InstrumentWillComposite() { |
| 3707 | if (!webview()) |
| 3708 | return; |
| 3709 | if (!webview()->devToolsAgent()) |
| 3710 | return; |
| 3711 | webview()->devToolsAgent()->willComposite(); |
| 3712 | } |
| 3713 | |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 3714 | void RenderViewImpl::DidCompletePageScaleAnimation() { |
| 3715 | FocusChangeComplete(); |
| 3716 | } |
| 3717 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 3718 | void RenderViewImpl::SetScreenMetricsEmulationParameters( |
[email protected] | 7f99fc2 | 2013-11-08 14:05:58 | [diff] [blame] | 3719 | float device_scale_factor, |
| 3720 | const gfx::Point& root_layer_offset, |
| 3721 | float root_layer_scale) { |
[email protected] | 404630b | 2014-07-03 19:33:03 | [diff] [blame] | 3722 | if (webview() && compositor()) { |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 3723 | webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor); |
[email protected] | 7f99fc2 | 2013-11-08 14:05:58 | [diff] [blame] | 3724 | webview()->setRootLayerTransform( |
| 3725 | blink::WebSize(root_layer_offset.x(), root_layer_offset.y()), |
| 3726 | root_layer_scale); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 3727 | } |
| 3728 | } |
| 3729 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3730 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3731 | const FileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3732 | WebFileChooserCompletion* completion) { |
| 3733 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 3734 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 3735 | // This sanity check prevents too many file choose requests from getting |
| 3736 | // queued which could DoS the user. Getting these is most likely a |
| 3737 | // programming error (there are many ways to DoS the user so it's not |
| 3738 | // considered a "real" security check), either in JS requesting many file |
| 3739 | // choosers to pop up, or in a plugin. |
| 3740 | // |
| 3741 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 3742 | // a file picker, which will address this issue in a better way. |
| 3743 | return false; |
| 3744 | } |
| 3745 | |
| 3746 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 3747 | new PendingFileChooser(params, completion))); |
| 3748 | if (file_chooser_completions_.size() == 1) { |
| 3749 | // Actually show the browse dialog when this is the first request. |
| 3750 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 3751 | } |
| 3752 | return true; |
| 3753 | } |
| 3754 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3755 | blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 3756 | if (!speech_recognition_dispatcher_) |
| 3757 | speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 3758 | return speech_recognition_dispatcher_; |
| 3759 | } |
| 3760 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3761 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 3762 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3763 | int minimum_percent = static_cast<int>( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 3764 | ZoomLevelToZoomFactor(minimum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3765 | int maximum_percent = static_cast<int>( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 3766 | ZoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3767 | |
| 3768 | Send(new ViewHostMsg_UpdateZoomLimits( |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 3769 | routing_id_, minimum_percent, maximum_percent)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3770 | } |
| 3771 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3772 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | 54b8e18 | 2014-05-02 18:08:29 | [diff] [blame] | 3773 | double zoom_level = webview()->zoomLevel(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 3774 | |
[email protected] | 54b8e18 | 2014-05-02 18:08:29 | [diff] [blame] | 3775 | // Do not send empty URLs to the browser when we are just setting the default |
| 3776 | // zoom level (from RendererPreferences) before the first navigation. |
| 3777 | if (!webview()->mainFrame()->document().url().isEmpty()) { |
| 3778 | // Tell the browser which url got zoomed so it can update the menu and the |
| 3779 | // saved values if necessary |
| 3780 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 3781 | routing_id_, zoom_level, |
[email protected] | 54b8e18 | 2014-05-02 18:08:29 | [diff] [blame] | 3782 | GURL(webview()->mainFrame()->document().url()))); |
| 3783 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3784 | } |
| 3785 | |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 3786 | double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const { |
| 3787 | return ZoomLevelToZoomFactor(zoom_level); |
| 3788 | } |
| 3789 | |
| 3790 | double RenderViewImpl::zoomFactorToZoomLevel(double factor) const { |
| 3791 | return ZoomFactorToZoomLevel(factor); |
| 3792 | } |
| 3793 | |
[email protected] | f29bc5e | 2014-08-22 10:34:06 | [diff] [blame] | 3794 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
| 3795 | const WebURL& url, |
| 3796 | const WebString& title) { |
| 3797 | bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
| 3798 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
| 3799 | base::UTF16ToUTF8(scheme), |
| 3800 | url, |
| 3801 | title, |
| 3802 | user_gesture)); |
| 3803 | } |
| 3804 | |
| 3805 | void RenderViewImpl::unregisterProtocolHandler(const WebString& scheme, |
| 3806 | const WebURL& url) { |
| 3807 | bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
| 3808 | Send(new ViewHostMsg_UnregisterProtocolHandler(routing_id_, |
| 3809 | base::UTF16ToUTF8(scheme), |
| 3810 | url, |
| 3811 | user_gesture)); |
| 3812 | } |
| 3813 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3814 | blink::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
| 3815 | blink::WebPageVisibilityState current_state = is_hidden() ? |
| 3816 | blink::WebPageVisibilityStateHidden : |
| 3817 | blink::WebPageVisibilityStateVisible; |
| 3818 | blink::WebPageVisibilityState override_state = current_state; |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 3819 | // TODO(jam): move this method to WebFrameClient. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3820 | if (GetContentClient()->renderer()-> |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 3821 | ShouldOverridePageVisibilityState(main_render_frame_.get(), |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 3822 | &override_state)) |
| 3823 | return override_state; |
| 3824 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 3825 | } |
| 3826 | |
[email protected] | a0629af9 | 2012-08-08 00:39:37 | [diff] [blame] | 3827 | void RenderViewImpl::draggableRegionsChanged() { |
| 3828 | FOR_EACH_OBSERVER( |
| 3829 | RenderViewObserver, |
| 3830 | observers_, |
| 3831 | DraggableRegionsChanged(webview()->mainFrame())); |
| 3832 | } |
| 3833 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 3834 | #if defined(OS_ANDROID) |
| 3835 | WebContentDetectionResult RenderViewImpl::detectContentAround( |
| 3836 | const WebHitTestResult& touch_hit) { |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 3837 | DCHECK(touch_hit.node().isTextNode()); |
| 3838 | |
| 3839 | // Process the position with all the registered content detectors until |
| 3840 | // a match is found. Priority is provided by their relative order. |
| 3841 | for (ContentDetectorList::const_iterator it = content_detectors_.begin(); |
| 3842 | it != content_detectors_.end(); ++it) { |
| 3843 | ContentDetector::Result content = (*it)->FindTappedContent(touch_hit); |
| 3844 | if (content.valid) { |
| 3845 | return WebContentDetectionResult(content.content_boundaries, |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 3846 | base::UTF8ToUTF16(content.text), content.intent_url); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 3847 | } |
| 3848 | } |
| 3849 | return WebContentDetectionResult(); |
| 3850 | } |
| 3851 | |
| 3852 | void RenderViewImpl::scheduleContentIntent(const WebURL& intent) { |
| 3853 | // Introduce a short delay so that the user can notice the content. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 3854 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 3855 | FROM_HERE, |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 3856 | base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, |
| 3857 | AsWeakPtr(), |
| 3858 | intent, |
| 3859 | expected_content_intent_id_), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 3860 | base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); |
| 3861 | } |
| 3862 | |
| 3863 | void RenderViewImpl::cancelScheduledContentIntents() { |
| 3864 | ++expected_content_intent_id_; |
| 3865 | } |
| 3866 | |
| 3867 | void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, |
| 3868 | size_t request_id) { |
| 3869 | if (request_id != expected_content_intent_id_) |
qinmin | 0d5560df | 2014-11-12 19:03:39 | [diff] [blame] | 3870 | return; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 3871 | |
| 3872 | // Remove the content highlighting if any. |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 3873 | scheduleComposite(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 3874 | |
| 3875 | if (!intent.is_empty()) |
| 3876 | Send(new ViewHostMsg_StartContentIntent(routing_id_, intent)); |
| 3877 | } |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 3878 | |
| 3879 | bool RenderViewImpl::openDateTimeChooser( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 3880 | const blink::WebDateTimeChooserParams& params, |
| 3881 | blink::WebDateTimeChooserCompletion* completion) { |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 3882 | // JavaScript may try to open a date time chooser while one is already open. |
| 3883 | if (date_time_picker_client_) |
| 3884 | return false; |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 3885 | date_time_picker_client_.reset( |
| 3886 | new RendererDateTimePicker(this, params, completion)); |
| 3887 | return date_time_picker_client_->Open(); |
| 3888 | } |
| 3889 | |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 3890 | void RenderViewImpl::DismissDateTimeDialog() { |
| 3891 | DCHECK(date_time_picker_client_); |
| 3892 | date_time_picker_client_.reset(NULL); |
| 3893 | } |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 3894 | |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 3895 | #endif // defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 3896 | |
[email protected] | be1af066 | 2014-07-29 19:55:51 | [diff] [blame] | 3897 | void RenderViewImpl::OnShowContextMenu( |
| 3898 | ui::MenuSourceType source_type, const gfx::Point& location) { |
| 3899 | context_menu_source_type_ = source_type; |
| 3900 | has_host_context_menu_location_ = true; |
| 3901 | host_context_menu_location_ = location; |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 3902 | if (webview()) |
| 3903 | webview()->showContextMenu(); |
[email protected] | be1af066 | 2014-07-29 19:55:51 | [diff] [blame] | 3904 | has_host_context_menu_location_ = false; |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 3905 | } |
| 3906 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3907 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 3908 | if (!webview()) |
| 3909 | return; |
| 3910 | WebFrame* main_frame = webview()->mainFrame(); |
| 3911 | if (!main_frame) |
| 3912 | return; |
| 3913 | main_frame->enableViewSourceMode(true); |
| 3914 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 3915 | |
luken | b171b53 | 2014-09-24 05:50:38 | [diff] [blame] | 3916 | #if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 3917 | bool RenderViewImpl::didTapMultipleTargets( |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 3918 | const WebSize& inner_viewport_offset, |
| 3919 | const WebRect& touch_rect, |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 3920 | const WebVector<WebRect>& target_rects) { |
luken | e23094a | 2014-11-23 14:12:31 | [diff] [blame] | 3921 | if (!switches::IsLinkDisambiguationPopupEnabled()) |
| 3922 | return false; |
| 3923 | |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 3924 | // Never show a disambiguation popup when accessibility is enabled, |
| 3925 | // as this interferes with "touch exploration". |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3926 | AccessibilityMode accessibility_mode = |
mostynb | c3335323 | 2014-09-12 09:38:31 | [diff] [blame] | 3927 | GetMainRenderFrame()->accessibility_mode(); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3928 | bool matches_accessibility_mode_complete = |
| 3929 | (accessibility_mode & AccessibilityModeComplete) == |
| 3930 | AccessibilityModeComplete; |
| 3931 | if (matches_accessibility_mode_complete) |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 3932 | return false; |
| 3933 | |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 3934 | // The touch_rect, target_rects and zoom_rect are in the outer viewport |
| 3935 | // reference frame. |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 3936 | gfx::Rect zoom_rect; |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 3937 | float new_total_scale = |
| 3938 | DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 3939 | touch_rect, target_rects, GetSize(), |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 3940 | gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(), |
| 3941 | device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect); |
| 3942 | if (!new_total_scale) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 3943 | return false; |
| 3944 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 3945 | bool handled = false; |
| 3946 | switch (renderer_preferences_.tap_multiple_targets_strategy) { |
| 3947 | case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM: |
| 3948 | handled = webview()->zoomToMultipleTargetsRect(zoom_rect); |
| 3949 | break; |
| 3950 | case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: { |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 3951 | gfx::Size canvas_size = |
| 3952 | gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale)); |
[email protected] | cb189e06 | 2014-04-23 00:57:01 | [diff] [blame] | 3953 | cc::SharedBitmapManager* manager = |
| 3954 | RenderThreadImpl::current()->shared_bitmap_manager(); |
| 3955 | scoped_ptr<cc::SharedBitmap> shared_bitmap = |
| 3956 | manager->AllocateSharedBitmap(canvas_size); |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 3957 | { |
[email protected] | cb189e06 | 2014-04-23 00:57:01 | [diff] [blame] | 3958 | SkBitmap bitmap; |
| 3959 | SkImageInfo info = SkImageInfo::MakeN32Premul(canvas_size.width(), |
| 3960 | canvas_size.height()); |
| 3961 | bitmap.installPixels(info, shared_bitmap->pixels(), info.minRowBytes()); |
| 3962 | SkCanvas canvas(bitmap); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 3963 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 3964 | // TODO(trchen): Cleanup the device scale factor mess. |
| 3965 | // device scale will be applied in WebKit |
| 3966 | // --> zoom_rect doesn't include device scale, |
| 3967 | // but WebKit will still draw on zoom_rect * device_scale_factor_ |
[email protected] | cb189e06 | 2014-04-23 00:57:01 | [diff] [blame] | 3968 | canvas.scale(new_total_scale / device_scale_factor_, |
| 3969 | new_total_scale / device_scale_factor_); |
| 3970 | canvas.translate(-zoom_rect.x() * device_scale_factor_, |
| 3971 | -zoom_rect.y() * device_scale_factor_); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 3972 | |
[email protected] | bcb1f02 | 2014-05-06 01:54:17 | [diff] [blame] | 3973 | DCHECK(webwidget_->isAcceleratedCompositingActive()); |
| 3974 | // TODO(aelias): The disambiguation popup should be composited so we |
| 3975 | // don't have to call this method. |
| 3976 | webwidget_->paintCompositedDeprecated(&canvas, zoom_rect); |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 3977 | } |
| 3978 | |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 3979 | gfx::Rect zoom_rect_in_screen = |
| 3980 | zoom_rect - gfx::Vector2d(inner_viewport_offset.width, |
| 3981 | inner_viewport_offset.height); |
| 3982 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 3983 | gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect( |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 3984 | ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect_in_screen))); |
| 3985 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 3986 | Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_, |
| 3987 | physical_window_zoom_rect, |
| 3988 | canvas_size, |
[email protected] | cb189e06 | 2014-04-23 00:57:01 | [diff] [blame] | 3989 | shared_bitmap->id())); |
| 3990 | cc::SharedBitmapId id = shared_bitmap->id(); |
| 3991 | disambiguation_bitmaps_[id] = shared_bitmap.release(); |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 3992 | handled = true; |
| 3993 | break; |
| 3994 | } |
| 3995 | case TAP_MULTIPLE_TARGETS_STRATEGY_NONE: |
| 3996 | // No-op. |
| 3997 | break; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 3998 | } |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 3999 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 4000 | return handled; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4001 | } |
luken | b171b53 | 2014-09-24 05:50:38 | [diff] [blame] | 4002 | #endif // defined(OS_ANDROID) || defined(TOOLKIT_VIEWS) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4003 | |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 4004 | unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const { |
| 4005 | return history_list_length_; |
| 4006 | } |
| 4007 | |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 4008 | void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) { |
| 4009 | if (enable) { |
| 4010 | if (has_focus()) |
| 4011 | return; |
| 4012 | OnSetActive(true); |
| 4013 | OnSetFocus(true); |
| 4014 | } else { |
| 4015 | if (!has_focus()) |
| 4016 | return; |
| 4017 | OnSetFocus(false); |
| 4018 | OnSetActive(false); |
| 4019 | } |
| 4020 | } |
| 4021 | |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 4022 | void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) { |
[email protected] | b54fe45 | 2013-06-07 14:01:53 | [diff] [blame] | 4023 | ViewMsg_Resize_Params params; |
| 4024 | params.screen_info = screen_info_; |
| 4025 | params.screen_info.deviceScaleFactor = factor; |
| 4026 | params.new_size = size(); |
bokan | f0fd241 | 2014-10-30 15:28:55 | [diff] [blame] | 4027 | params.visible_viewport_size = visible_viewport_size_; |
[email protected] | b54fe45 | 2013-06-07 14:01:53 | [diff] [blame] | 4028 | params.physical_backing_size = |
| 4029 | gfx::ToCeiledSize(gfx::ScaleSize(size(), factor)); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4030 | params.top_controls_shrink_blink_size = false; |
| 4031 | params.top_controls_height = 0.f; |
[email protected] | b54fe45 | 2013-06-07 14:01:53 | [diff] [blame] | 4032 | params.resizer_rect = WebRect(); |
| 4033 | params.is_fullscreen = is_fullscreen(); |
| 4034 | OnResize(params); |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 4035 | } |
| 4036 | |
[email protected] | 71e65230 | 2014-05-09 14:20:13 | [diff] [blame] | 4037 | void RenderViewImpl::SetDeviceColorProfileForTesting( |
| 4038 | const std::vector<char>& color_profile) { |
[email protected] | 28ed6b3 | 2014-06-08 02:16:27 | [diff] [blame] | 4039 | SetDeviceColorProfile(color_profile); |
[email protected] | 71e65230 | 2014-05-09 14:20:13 | [diff] [blame] | 4040 | } |
| 4041 | |
[email protected] | 9265016 | 2013-10-30 03:31:02 | [diff] [blame] | 4042 | void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) { |
| 4043 | gfx::Rect new_position(rootWindowRect().x, |
| 4044 | rootWindowRect().y, |
| 4045 | new_size.width(), |
| 4046 | new_size.height()); |
bokan | f0fd241 | 2014-10-30 15:28:55 | [diff] [blame] | 4047 | ResizeSynchronously(new_position, new_size); |
[email protected] | 9265016 | 2013-10-30 03:31:02 | [diff] [blame] | 4048 | } |
| 4049 | |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 4050 | void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) { |
| 4051 | resizing_mode_selector_->set_is_synchronous_mode(enable); |
| 4052 | } |
| 4053 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 4054 | void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size, |
| 4055 | const gfx::Size& max_size) { |
| 4056 | OnEnableAutoResize(min_size, max_size); |
| 4057 | } |
| 4058 | |
| 4059 | void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) { |
| 4060 | OnDisableAutoResize(new_size); |
| 4061 | } |
| 4062 | |
[email protected] | cb189e06 | 2014-04-23 00:57:01 | [diff] [blame] | 4063 | void RenderViewImpl::OnReleaseDisambiguationPopupBitmap( |
| 4064 | const cc::SharedBitmapId& id) { |
| 4065 | BitmapMap::iterator it = disambiguation_bitmaps_.find(id); |
| 4066 | DCHECK(it != disambiguation_bitmaps_.end()); |
| 4067 | delete it->second; |
| 4068 | disambiguation_bitmaps_.erase(it); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 4069 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4070 | |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 4071 | void RenderViewImpl::DidCommitCompositorFrame() { |
| 4072 | RenderWidget::DidCommitCompositorFrame(); |
fsamuel | 6c1dfeb | 2014-12-18 19:21:33 | [diff] [blame] | 4073 | if (BrowserPluginManager::Get()) |
| 4074 | BrowserPluginManager::Get()->DidCommitCompositorFrame(GetRoutingID()); |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 4075 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame()); |
| 4076 | } |
| 4077 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 4078 | void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) { |
| 4079 | if (!urls.empty()) |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 4080 | Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, urls)); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | void RenderViewImpl::DidStopLoadingIcons() { |
| 4084 | int icon_types = WebIconURL::TypeFavicon; |
| 4085 | if (TouchEnabled()) |
| 4086 | icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
| 4087 | |
nasko | 2411ba37 | 2014-10-13 17:45:41 | [diff] [blame] | 4088 | // Favicons matter only for the top-level frame. If it is a WebRemoteFrame, |
| 4089 | // just return early. |
| 4090 | if (webview()->mainFrame()->isWebRemoteFrame()) |
| 4091 | return; |
| 4092 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 4093 | WebVector<WebIconURL> icon_urls = |
| 4094 | webview()->mainFrame()->iconURLs(icon_types); |
| 4095 | |
| 4096 | std::vector<FaviconURL> urls; |
| 4097 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 4098 | WebURL url = icon_urls[i].iconURL(); |
[email protected] | 2bd262b | 2014-04-16 05:31:23 | [diff] [blame] | 4099 | std::vector<gfx::Size> sizes; |
[email protected] | f34ac13 | 2014-03-20 23:02:05 | [diff] [blame] | 4100 | ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 4101 | if (!url.isEmpty()) |
[email protected] | f34ac13 | 2014-03-20 23:02:05 | [diff] [blame] | 4102 | urls.push_back( |
| 4103 | FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 4104 | } |
| 4105 | SendUpdateFaviconURL(urls); |
| 4106 | } |
| 4107 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4108 | } // namespace content |