[email protected] | b553edd5 | 2012-01-10 12:15:23 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5 | #include "content/renderer/render_view_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
| 7 | #include <algorithm> |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 8 | #include <cmath> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 10 | #include "base/auto_reset.h" |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/bind_helpers.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 14 | #include "base/compiler_specific.h" |
[email protected] | 2132d6b | 2013-06-05 00:15:43 | [diff] [blame] | 15 | #include "base/debug/alias.h" |
[email protected] | e7ca289 | 2012-09-01 00:52:15 | [diff] [blame] | 16 | #include "base/debug/trace_event.h" |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 17 | #include "base/files/file_path.h" |
[email protected] | 28fccb3 | 2013-08-29 22:25:46 | [diff] [blame] | 18 | #include "base/i18n/char_iterator.h" |
[email protected] | b1cf337 | 2011-04-20 21:28:10 | [diff] [blame] | 19 | #include "base/json/json_writer.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 20 | #include "base/lazy_instance.h" |
[email protected] | cffd752 | 2012-10-23 19:10:58 | [diff] [blame] | 21 | #include "base/memory/scoped_ptr.h" |
[email protected] | 7ccb707 | 2013-06-10 20:56:28 | [diff] [blame] | 22 | #include "base/message_loop/message_loop_proxy.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 23 | #include "base/metrics/histogram.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 24 | #include "base/path_service.h" |
[email protected] | d3b4ee2 | 2013-07-24 22:50:06 | [diff] [blame] | 25 | #include "base/process/kill.h" |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 26 | #include "base/process/process.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 27 | #include "base/strings/string_number_conversions.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 28 | #include "base/strings/string_piece.h" |
[email protected] | 27c0573 | 2013-02-15 21:55:49 | [diff] [blame] | 29 | #include "base/strings/string_split.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 30 | #include "base/strings/string_util.h" |
[email protected] | 40d11e0 | 2013-03-28 17:43:14 | [diff] [blame] | 31 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 32 | #include "base/strings/utf_string_conversions.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 33 | #include "base/time/time.h" |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 34 | #include "cc/base/switches.h" |
[email protected] | a8cb3b73b | 2013-08-12 05:50:50 | [diff] [blame] | 35 | #include "content/child/appcache/appcache_dispatcher.h" |
| 36 | #include "content/child/appcache/web_application_cache_host_impl.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 37 | #include "content/child/child_thread.h" |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 38 | #include "content/child/npapi/webplugin_delegate_impl.h" |
[email protected] | 541b7b0 | 2013-06-07 00:59:34 | [diff] [blame] | 39 | #include "content/child/request_extra_data.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 40 | #include "content/child/webmessageportchannel_impl.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 41 | #include "content/common/clipboard_messages.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 42 | #include "content/common/database_messages.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 43 | #include "content/common/dom_storage/dom_storage_types.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 44 | #include "content/common/drag_messages.h" |
[email protected] | c26ad88 | 2012-02-07 06:41:20 | [diff] [blame] | 45 | #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 46 | #include "content/common/input_messages.h" |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 47 | #include "content/common/java_bridge_messages.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 48 | #include "content/common/pepper_messages.h" |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 49 | #include "content/common/socket_stream_handle_data.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 50 | #include "content/common/ssl_status_serialization.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 51 | #include "content/common/view_messages.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 52 | #include "content/public/common/bindings_policy.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 53 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 54 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 55 | #include "content/public/common/content_switches.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 56 | #include "content/public/common/context_menu_params.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" |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 59 | #include "content/public/common/file_chooser_params.h" |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 60 | #include "content/public/common/page_zoom.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 61 | #include "content/public/common/ssl_status.h" |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 62 | #include "content/public/common/three_d_api_types.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 63 | #include "content/public/common/url_constants.h" |
[email protected] | 3b366ae | 2013-05-17 21:16:58 | [diff] [blame] | 64 | #include "content/public/common/url_utils.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 65 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 97f5813 | 2012-11-15 20:41:32 | [diff] [blame] | 66 | #include "content/public/renderer/context_menu_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 67 | #include "content/public/renderer/document_state.h" |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 68 | #include "content/public/renderer/history_item_serialization.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 69 | #include "content/public/renderer/navigation_state.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 70 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 71 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 72 | #include "content/public/renderer/web_preferences.h" |
[email protected] | 4e4646a5 | 2013-02-08 07:23:41 | [diff] [blame] | 73 | #include "content/renderer/accessibility/renderer_accessibility.h" |
| 74 | #include "content/renderer/accessibility/renderer_accessibility_complete.h" |
| 75 | #include "content/renderer/accessibility/renderer_accessibility_focus_only.h" |
[email protected] | e6e5675 | 2012-08-10 00:46:06 | [diff] [blame] | 76 | #include "content/renderer/browser_plugin/browser_plugin.h" |
| 77 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 78 | #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" |
[email protected] | 3175fea | 2013-05-16 10:57:48 | [diff] [blame] | 79 | #include "content/renderer/context_menu_params_builder.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 80 | #include "content/renderer/devtools/devtools_agent.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 81 | #include "content/renderer/disambiguation_popup_helper.h" |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 82 | #include "content/renderer/dom_automation_controller.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 83 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 84 | #include "content/renderer/drop_data_builder.h" |
[email protected] | 5572215 | 2011-03-22 01:33:53 | [diff] [blame] | 85 | #include "content/renderer/external_popup_menu.h" |
[email protected] | f8c700ba | 2013-05-14 08:25:49 | [diff] [blame] | 86 | #include "content/renderer/fetchers/alt_error_page_resource_fetcher.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 87 | #include "content/renderer/geolocation_dispatcher.h" |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 88 | #include "content/renderer/gpu/input_handler_manager.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 89 | #include "content/renderer/gpu/render_widget_compositor.h" |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 90 | #include "content/renderer/idle_user_detector.h" |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 91 | #include "content/renderer/image_loading_helper.h" |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 92 | #include "content/renderer/ime_event_guard.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 93 | #include "content/renderer/input_tag_speech_dispatcher.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 94 | #include "content/renderer/internal_document_state_data.h" |
[email protected] | 0716190 | 2011-11-11 09:57:42 | [diff] [blame] | 95 | #include "content/renderer/java/java_bridge_dispatcher.h" |
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 96 | #include "content/renderer/load_progress_tracker.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 97 | #include "content/renderer/media/audio_device_factory.h" |
| 98 | #include "content/renderer/media/audio_renderer_mixer_manager.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 99 | #include "content/renderer/media/media_stream_dependency_factory.h" |
| 100 | #include "content/renderer/media/media_stream_dispatcher.h" |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 101 | #include "content/renderer/media/media_stream_impl.h" |
[email protected] | 7b77f6cb | 2013-07-25 16:23:14 | [diff] [blame] | 102 | #include "content/renderer/media/midi_dispatcher.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 103 | #include "content/renderer/media/render_media_log.h" |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 104 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 105 | #include "content/renderer/media/webmediaplayer_impl.h" |
| 106 | #include "content/renderer/media/webmediaplayer_ms.h" |
| 107 | #include "content/renderer/media/webmediaplayer_params.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 108 | #include "content/renderer/mhtml_generator.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 109 | #include "content/renderer/notification_provider.h" |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 110 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 111 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 112 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 113 | #include "content/renderer/render_view_impl_params.h" |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 114 | #include "content/renderer/render_view_mouse_lock_dispatcher.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 115 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 116 | #include "content/renderer/renderer_date_time_picker.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 117 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 118 | #include "content/renderer/renderer_webcolorchooser_impl.h" |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 119 | #include "content/renderer/resizing_mode_selector.h" |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 120 | #include "content/renderer/savable_resources.h" |
[email protected] | 503fa03 | 2013-10-27 19:34:40 | [diff] [blame] | 121 | #include "content/renderer/shared_worker_repository.h" |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 122 | #include "content/renderer/speech_recognition_dispatcher.h" |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 123 | #include "content/renderer/stats_collection_controller.h" |
| 124 | #include "content/renderer/stats_collection_observer.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 125 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 126 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 127 | #include "content/renderer/web_ui_extension.h" |
| 128 | #include "content/renderer/web_ui_extension_data.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 129 | #include "content/renderer/websharedworker_proxy.h" |
[email protected] | f596114 | 2013-04-17 23:09:42 | [diff] [blame] | 130 | #include "media/audio/audio_output_device.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 131 | #include "media/base/audio_renderer_mixer_input.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 132 | #include "media/base/filter_collection.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 133 | #include "media/base/media_switches.h" |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 134 | #include "media/filters/audio_renderer_impl.h" |
[email protected] | 1cad880 | 2013-08-13 16:54:32 | [diff] [blame] | 135 | #include "media/filters/gpu_video_accelerator_factories.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 136 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 137 | #include "net/base/escape.h" |
| 138 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 139 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 140 | #include "net/http/http_util.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 141 | #include "third_party/WebKit/public/platform/WebCString.h" |
| 142 | #include "third_party/WebKit/public/platform/WebDragData.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 143 | #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 144 | #include "third_party/WebKit/public/platform/WebImage.h" |
| 145 | #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 146 | #include "third_party/WebKit/public/platform/WebPoint.h" |
| 147 | #include "third_party/WebKit/public/platform/WebRect.h" |
| 148 | #include "third_party/WebKit/public/platform/WebSize.h" |
| 149 | #include "third_party/WebKit/public/platform/WebSocketStreamHandle.h" |
| 150 | #include "third_party/WebKit/public/platform/WebString.h" |
| 151 | #include "third_party/WebKit/public/platform/WebURL.h" |
| 152 | #include "third_party/WebKit/public/platform/WebURLError.h" |
| 153 | #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 154 | #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 155 | #include "third_party/WebKit/public/platform/WebVector.h" |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 156 | #include "third_party/WebKit/public/web/WebAXObject.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 157 | #include "third_party/WebKit/public/web/WebColorName.h" |
| 158 | #include "third_party/WebKit/public/web/WebDOMEvent.h" |
| 159 | #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" |
| 160 | #include "third_party/WebKit/public/web/WebDataSource.h" |
| 161 | #include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h" |
| 162 | #include "third_party/WebKit/public/web/WebDateTimeChooserParams.h" |
| 163 | #include "third_party/WebKit/public/web/WebDevToolsAgent.h" |
| 164 | #include "third_party/WebKit/public/web/WebDocument.h" |
| 165 | #include "third_party/WebKit/public/web/WebElement.h" |
| 166 | #include "third_party/WebKit/public/web/WebFileChooserParams.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 167 | #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 168 | #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 169 | #include "third_party/WebKit/public/web/WebFormElement.h" |
| 170 | #include "third_party/WebKit/public/web/WebFrame.h" |
[email protected] | 6bd867b | 2013-07-24 22:10:20 | [diff] [blame] | 171 | #include "third_party/WebKit/public/web/WebGlyphCache.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 172 | #include "third_party/WebKit/public/web/WebHelperPlugin.h" |
| 173 | #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 174 | #include "third_party/WebKit/public/web/WebInputElement.h" |
| 175 | #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 176 | #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" |
| 177 | #include "third_party/WebKit/public/web/WebNavigationPolicy.h" |
| 178 | #include "third_party/WebKit/public/web/WebNodeList.h" |
| 179 | #include "third_party/WebKit/public/web/WebPageSerializer.h" |
| 180 | #include "third_party/WebKit/public/web/WebPlugin.h" |
| 181 | #include "third_party/WebKit/public/web/WebPluginAction.h" |
| 182 | #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 183 | #include "third_party/WebKit/public/web/WebPluginDocument.h" |
| 184 | #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 185 | #include "third_party/WebKit/public/web/WebRange.h" |
[email protected] | 91f0576 | 2013-08-21 02:55:09 | [diff] [blame] | 186 | #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 187 | #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 188 | #include "third_party/WebKit/public/web/WebSearchableFormData.h" |
| 189 | #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 190 | #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 191 | #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
| 192 | #include "third_party/WebKit/public/web/WebSettings.h" |
| 193 | #include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h" |
| 194 | #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 195 | #include "third_party/WebKit/public/web/WebUserMediaClient.h" |
| 196 | #include "third_party/WebKit/public/web/WebView.h" |
| 197 | #include "third_party/WebKit/public/web/WebWindowFeatures.h" |
| 198 | #include "third_party/WebKit/public/web/default/WebRenderTheme.h" |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 199 | #include "ui/base/ui_base_switches_util.h" |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 200 | #include "ui/events/latency_info.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 201 | #include "ui/gfx/native_widget_types.h" |
| 202 | #include "ui/gfx/point.h" |
| 203 | #include "ui/gfx/rect.h" |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 204 | #include "ui/gfx/rect_conversions.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 205 | #include "ui/gfx/size_conversions.h" |
[email protected] | 4344a3c | 2013-01-17 23:49:20 | [diff] [blame] | 206 | #include "ui/shell_dialogs/selected_file_info.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 207 | #include "v8/include/v8.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 208 | #include "webkit/child/weburlresponse_extradata_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 209 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 210 | #if defined(OS_ANDROID) |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 211 | #include <cpu-features.h> |
| 212 | |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 213 | #include "content/common/android/device_telephony_info.h" |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 214 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 215 | #include "content/renderer/android/address_detector.h" |
| 216 | #include "content/renderer/android/content_detector.h" |
| 217 | #include "content/renderer/android/email_detector.h" |
| 218 | #include "content/renderer/android/phone_number_detector.h" |
[email protected] | 3a59bb9 | 2013-08-22 18:54:08 | [diff] [blame] | 219 | #include "content/renderer/android/synchronous_compositor_factory.h" |
[email protected] | bc42744 | 2013-07-13 02:53:08 | [diff] [blame] | 220 | #include "content/renderer/media/android/renderer_media_player_manager.h" |
[email protected] | 3aaba57 | 2013-08-10 15:10:38 | [diff] [blame] | 221 | #include "content/renderer/media/android/stream_texture_factory_android_impl.h" |
[email protected] | be58099 | 2013-06-22 14:32:44 | [diff] [blame] | 222 | #include "content/renderer/media/android/webmediaplayer_android.h" |
[email protected] | c277d3c | 2013-07-15 21:49:37 | [diff] [blame] | 223 | #include "skia/ext/platform_canvas.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 224 | #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 225 | #include "third_party/WebKit/public/platform/WebFloatRect.h" |
[email protected] | d0fcff7 | 2013-07-23 02:45:43 | [diff] [blame] | 226 | #include "third_party/WebKit/public/web/WebHitTestResult.h" |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 227 | #include "ui/gfx/rect_f.h" |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 228 | |
| 229 | #if defined(GOOGLE_TV) |
| 230 | #include "content/renderer/media/rtc_video_decoder_bridge_tv.h" |
| 231 | #include "content/renderer/media/rtc_video_decoder_factory_tv.h" |
| 232 | #endif |
| 233 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 234 | #elif defined(OS_WIN) |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 235 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 236 | // * theming |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 237 | #include "ui/native_theme/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 238 | #elif defined(USE_X11) |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 239 | #include "ui/native_theme/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 240 | #elif defined(OS_MACOSX) |
| 241 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 242 | #endif |
| 243 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 244 | #if defined(ENABLE_PLUGINS) |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 245 | #include "content/renderer/npapi/webplugin_delegate_proxy.h" |
| 246 | #include "content/renderer/npapi/webplugin_impl.h" |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 247 | #include "content/renderer/pepper/pepper_browser_connection.h" |
| 248 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 249 | #include "content/renderer/pepper/pepper_plugin_registry.h" |
| 250 | #include "content/renderer/pepper/pepper_webplugin_impl.h" |
| 251 | #include "content/renderer/pepper/plugin_module.h" |
| 252 | #endif |
| 253 | |
[email protected] | 9ac667e | 2013-09-09 12:49:21 | [diff] [blame] | 254 | #if defined(ENABLE_WEBRTC) |
| 255 | #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 256 | #endif |
| 257 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 258 | using blink::WebAXObject; |
| 259 | using blink::WebApplicationCacheHost; |
| 260 | using blink::WebApplicationCacheHostClient; |
| 261 | using blink::WebCString; |
| 262 | using blink::WebColor; |
| 263 | using blink::WebColorName; |
| 264 | using blink::WebConsoleMessage; |
| 265 | using blink::WebContextMenuData; |
| 266 | using blink::WebCookieJar; |
| 267 | using blink::WebData; |
| 268 | using blink::WebDataSource; |
| 269 | using blink::WebDocument; |
| 270 | using blink::WebDOMEvent; |
| 271 | using blink::WebDOMMessageEvent; |
| 272 | using blink::WebDragData; |
| 273 | using blink::WebDragOperation; |
| 274 | using blink::WebDragOperationsMask; |
| 275 | using blink::WebElement; |
| 276 | using blink::WebExternalPopupMenu; |
| 277 | using blink::WebExternalPopupMenuClient; |
| 278 | using blink::WebFileChooserCompletion; |
| 279 | using blink::WebFindOptions; |
| 280 | using blink::WebFormControlElement; |
| 281 | using blink::WebFormElement; |
| 282 | using blink::WebFrame; |
| 283 | using blink::WebGestureEvent; |
| 284 | using blink::WebHistoryItem; |
| 285 | using blink::WebHTTPBody; |
| 286 | using blink::WebIconURL; |
| 287 | using blink::WebImage; |
| 288 | using blink::WebInputElement; |
| 289 | using blink::WebInputEvent; |
| 290 | using blink::WebMediaPlayer; |
| 291 | using blink::WebMediaPlayerAction; |
| 292 | using blink::WebMediaPlayerClient; |
| 293 | using blink::WebMouseEvent; |
| 294 | using blink::WebNavigationPolicy; |
| 295 | using blink::WebNavigationType; |
| 296 | using blink::WebNode; |
| 297 | using blink::WebPageSerializer; |
| 298 | using blink::WebPageSerializerClient; |
| 299 | using blink::WebPeerConnection00Handler; |
| 300 | using blink::WebPeerConnection00HandlerClient; |
| 301 | using blink::WebPeerConnectionHandler; |
| 302 | using blink::WebPeerConnectionHandlerClient; |
| 303 | using blink::WebPluginAction; |
| 304 | using blink::WebPluginContainer; |
| 305 | using blink::WebPluginDocument; |
| 306 | using blink::WebPluginParams; |
| 307 | using blink::WebPoint; |
| 308 | using blink::WebPopupMenuInfo; |
| 309 | using blink::WebRange; |
| 310 | using blink::WebRect; |
| 311 | using blink::WebReferrerPolicy; |
| 312 | using blink::WebRuntimeFeatures; |
| 313 | using blink::WebScriptSource; |
| 314 | using blink::WebSearchableFormData; |
| 315 | using blink::WebSecurityOrigin; |
| 316 | using blink::WebSecurityPolicy; |
| 317 | using blink::WebSerializedScriptValue; |
| 318 | using blink::WebSettings; |
| 319 | using blink::WebSize; |
| 320 | using blink::WebSocketStreamHandle; |
| 321 | using blink::WebStorageNamespace; |
| 322 | using blink::WebStorageQuotaCallbacks; |
| 323 | using blink::WebStorageQuotaError; |
| 324 | using blink::WebStorageQuotaType; |
| 325 | using blink::WebString; |
| 326 | using blink::WebTextAffinity; |
| 327 | using blink::WebTextDirection; |
| 328 | using blink::WebTouchEvent; |
| 329 | using blink::WebURL; |
| 330 | using blink::WebURLError; |
| 331 | using blink::WebURLRequest; |
| 332 | using blink::WebURLResponse; |
| 333 | using blink::WebUserGestureIndicator; |
| 334 | using blink::WebVector; |
| 335 | using blink::WebView; |
| 336 | using blink::WebWidget; |
| 337 | using blink::WebWindowFeatures; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 338 | using base::Time; |
| 339 | using base::TimeDelta; |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 340 | using webkit_glue::WebURLResponseExtraDataImpl; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 341 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 342 | #if defined(OS_ANDROID) |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 343 | using blink::WebContentDetectionResult; |
| 344 | using blink::WebFloatPoint; |
| 345 | using blink::WebFloatRect; |
| 346 | using blink::WebHitTestResult; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 347 | #endif |
| 348 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 349 | namespace content { |
| 350 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 351 | //----------------------------------------------------------------------------- |
| 352 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 353 | typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 354 | static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 355 | typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap; |
| 356 | static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map = |
| 357 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 358 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 359 | // Time, in seconds, we delay before sending content state changes (such as form |
| 360 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 361 | // spamming the browser. |
| 362 | // To avoid having tab/session restore require sending a message to get the |
| 363 | // current content state during tab closing we use a shorter timeout for the |
| 364 | // foreground renderer. This means there is a small window of time from which |
| 365 | // content state is modified and not sent to session restore, but this is |
| 366 | // better than having to wake up all renderers during shutdown. |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 367 | const int kDelaySecondsForContentStateSyncHidden = 5; |
| 368 | const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 369 | |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 370 | const size_t kExtraCharsBeforeAndAfterSelection = 100; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 371 | |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 372 | const float kScalingIncrementForGesture = 0.01f; |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 373 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 374 | #if defined(OS_ANDROID) |
| 375 | // Delay between tapping in content and launching the associated android intent. |
| 376 | // Used to allow users see what has been recognized as content. |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 377 | const size_t kContentIntentDelayMilliseconds = 700; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 378 | #endif |
| 379 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 380 | static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = |
| 381 | NULL; |
| 382 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 383 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 384 | // Replace any occurrences of swappedout:// with about:blank. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 385 | const WebURL& blank_url = GURL(kAboutBlankURL); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 386 | WebVector<WebURL> urls; |
| 387 | ds->redirectChain(urls); |
| 388 | result->reserve(urls.size()); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 389 | for (size_t i = 0; i < urls.size(); ++i) { |
| 390 | if (urls[i] != GURL(kSwappedOutURL)) |
| 391 | result->push_back(urls[i]); |
| 392 | else |
| 393 | result->push_back(blank_url); |
| 394 | } |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 395 | } |
| 396 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 397 | // If |data_source| is non-null and has an InternalDocumentStateData associated |
| 398 | // with it, the AltErrorPageResourceFetcher is reset. |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 399 | static void StopAltErrorPageFetcher(WebDataSource* data_source) { |
| 400 | if (data_source) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 401 | InternalDocumentStateData* internal_data = |
| 402 | InternalDocumentStateData::FromDataSource(data_source); |
| 403 | if (internal_data) |
| 404 | internal_data->set_alt_error_page_fetcher(NULL); |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 408 | static bool IsReload(const ViewMsg_Navigate_Params& params) { |
| 409 | return |
| 410 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 411 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE || |
| 412 | params.navigation_type == |
| 413 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 414 | } |
| 415 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 416 | // static |
| 417 | WebReferrerPolicy RenderViewImpl::GetReferrerPolicyFromRequest( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 418 | WebFrame* frame, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 419 | const WebURLRequest& request) { |
| 420 | return request.extraData() ? |
| 421 | static_cast<RequestExtraData*>(request.extraData())->referrer_policy() : |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 422 | frame->document().referrerPolicy(); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 423 | } |
| 424 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 425 | // static |
| 426 | Referrer RenderViewImpl::GetReferrerFromRequest( |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 427 | WebFrame* frame, |
| 428 | const WebURLRequest& request) { |
| 429 | return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 430 | GetReferrerPolicyFromRequest(frame, request)); |
| 431 | } |
| 432 | |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 433 | // static |
| 434 | WebURLResponseExtraDataImpl* RenderViewImpl::GetExtraDataFromResponse( |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 435 | const WebURLResponse& response) { |
| 436 | return static_cast<WebURLResponseExtraDataImpl*>( |
| 437 | response.extraData()); |
| 438 | } |
| 439 | |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 440 | NOINLINE static void CrashIntentionally() { |
| 441 | // NOTE(shess): Crash directly rather than using NOTREACHED() so |
| 442 | // that the signature is easier to triage in crash reports. |
| 443 | volatile int* zero = NULL; |
| 444 | *zero = 0; |
| 445 | } |
| 446 | |
[email protected] | 2132d6b | 2013-06-05 00:15:43 | [diff] [blame] | 447 | #if defined(ADDRESS_SANITIZER) |
| 448 | NOINLINE static void MaybeTriggerAsanError(const GURL& url) { |
| 449 | // NOTE(rogerm): We intentionally perform an invalid heap access here in |
| 450 | // order to trigger an Address Sanitizer (ASAN) error report. |
| 451 | static const char kCrashDomain[] = "crash"; |
| 452 | static const char kHeapOverflow[] = "/heap-overflow"; |
| 453 | static const char kHeapUnderflow[] = "/heap-underflow"; |
| 454 | static const char kUseAfterFree[] = "/use-after-free"; |
| 455 | static const int kArraySize = 5; |
| 456 | |
| 457 | if (!url.DomainIs(kCrashDomain, sizeof(kCrashDomain) - 1)) |
| 458 | return; |
| 459 | |
| 460 | if (!url.has_path()) |
| 461 | return; |
| 462 | |
| 463 | scoped_ptr<int[]> array(new int[kArraySize]); |
| 464 | std::string crash_type(url.path()); |
| 465 | int dummy = 0; |
| 466 | if (crash_type == kHeapOverflow) { |
| 467 | dummy = array[kArraySize]; |
| 468 | } else if (crash_type == kHeapUnderflow ) { |
| 469 | dummy = array[-1]; |
| 470 | } else if (crash_type == kUseAfterFree) { |
| 471 | int* dangling = array.get(); |
| 472 | array.reset(); |
| 473 | dummy = dangling[kArraySize / 2]; |
| 474 | } |
| 475 | |
| 476 | // Make sure the assignments to the dummy value aren't optimized away. |
| 477 | base::debug::Alias(&dummy); |
| 478 | } |
| 479 | #endif // ADDRESS_SANITIZER |
| 480 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 481 | static void MaybeHandleDebugURL(const GURL& url) { |
| 482 | if (!url.SchemeIs(chrome::kChromeUIScheme)) |
| 483 | return; |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 484 | if (url == GURL(kChromeUICrashURL)) { |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 485 | CrashIntentionally(); |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 486 | } else if (url == GURL(kChromeUIKillURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 487 | base::KillProcess(base::GetCurrentProcessHandle(), 1, false); |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 488 | } else if (url == GURL(kChromeUIHangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 489 | for (;;) { |
| 490 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 491 | } |
[email protected] | 50f86bc | 2012-11-01 19:59:13 | [diff] [blame] | 492 | } else if (url == GURL(kChromeUIShorthangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 493 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 494 | } |
[email protected] | 2132d6b | 2013-06-05 00:15:43 | [diff] [blame] | 495 | |
| 496 | #if defined(ADDRESS_SANITIZER) |
| 497 | MaybeTriggerAsanError(url); |
| 498 | #endif // ADDRESS_SANITIZER |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 499 | } |
| 500 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 501 | // Returns false unless this is a top-level navigation. |
| 502 | static bool IsTopLevelNavigation(WebFrame* frame) { |
| 503 | return frame->parent() == NULL; |
| 504 | } |
| 505 | |
| 506 | // Returns false unless this is a top-level navigation that crosses origins. |
| 507 | static bool IsNonLocalTopLevelNavigation(const GURL& url, |
| 508 | WebFrame* frame, |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 509 | WebNavigationType type, |
| 510 | bool is_form_post) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 511 | if (!IsTopLevelNavigation(frame)) |
| 512 | return false; |
| 513 | |
| 514 | // Navigations initiated within Webkit are not sent out to the external host |
| 515 | // in the following cases. |
| 516 | // 1. The url scheme is not http/https |
| 517 | // 2. The origin of the url and the opener is the same in which case the |
| 518 | // opener relationship is maintained. |
| 519 | // 3. Reloads/form submits/back forward navigations |
[email protected] | e9a8204 | 2013-09-15 03:38:29 | [diff] [blame] | 520 | if (!url.SchemeIs(kHttpScheme) && !url.SchemeIs(kHttpsScheme)) |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 521 | return false; |
| 522 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 523 | if (type != blink::WebNavigationTypeReload && |
| 524 | type != blink::WebNavigationTypeBackForward && !is_form_post) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 525 | // The opener relationship between the new window and the parent allows the |
| 526 | // new window to script the parent and vice versa. This is not allowed if |
| 527 | // the origins of the two domains are different. This can be treated as a |
| 528 | // top level navigation and routed back to the host. |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 529 | blink::WebFrame* opener = frame->opener(); |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 530 | if (!opener) |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 531 | return true; |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 532 | |
| 533 | if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
| 534 | return true; |
| 535 | } |
| 536 | return false; |
| 537 | } |
| 538 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 539 | static void NotifyTimezoneChange(blink::WebFrame* frame) { |
[email protected] | e1907b43 | 2013-09-04 16:11:14 | [diff] [blame] | 540 | v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 541 | v8::Context::Scope context_scope(frame->mainWorldScriptContext()); |
| 542 | v8::Date::DateTimeConfigurationChangeNotification(); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 543 | blink::WebFrame* child = frame->firstChild(); |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 544 | for (; child; child = child->nextSibling()) |
| 545 | NotifyTimezoneChange(child); |
| 546 | } |
| 547 | |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 548 | static WindowOpenDisposition NavigationPolicyToDisposition( |
| 549 | WebNavigationPolicy policy) { |
| 550 | switch (policy) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 551 | case blink::WebNavigationPolicyIgnore: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 552 | return IGNORE_ACTION; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 553 | case blink::WebNavigationPolicyDownload: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 554 | return SAVE_TO_DISK; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 555 | case blink::WebNavigationPolicyCurrentTab: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 556 | return CURRENT_TAB; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 557 | case blink::WebNavigationPolicyNewBackgroundTab: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 558 | return NEW_BACKGROUND_TAB; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 559 | case blink::WebNavigationPolicyNewForegroundTab: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 560 | return NEW_FOREGROUND_TAB; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 561 | case blink::WebNavigationPolicyNewWindow: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 562 | return NEW_WINDOW; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 563 | case blink::WebNavigationPolicyNewPopup: |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 564 | return NEW_POPUP; |
| 565 | default: |
| 566 | NOTREACHED() << "Unexpected WebNavigationPolicy"; |
| 567 | return IGNORE_ACTION; |
| 568 | } |
| 569 | } |
| 570 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 571 | // Returns true if the device scale is high enough that losing subpixel |
| 572 | // antialiasing won't have a noticeable effect on text quality. |
| 573 | static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) { |
| 574 | #if defined(OS_ANDROID) |
| 575 | // On Android, we never have subpixel antialiasing. |
| 576 | return true; |
| 577 | #else |
| 578 | return device_scale_factor > 1.5f; |
| 579 | #endif |
| 580 | |
| 581 | } |
| 582 | |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 583 | static bool ShouldUseFixedPositionCompositing(float device_scale_factor) { |
| 584 | // Compositing for fixed-position elements is dependent on |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 585 | // device_scale_factor if no flag is set. http://crbug.com/172738 |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 586 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 587 | |
| 588 | if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition)) |
| 589 | return false; |
| 590 | |
| 591 | if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition)) |
| 592 | return true; |
| 593 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 594 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 595 | } |
| 596 | |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 597 | static bool ShouldUseAcceleratedCompositingForOverflowScroll( |
| 598 | float device_scale_factor) { |
| 599 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 600 | |
[email protected] | 7d20c7c | 2013-10-15 13:55:46 | [diff] [blame] | 601 | if (command_line.HasSwitch(switches::kDisableAcceleratedOverflowScroll)) |
| 602 | return false; |
| 603 | |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 604 | if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll)) |
| 605 | return true; |
| 606 | |
| 607 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 608 | } |
| 609 | |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 610 | static bool ShouldUseAcceleratedCompositingForScrollableFrames( |
| 611 | float device_scale_factor) { |
| 612 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 613 | |
| 614 | if (command_line.HasSwitch(switches::kDisableAcceleratedScrollableFrames)) |
| 615 | return false; |
| 616 | |
| 617 | if (command_line.HasSwitch(switches::kEnableAcceleratedScrollableFrames)) |
| 618 | return true; |
| 619 | |
| 620 | if (!cc::switches::IsLCDTextEnabled()) |
| 621 | return true; |
| 622 | |
| 623 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 624 | } |
| 625 | |
| 626 | static bool ShouldUseCompositedScrollingForFrames( |
| 627 | float device_scale_factor) { |
| 628 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 629 | |
| 630 | if (command_line.HasSwitch(switches::kDisableCompositedScrollingForFrames)) |
| 631 | return false; |
| 632 | |
| 633 | if (command_line.HasSwitch(switches::kEnableCompositedScrollingForFrames)) |
| 634 | return true; |
| 635 | |
| 636 | if (!cc::switches::IsLCDTextEnabled()) |
| 637 | return true; |
| 638 | |
| 639 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 640 | } |
| 641 | |
[email protected] | f388a5d | 2013-11-04 20:19:13 | [diff] [blame] | 642 | static bool ShouldUseUniversalAcceleratedCompositingForOverflowScroll() { |
[email protected] | 44de749 | 2013-10-18 15:14:59 | [diff] [blame] | 643 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 644 | |
| 645 | if (command_line.HasSwitch( |
| 646 | switches::kDisableUniversalAcceleratedOverflowScroll)) |
| 647 | return false; |
| 648 | |
| 649 | if (command_line.HasSwitch( |
| 650 | switches::kEnableUniversalAcceleratedOverflowScroll)) |
| 651 | return true; |
| 652 | |
[email protected] | f388a5d | 2013-11-04 20:19:13 | [diff] [blame] | 653 | return false; |
[email protected] | 44de749 | 2013-10-18 15:14:59 | [diff] [blame] | 654 | } |
| 655 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 656 | static bool ShouldUseTransitionCompositing(float device_scale_factor) { |
| 657 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 658 | |
| 659 | if (command_line.HasSwitch(switches::kDisableCompositingForTransition)) |
| 660 | return false; |
| 661 | |
| 662 | if (command_line.HasSwitch(switches::kEnableCompositingForTransition)) |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 663 | return true; |
| 664 | |
[email protected] | 9a7f6e1 | 2013-06-11 07:05:13 | [diff] [blame] | 665 | // TODO(ajuma): Re-enable this by default for high-DPI once the problem |
| 666 | // of excessive layer promotion caused by overlap has been addressed. |
| 667 | // http://crbug.com/178119. |
| 668 | return false; |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 669 | } |
| 670 | |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 671 | static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) { |
| 672 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 673 | |
| 674 | if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground)) |
| 675 | return false; |
| 676 | |
| 677 | if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground)) |
| 678 | return true; |
| 679 | |
| 680 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 681 | } |
| 682 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 683 | static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) { |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 684 | switch (type) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 685 | case blink::WebIconURL::TypeFavicon: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 686 | return FaviconURL::FAVICON; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 687 | case blink::WebIconURL::TypeTouch: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 688 | return FaviconURL::TOUCH_ICON; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 689 | case blink::WebIconURL::TypeTouchPrecomposed: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 690 | return FaviconURL::TOUCH_PRECOMPOSED_ICON; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 691 | case blink::WebIconURL::TypeInvalid: |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 692 | return FaviconURL::INVALID_ICON; |
| 693 | } |
| 694 | return FaviconURL::INVALID_ICON; |
| 695 | } |
| 696 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 697 | /////////////////////////////////////////////////////////////////////////////// |
| 698 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 699 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 700 | PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c) |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 701 | : params(p), |
| 702 | completion(c) { |
| 703 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 704 | FileChooserParams params; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 705 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 706 | }; |
| 707 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 708 | namespace { |
| 709 | |
| 710 | class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { |
| 711 | public: |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 712 | explicit WebWidgetLockTarget(blink::WebWidget* webwidget) |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 713 | : webwidget_(webwidget) {} |
| 714 | |
| 715 | virtual void OnLockMouseACK(bool succeeded) OVERRIDE { |
| 716 | if (succeeded) |
| 717 | webwidget_->didAcquirePointerLock(); |
| 718 | else |
| 719 | webwidget_->didNotAcquirePointerLock(); |
| 720 | } |
| 721 | |
| 722 | virtual void OnMouseLockLost() OVERRIDE { |
| 723 | webwidget_->didLosePointerLock(); |
| 724 | } |
| 725 | |
| 726 | virtual bool HandleMouseLockedInputEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 727 | const blink::WebMouseEvent &event) OVERRIDE { |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 728 | // The WebWidget handles mouse lock in WebKit's handleInputEvent(). |
| 729 | return false; |
| 730 | } |
| 731 | |
| 732 | private: |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 733 | blink::WebWidget* webwidget_; |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 734 | }; |
| 735 | |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 736 | int64 ExtractPostId(const WebHistoryItem& item) { |
| 737 | if (item.isNull()) |
| 738 | return -1; |
| 739 | |
| 740 | if (item.httpBody().isNull()) |
| 741 | return -1; |
| 742 | |
| 743 | return item.httpBody().identifier(); |
| 744 | } |
| 745 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 746 | bool TouchEnabled() { |
| 747 | // Based on the definition of chrome::kEnableTouchIcon. |
| 748 | #if defined(OS_ANDROID) |
| 749 | return true; |
| 750 | #else |
| 751 | return false; |
| 752 | #endif |
| 753 | } |
| 754 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 755 | WebDragData DropDataToWebDragData(const DropData& drop_data) { |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 756 | std::vector<WebDragData::Item> item_list; |
| 757 | |
| 758 | // These fields are currently unused when dragging into WebKit. |
| 759 | DCHECK(drop_data.download_metadata.empty()); |
| 760 | DCHECK(drop_data.file_contents.empty()); |
| 761 | DCHECK(drop_data.file_description_filename.empty()); |
| 762 | |
| 763 | if (!drop_data.text.is_null()) { |
| 764 | WebDragData::Item item; |
| 765 | item.storageType = WebDragData::Item::StorageTypeString; |
| 766 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| 767 | item.stringData = drop_data.text.string(); |
| 768 | item_list.push_back(item); |
| 769 | } |
| 770 | |
| 771 | // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it |
| 772 | // meaningful to write an empty URL to the clipboard? |
| 773 | if (!drop_data.url.is_empty()) { |
| 774 | WebDragData::Item item; |
| 775 | item.storageType = WebDragData::Item::StorageTypeString; |
| 776 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 777 | item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
| 778 | item.title = drop_data.url_title; |
| 779 | item_list.push_back(item); |
| 780 | } |
| 781 | |
| 782 | if (!drop_data.html.is_null()) { |
| 783 | WebDragData::Item item; |
| 784 | item.storageType = WebDragData::Item::StorageTypeString; |
| 785 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 786 | item.stringData = drop_data.html.string(); |
| 787 | item.baseURL = drop_data.html_base_url; |
| 788 | item_list.push_back(item); |
| 789 | } |
| 790 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 791 | for (std::vector<DropData::FileInfo>::const_iterator it = |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 792 | drop_data.filenames.begin(); |
| 793 | it != drop_data.filenames.end(); |
| 794 | ++it) { |
| 795 | WebDragData::Item item; |
| 796 | item.storageType = WebDragData::Item::StorageTypeFilename; |
[email protected] | ef1bbf63 | 2013-10-24 22:54:08 | [diff] [blame] | 797 | item.filenameData = it->path; |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 798 | item.displayNameData = it->display_name; |
| 799 | item_list.push_back(item); |
| 800 | } |
| 801 | |
| 802 | for (std::map<base::string16, base::string16>::const_iterator it = |
| 803 | drop_data.custom_data.begin(); |
| 804 | it != drop_data.custom_data.end(); |
| 805 | ++it) { |
| 806 | WebDragData::Item item; |
| 807 | item.storageType = WebDragData::Item::StorageTypeString; |
| 808 | item.stringType = it->first; |
| 809 | item.stringData = it->second; |
| 810 | item_list.push_back(item); |
| 811 | } |
| 812 | |
| 813 | WebDragData result; |
| 814 | result.initialize(); |
| 815 | result.setItems(item_list); |
| 816 | result.setFilesystemId(drop_data.filesystem_id); |
| 817 | return result; |
| 818 | } |
| 819 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 820 | } // namespace |
| 821 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 822 | RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 823 | : RenderWidget(blink::WebPopupTypeNone, |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 824 | params->screen_info, |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 825 | params->swapped_out, |
| 826 | params->hidden), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 827 | webkit_preferences_(params->webkit_prefs), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 828 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 829 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 830 | send_preferred_size_changes_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 831 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 832 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 833 | opened_by_user_gesture_(true), |
| 834 | opener_suppressed_(false), |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 835 | suppress_dialogs_until_swap_out_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 836 | page_id_(-1), |
| 837 | last_page_id_sent_to_browser_(-1), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 838 | next_page_id_(params->next_page_id), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 839 | history_list_offset_(-1), |
| 840 | history_list_length_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 841 | target_url_status_(TARGET_NONE), |
[email protected] | bbef1d3 | 2011-10-25 14:36:55 | [diff] [blame] | 842 | selection_text_offset_(0), |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 843 | selection_range_(gfx::Range::InvalidRange()), |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 844 | #if defined(OS_ANDROID) |
| 845 | top_controls_constraints_(cc::BOTH), |
| 846 | #endif |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 847 | cached_is_main_frame_pinned_to_left_(false), |
| 848 | cached_is_main_frame_pinned_to_right_(false), |
| 849 | cached_has_main_frame_horizontal_scrollbar_(false), |
| 850 | cached_has_main_frame_vertical_scrollbar_(false), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 851 | cookie_jar_(this), |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 852 | notification_provider_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 853 | geolocation_dispatcher_(NULL), |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 854 | input_tag_speech_dispatcher_(NULL), |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 855 | speech_recognition_dispatcher_(NULL), |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 856 | media_stream_dispatcher_(NULL), |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 857 | browser_plugin_manager_(NULL), |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 858 | media_stream_client_(NULL), |
| 859 | web_user_media_client_(NULL), |
[email protected] | f39b9d5 | 2013-07-28 08:03:44 | [diff] [blame] | 860 | midi_dispatcher_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 861 | devtools_agent_(NULL), |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 862 | accessibility_mode_(AccessibilityModeOff), |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 863 | renderer_accessibility_(NULL), |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 864 | mouse_lock_dispatcher_(NULL), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 865 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 866 | body_background_color_(SK_ColorWHITE), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 867 | expected_content_intent_id_(0), |
[email protected] | 305ecfc7 | 2013-10-31 00:35:48 | [diff] [blame] | 868 | media_player_manager_(NULL), |
[email protected] | a756427 | 2013-04-19 14:24:46 | [diff] [blame] | 869 | #endif |
| 870 | #if defined(OS_WIN) |
| 871 | focused_plugin_id_(-1), |
| 872 | #endif |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 873 | #if defined(ENABLE_PLUGINS) |
| 874 | focused_pepper_plugin_(NULL), |
| 875 | pepper_last_mouse_event_target_(NULL), |
| 876 | #endif |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 877 | enumeration_completion_id_(0), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 878 | load_progress_tracker_(new LoadProgressTracker(this)), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 879 | session_storage_namespace_id_(params->session_storage_namespace_id), |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 880 | handling_select_range_(false), |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 881 | next_snapshot_id_(0), |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 882 | allow_partial_swap_(params->allow_partial_swap), |
[email protected] | 07fb8d5 | 2013-08-07 17:03:51 | [diff] [blame] | 883 | context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | void RenderViewImpl::Initialize(RenderViewImplParams* params) { |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 887 | routing_id_ = params->routing_id; |
| 888 | surface_id_ = params->surface_id; |
| 889 | if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created) |
| 890 | opener_id_ = params->opener_id; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 891 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 892 | // Ensure we start with a valid next_page_id_ from the browser. |
| 893 | DCHECK_GE(next_page_id_, 0); |
| 894 | |
[email protected] | 21b3a6ae | 2011-11-30 00:45:29 | [diff] [blame] | 895 | #if defined(ENABLE_NOTIFICATIONS) |
| 896 | notification_provider_ = new NotificationProvider(this); |
| 897 | #else |
| 898 | notification_provider_ = NULL; |
| 899 | #endif |
| 900 | |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 901 | webwidget_ = WebView::create(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 902 | webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 903 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 904 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 905 | |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 906 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 907 | stats_collection_observer_.reset(new StatsCollectionObserver(this)); |
| 908 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 909 | #if defined(OS_ANDROID) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 910 | content::DeviceTelephonyInfo device_info; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 911 | |
| 912 | const std::string region_code = |
| 913 | command_line.HasSwitch(switches::kNetworkCountryIso) |
| 914 | ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 915 | : device_info.GetNetworkCountryIso(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 916 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 917 | new AddressDetector())); |
| 918 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 919 | new PhoneNumberDetector(region_code))); |
| 920 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 921 | new EmailDetector())); |
| 922 | #endif |
| 923 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 924 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 925 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 926 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 927 | AddRef(); |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 928 | if (is_hidden_) |
| 929 | RenderThread::Get()->WidgetHidden(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 930 | |
| 931 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 932 | // completing initialization. Otherwise, we can finish it now. |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 933 | if (opener_id_ == MSG_ROUTING_NONE) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 934 | did_show_ = true; |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 935 | CompleteInit(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 936 | } |
| 937 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 938 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 939 | g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this)); |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 940 | webview()->setDeviceScaleFactor(device_scale_factor_); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 941 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 942 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 943 | webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled( |
| 944 | ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_)); |
[email protected] | 44de749 | 2013-10-18 15:14:59 | [diff] [blame] | 945 | webview()->settings()->setCompositorDrivenAcceleratedScrollingEnabled( |
[email protected] | f388a5d | 2013-11-04 20:19:13 | [diff] [blame] | 946 | ShouldUseUniversalAcceleratedCompositingForOverflowScroll()); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 947 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 948 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 949 | webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled( |
| 950 | ShouldUseAcceleratedFixedRootBackground(device_scale_factor_)); |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 951 | webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled( |
| 952 | ShouldUseAcceleratedCompositingForScrollableFrames(device_scale_factor_)); |
| 953 | webview()->settings()->setCompositedScrollingForFramesEnabled( |
| 954 | ShouldUseCompositedScrollingForFrames(device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 955 | |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 956 | ApplyWebPreferences(webkit_preferences_, webview()); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 957 | |
| 958 | main_render_frame_.reset( |
| 959 | RenderFrameImpl::Create(this, params->main_frame_routing_id)); |
| 960 | // The main frame WebFrame object is closed by |
| 961 | // RenderViewImpl::frameDetached(). |
| 962 | webview()->setMainFrame(WebFrame::create(main_render_frame_.get())); |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 963 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 964 | if (switches::IsTouchDragDropEnabled()) |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 965 | webview()->settings()->setTouchDragDropEnabled(true); |
| 966 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 967 | if (switches::IsTouchEditingEnabled()) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 968 | webview()->settings()->setTouchEditingEnabled(true); |
| 969 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 970 | if (!params->frame_name.empty()) |
| 971 | webview()->mainFrame()->setName(params->frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 972 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 973 | OnSetRendererPrefs(params->renderer_prefs); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 974 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 975 | #if defined(ENABLE_WEBRTC) |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 976 | if (!media_stream_dispatcher_) |
| 977 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 978 | #endif |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 979 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 980 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 981 | #if defined(OS_MACOSX) |
| 982 | new TextInputClientObserver(this); |
| 983 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 984 | |
[email protected] | 503fa03 | 2013-10-27 19:34:40 | [diff] [blame] | 985 | new SharedWorkerRepository(this); |
| 986 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 987 | #if defined(OS_ANDROID) |
[email protected] | 305ecfc7 | 2013-10-31 00:35:48 | [diff] [blame] | 988 | media_player_manager_ = new RendererMediaPlayerManager(this); |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 989 | new JavaBridgeDispatcher(this); |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 990 | #endif |
| 991 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 992 | // The next group of objects all implement RenderViewObserver, so are deleted |
| 993 | // along with the RenderView automatically. |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 994 | devtools_agent_ = new DevToolsAgent(this); |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 995 | if (RenderWidgetCompositor* rwc = compositor()) { |
| 996 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 997 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 998 | mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 999 | new ImageLoadingHelper(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 1000 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1001 | // Create renderer_accessibility_ if needed. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1002 | OnSetAccessibilityMode(params->accessibility_mode); |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1003 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 1004 | new IdleUserDetector(this); |
| 1005 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 1006 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1007 | enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION; |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 1008 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 1009 | enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION; |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 1010 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 1011 | ProcessViewLayoutFlags(command_line); |
[email protected] | 7ddea980 | 2012-02-22 23:08:05 | [diff] [blame] | 1012 | |
[email protected] | b9bad12 | 2013-07-29 20:32:33 | [diff] [blame] | 1013 | #if defined(ENABLE_PLUGINS) |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 1014 | new PepperBrowserConnection(this); |
[email protected] | b9bad12 | 2013-07-29 20:32:33 | [diff] [blame] | 1015 | #endif |
| 1016 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1017 | GetContentClient()->renderer()->RenderViewCreated(this); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1018 | |
| 1019 | // If we have an opener_id but we weren't created by a renderer, then |
| 1020 | // it's the browser asking us to set our opener to another RenderView. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1021 | if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) { |
| 1022 | RenderViewImpl* opener_view = FromRoutingID(params->opener_id); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 1023 | if (opener_view) |
| 1024 | webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | // If we are initially swapped out, navigate to kSwappedOutURL. |
| 1028 | // This ensures we are in a unique origin that others cannot script. |
| 1029 | if (is_swapped_out_) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 1030 | NavigateToSwappedOutURL(webview()->mainFrame()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1031 | } |
| 1032 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1033 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1034 | history_page_ids_.clear(); |
| 1035 | |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 1036 | base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_); |
| 1037 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1038 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1039 | while (!file_chooser_completions_.empty()) { |
| 1040 | if (file_chooser_completions_.front()->completion) { |
| 1041 | file_chooser_completions_.front()->completion->didChooseFile( |
| 1042 | WebVector<WebString>()); |
| 1043 | } |
| 1044 | file_chooser_completions_.pop_front(); |
| 1045 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1046 | |
[email protected] | 8ed1d3f | 2013-02-20 11:45:55 | [diff] [blame] | 1047 | #if defined(OS_ANDROID) |
| 1048 | // The date/time picker client is both a scoped_ptr member of this class and |
| 1049 | // a RenderViewObserver. Reset it to prevent double deletion. |
| 1050 | date_time_picker_client_.reset(); |
| 1051 | #endif |
| 1052 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1053 | #ifndef NDEBUG |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 1054 | // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 1055 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1056 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 1057 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 1058 | RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 1059 | for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 1060 | it != routing_id_views->end(); ++it) |
| 1061 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1062 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1063 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1064 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1065 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1069 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1070 | ViewMap* views = g_view_map.Pointer(); |
| 1071 | ViewMap::iterator it = views->find(webview); |
| 1072 | return it == views->end() ? NULL : it->second; |
| 1073 | } |
| 1074 | |
| 1075 | /*static*/ |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 1076 | RenderView* RenderView::FromWebView(blink::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1077 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | /*static*/ |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 1081 | RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) { |
| 1082 | RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
| 1083 | RoutingIDViewMap::iterator it = views->find(routing_id); |
| 1084 | return it == views->end() ? NULL : it->second; |
| 1085 | } |
| 1086 | |
| 1087 | /*static*/ |
| 1088 | RenderView* RenderView::FromRoutingID(int routing_id) { |
| 1089 | return RenderViewImpl::FromRoutingID(routing_id); |
| 1090 | } |
| 1091 | |
| 1092 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1093 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 1094 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 1095 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 1096 | if (!visitor->Visit(it->second)) |
| 1097 | return; |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1102 | RenderViewImpl* RenderViewImpl::Create( |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1103 | int32 opener_id, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1104 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1105 | const WebPreferences& webkit_prefs, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1106 | int32 routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1107 | int32 main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1108 | int32 surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1109 | int64 session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1110 | const string16& frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1111 | bool is_renderer_created, |
| 1112 | bool swapped_out, |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 1113 | bool hidden, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1114 | int32 next_page_id, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 1115 | const blink::WebScreenInfo& screen_info, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 1116 | AccessibilityMode accessibility_mode, |
| 1117 | bool allow_partial_swap) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1118 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1119 | RenderViewImplParams params( |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1120 | opener_id, |
| 1121 | renderer_prefs, |
| 1122 | webkit_prefs, |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1123 | routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1124 | main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1125 | surface_id, |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1126 | session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1127 | frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1128 | is_renderer_created, |
| 1129 | swapped_out, |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 1130 | hidden, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1131 | next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1132 | screen_info, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 1133 | accessibility_mode, |
| 1134 | allow_partial_swap); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1135 | RenderViewImpl* render_view = NULL; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1136 | if (g_create_render_view_impl) |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1137 | render_view = g_create_render_view_impl(¶ms); |
| 1138 | else |
| 1139 | render_view = new RenderViewImpl(¶ms); |
| 1140 | render_view->Initialize(¶ms); |
| 1141 | return render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | // static |
| 1145 | void RenderViewImpl::InstallCreateHook( |
| 1146 | RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) { |
| 1147 | CHECK(!g_create_render_view_impl); |
| 1148 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1149 | } |
| 1150 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1151 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1152 | observers_.AddObserver(observer); |
| 1153 | } |
| 1154 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1155 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 1156 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1157 | observers_.RemoveObserver(observer); |
| 1158 | } |
| 1159 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 1160 | blink::WebView* RenderViewImpl::webview() const { |
| 1161 | return static_cast<blink::WebView*>(webwidget()); |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 1162 | } |
| 1163 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 1164 | #if defined(ENABLE_PLUGINS) |
| 1165 | void RenderViewImpl::PepperInstanceCreated(PepperPluginInstanceImpl* instance) { |
| 1166 | active_pepper_instances_.insert(instance); |
| 1167 | } |
| 1168 | |
| 1169 | void RenderViewImpl::PepperInstanceDeleted(PepperPluginInstanceImpl* instance) { |
| 1170 | active_pepper_instances_.erase(instance); |
| 1171 | |
| 1172 | if (pepper_last_mouse_event_target_ == instance) |
| 1173 | pepper_last_mouse_event_target_ = NULL; |
| 1174 | if (focused_pepper_plugin_ == instance) |
| 1175 | PepperFocusChanged(instance, false); |
| 1176 | } |
| 1177 | |
| 1178 | void RenderViewImpl::PepperDidChangeCursor( |
| 1179 | PepperPluginInstanceImpl* instance, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 1180 | const blink::WebCursorInfo& cursor) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 1181 | // Update the cursor appearance immediately if the requesting plugin is the |
| 1182 | // one which receives the last mouse event. Otherwise, the new cursor won't be |
| 1183 | // picked up until the plugin gets the next input event. That is bad if, e.g., |
| 1184 | // the plugin would like to set an invisible cursor when there isn't any user |
| 1185 | // input for a while. |
| 1186 | if (instance == pepper_last_mouse_event_target_) |
| 1187 | didChangeCursor(cursor); |
| 1188 | } |
| 1189 | |
| 1190 | void RenderViewImpl::PepperDidReceiveMouseEvent( |
| 1191 | PepperPluginInstanceImpl* instance) { |
| 1192 | pepper_last_mouse_event_target_ = instance; |
| 1193 | } |
| 1194 | |
| 1195 | void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance, |
| 1196 | bool focused) { |
| 1197 | if (focused) |
| 1198 | focused_pepper_plugin_ = instance; |
| 1199 | else if (focused_pepper_plugin_ == instance) |
| 1200 | focused_pepper_plugin_ = NULL; |
| 1201 | |
| 1202 | UpdateTextInputType(); |
| 1203 | UpdateSelectionBounds(); |
| 1204 | } |
| 1205 | |
| 1206 | void RenderViewImpl::PepperTextInputTypeChanged( |
| 1207 | PepperPluginInstanceImpl* instance) { |
| 1208 | if (instance != focused_pepper_plugin_) |
| 1209 | return; |
| 1210 | |
| 1211 | UpdateTextInputType(); |
| 1212 | if (renderer_accessibility_) |
| 1213 | renderer_accessibility_->FocusedNodeChanged(WebNode()); |
| 1214 | } |
| 1215 | |
| 1216 | void RenderViewImpl::PepperCaretPositionChanged( |
| 1217 | PepperPluginInstanceImpl* instance) { |
| 1218 | if (instance != focused_pepper_plugin_) |
| 1219 | return; |
| 1220 | UpdateSelectionBounds(); |
| 1221 | } |
| 1222 | |
| 1223 | void RenderViewImpl::PepperCancelComposition( |
| 1224 | PepperPluginInstanceImpl* instance) { |
| 1225 | if (instance != focused_pepper_plugin_) |
| 1226 | return; |
| 1227 | Send(new ViewHostMsg_ImeCancelComposition(routing_id()));; |
| 1228 | #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA) |
| 1229 | UpdateCompositionInfo(true); |
| 1230 | #endif |
| 1231 | } |
| 1232 | |
| 1233 | void RenderViewImpl::PepperSelectionChanged( |
| 1234 | PepperPluginInstanceImpl* instance) { |
| 1235 | if (instance != focused_pepper_plugin_) |
| 1236 | return; |
| 1237 | SyncSelectionIfRequired(); |
| 1238 | } |
| 1239 | |
| 1240 | RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer( |
| 1241 | PepperPluginInstanceImpl* plugin) { |
| 1242 | GURL active_url; |
| 1243 | if (webview() && webview()->mainFrame()) |
| 1244 | active_url = GURL(webview()->mainFrame()->document().url()); |
| 1245 | RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create( |
| 1246 | routing_id_, plugin, active_url, screen_info_); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 1247 | widget->show(blink::WebNavigationPolicyIgnore); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 1248 | return widget; |
| 1249 | } |
| 1250 | |
| 1251 | void RenderViewImpl::PepperPluginCreated(RendererPpapiHost* host) { |
| 1252 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 1253 | DidCreatePepperPlugin(host)); |
| 1254 | } |
| 1255 | |
| 1256 | bool RenderViewImpl::GetPepperCaretBounds(gfx::Rect* rect) { |
| 1257 | if (!focused_pepper_plugin_) |
| 1258 | return false; |
| 1259 | *rect = focused_pepper_plugin_->GetCaretBounds(); |
| 1260 | return true; |
| 1261 | } |
| 1262 | |
| 1263 | bool RenderViewImpl::IsPepperAcceptingCompositionEvents() const { |
| 1264 | if (!focused_pepper_plugin_) |
| 1265 | return false; |
| 1266 | return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents(); |
| 1267 | } |
| 1268 | |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 1269 | void RenderViewImpl::PluginCrashed(const base::FilePath& plugin_path, |
[email protected] | cf4d6e74 | 2013-01-10 14:06:42 | [diff] [blame] | 1270 | base::ProcessId plugin_pid) { |
| 1271 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path, plugin_pid)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1272 | } |
| 1273 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1274 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1275 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1276 | // If the renderer is visible, set initial visibility and focus state. |
| 1277 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1278 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1279 | delegate->SetContainerVisibility(true); |
| 1280 | if (webview() && webview()->isActive()) |
| 1281 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1282 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1283 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1284 | // Plugins start assuming the content has focus (so that they work in |
| 1285 | // environments where RenderView isn't hosting them), so we always have to |
| 1286 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 1287 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1288 | } |
| 1289 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1290 | void RenderViewImpl::UnregisterPluginDelegate( |
| 1291 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1292 | plugin_delegates_.erase(delegate); |
| 1293 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1294 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1295 | bool RenderViewImpl::GetPluginInfo(const GURL& url, |
| 1296 | const GURL& page_url, |
| 1297 | const std::string& mime_type, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 1298 | WebPluginInfo* plugin_info, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1299 | std::string* actual_mime_type) { |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 1300 | bool found = false; |
| 1301 | Send(new ViewHostMsg_GetPluginInfo( |
| 1302 | routing_id_, url, page_url, mime_type, &found, plugin_info, |
| 1303 | actual_mime_type)); |
| 1304 | return found; |
| 1305 | } |
| 1306 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 1307 | void RenderViewImpl::SimulateImeSetComposition( |
| 1308 | const string16& text, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 1309 | const std::vector<blink::WebCompositionUnderline>& underlines, |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 1310 | int selection_start, |
| 1311 | int selection_end) { |
| 1312 | OnImeSetComposition(text, underlines, selection_start, selection_end); |
| 1313 | } |
| 1314 | |
| 1315 | void RenderViewImpl::SimulateImeConfirmComposition( |
| 1316 | const string16& text, |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 1317 | const gfx::Range& replacement_range) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 1318 | OnImeConfirmComposition(text, replacement_range, false); |
| 1319 | } |
| 1320 | |
| 1321 | #if defined(OS_WIN) |
| 1322 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1323 | if (focused) |
| 1324 | focused_plugin_id_ = plugin_id; |
| 1325 | else |
| 1326 | focused_plugin_id_ = -1; |
| 1327 | } |
| 1328 | #endif |
| 1329 | |
| 1330 | #if defined(OS_MACOSX) |
| 1331 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
| 1332 | Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); |
| 1333 | } |
| 1334 | |
| 1335 | void RenderViewImpl::StartPluginIme() { |
| 1336 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
| 1337 | // This message can be sent during event-handling, and needs to be delivered |
| 1338 | // within that context. |
| 1339 | msg->set_unblock(true); |
| 1340 | Send(msg); |
| 1341 | } |
| 1342 | #endif // defined(OS_MACOSX) |
| 1343 | |
| 1344 | #endif // ENABLE_PLUGINS |
| 1345 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 1346 | void RenderViewImpl::TransferActiveWheelFlingAnimation( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 1347 | const blink::WebActiveWheelFlingParameters& params) { |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 1348 | if (webview()) |
| 1349 | webview()->transferActiveWheelFlingAnimation(params); |
| 1350 | } |
| 1351 | |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 1352 | bool RenderViewImpl::HasIMETextFocus() { |
| 1353 | return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
| 1354 | } |
| 1355 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1356 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1357 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 1358 | if (main_frame) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1359 | GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1360 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1361 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 1362 | RenderViewObserver* observer; |
| 1363 | while ((observer = it.GetNext()) != NULL) |
| 1364 | if (observer->OnMessageReceived(message)) |
| 1365 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1366 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1367 | bool handled = true; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1368 | bool msg_is_ok = true; |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1369 | IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1370 | IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) |
| 1371 | IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) |
| 1372 | IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete) |
| 1373 | IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand) |
| 1374 | IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret) |
| 1375 | IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) |
| 1376 | IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
| 1377 | IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) |
| 1378 | IPC_MESSAGE_HANDLER(InputMsg_Replace, OnReplace) |
| 1379 | IPC_MESSAGE_HANDLER(InputMsg_ReplaceMisspelling, OnReplaceMisspelling) |
| 1380 | IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect, |
| 1381 | OnScrollFocusedEditableNodeIntoRect) |
| 1382 | IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll) |
| 1383 | IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange) |
| 1384 | IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent, |
| 1385 | OnSetEditCommandsForNextKeyEvent) |
| 1386 | IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) |
| 1387 | IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1388 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 1389 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1390 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1391 | IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1392 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets, |
| 1393 | OnSetEditableSelectionOffsets) |
| 1394 | IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText, |
| 1395 | OnSetCompositionFromExistingText) |
| 1396 | IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete, |
| 1397 | OnExtendSelectionAndDelete) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1398 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
| 1399 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 1400 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 1401 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1402 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 1403 | IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1404 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 1405 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1406 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1407 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 1408 | OnResetPageEncodingToDefault) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1409 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 1410 | IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 1411 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1412 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 1413 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 1414 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 1415 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| 1416 | IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) |
| 1417 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 1418 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 1419 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1420 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1421 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 1422 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 1423 | IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1424 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1425 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 1426 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1427 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 1428 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 1429 | IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut, |
| 1430 | OnSuppressDialogsUntilSwapOut) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1431 | IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1432 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 1433 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1434 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 1435 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1436 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 1437 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 1438 | OnEnablePreferredSizeChangedMode) |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1439 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1440 | IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 1441 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 1442 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1443 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 1444 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 1445 | IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent, |
| 1446 | OnOrientationChangeEvent) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1447 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 1448 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 1449 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 1450 | OnCustomContextMenuAction) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 1451 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 1452 | OnGetAllSavableResourceLinksForCurrentPage) |
| 1453 | IPC_MESSAGE_HANDLER( |
| 1454 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 1455 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 1456 | IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 1457 | IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 1458 | // TODO(viettrungluu): Move to a separate message filter. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1459 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 1460 | OnSetHistoryLengthAndPrune) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 1461 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1462 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 1463 | IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener) |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 1464 | IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB, |
| 1465 | OnReleaseDisambiguationPopupDIB) |
| 1466 | IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, |
| 1467 | OnWindowSnapshotCompleted) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1468 | #if defined(OS_ANDROID) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1469 | IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult, |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1470 | OnActivateNearestFindResult) |
| 1471 | IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects) |
| 1472 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1473 | IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView, |
| 1474 | OnUndoScrollFocusedEditableNodeIntoRect) |
[email protected] | 452b4a9 | 2013-03-28 21:24:38 | [diff] [blame] | 1475 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState, |
| 1476 | OnUpdateTopControlsState) |
[email protected] | 68877c28 | 2013-09-20 05:52:42 | [diff] [blame] | 1477 | IPC_MESSAGE_HANDLER(ViewMsg_PauseVideo, OnPauseVideo) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1478 | #elif defined(OS_MACOSX) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1479 | IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1480 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 1481 | OnPluginImeCompositionCompleted) |
| 1482 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 1483 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1484 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| 1485 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| 1486 | #endif |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 1487 | // Adding a new message? Add platform independent ones first, then put the |
| 1488 | // platform specific ones at the end. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1489 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1490 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1491 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1492 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1493 | |
| 1494 | if (!msg_is_ok) { |
| 1495 | // The message had a handler, but its deserialization failed. |
| 1496 | // Kill the renderer to avoid potential spoofing attacks. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1497 | CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1498 | } |
| 1499 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1500 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1501 | } |
| 1502 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1503 | void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 1504 | MaybeHandleDebugURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1505 | if (!webview()) |
| 1506 | return; |
| 1507 | |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 1508 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
| 1509 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1510 | bool is_reload = IsReload(params); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1511 | |
| 1512 | // If this is a stale back/forward (due to a recent navigation the browser |
| 1513 | // didn't know about), ignore it. |
| 1514 | if (IsBackForwardToStaleEntry(params, is_reload)) |
| 1515 | return; |
| 1516 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1517 | // Swap this renderer back in if necessary. |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1518 | if (is_swapped_out_) { |
| 1519 | // We marked the view as hidden when swapping the view out, so be sure to |
| 1520 | // reset the visibility state before navigating to the new URL. |
| 1521 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | 890b06ca | 2012-12-13 21:07:36 | [diff] [blame] | 1522 | |
| 1523 | // If this is an attempt to reload while we are swapped out, we should not |
| 1524 | // reload swappedout://, but the previous page, which is stored in |
| 1525 | // params.state. Setting is_reload to false will treat this like a back |
| 1526 | // navigation to accomplish that. |
| 1527 | is_reload = false; |
| 1528 | |
[email protected] | 0b05902 | 2013-07-03 22:50:09 | [diff] [blame] | 1529 | // We refresh timezone when a view is swapped in since timezone |
| 1530 | // can get out of sync when the system timezone is updated while |
| 1531 | // the view is swapped out. |
| 1532 | NotifyTimezoneChange(webview()->mainFrame()); |
| 1533 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1534 | SetSwappedOut(false); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1535 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1536 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1537 | if (params.should_clear_history_list) { |
| 1538 | CHECK_EQ(params.pending_history_list_offset, -1); |
| 1539 | CHECK_EQ(params.current_history_list_offset, -1); |
| 1540 | CHECK_EQ(params.current_history_list_length, 0); |
| 1541 | } |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1542 | history_list_offset_ = params.current_history_list_offset; |
| 1543 | history_list_length_ = params.current_history_list_length; |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1544 | if (history_list_length_ >= 0) |
| 1545 | history_page_ids_.resize(history_list_length_, -1); |
| 1546 | if (params.pending_history_list_offset >= 0 && |
| 1547 | params.pending_history_list_offset < history_list_length_) |
| 1548 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1549 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1550 | GetContentClient()->SetActiveURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1551 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1552 | WebFrame* frame = webview()->mainFrame(); |
| 1553 | if (!params.frame_to_navigate.empty()) { |
| 1554 | frame = webview()->findFrameByName( |
| 1555 | WebString::fromUTF8(params.frame_to_navigate)); |
| 1556 | CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; |
| 1557 | } |
| 1558 | |
| 1559 | if (is_reload && frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1560 | // We cannot reload if we do not have any history state. This happens, for |
| 1561 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1562 | // a hack since it means that reload after a crashed tab does not cause an |
| 1563 | // end-to-end cache validation. |
| 1564 | is_reload = false; |
| 1565 | } |
| 1566 | |
[email protected] | 3d2fd59 | 2012-11-30 02:05:50 | [diff] [blame] | 1567 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params)); |
[email protected] | 48a5c77 | 2011-04-18 23:50:50 | [diff] [blame] | 1568 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1569 | // If we are reloading, then WebKit will use the history state of the current |
| 1570 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1571 | // have history state, then we need to navigate to it, which corresponds to a |
| 1572 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1573 | if (is_reload) { |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1574 | bool reload_original_url = |
| 1575 | (params.navigation_type == |
| 1576 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1577 | bool ignore_cache = (params.navigation_type == |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 1578 | ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1579 | |
| 1580 | if (reload_original_url) |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1581 | frame->reloadWithOverrideURL(params.url, true); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1582 | else |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1583 | frame->reload(ignore_cache); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1584 | } else if (params.page_state.IsValid()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1585 | // We must know the page ID of the page we are navigating back to. |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1586 | DCHECK_NE(params.page_id, -1); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1587 | WebHistoryItem item = PageStateToHistoryItem(params.page_state); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1588 | if (!item.isNull()) { |
| 1589 | // Ensure we didn't save the swapped out URL in UpdateState, since the |
| 1590 | // browser should never be telling us to navigate to swappedout://. |
| 1591 | CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL)); |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1592 | frame->loadHistoryItem(item); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1593 | } |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1594 | } else if (!params.base_url_for_data_url.is_empty()) { |
| 1595 | // A loadData request with a specified base URL. |
| 1596 | std::string mime_type, charset, data; |
| 1597 | if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1598 | frame->loadData( |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1599 | WebData(data.c_str(), data.length()), |
| 1600 | WebString::fromUTF8(mime_type), |
| 1601 | WebString::fromUTF8(charset), |
| 1602 | params.base_url_for_data_url, |
| 1603 | params.history_url_for_data_url, |
| 1604 | false); |
| 1605 | } else { |
| 1606 | CHECK(false) << |
| 1607 | "Invalid URL passed: " << params.url.possibly_invalid_spec(); |
| 1608 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1609 | } else { |
| 1610 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1611 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1612 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1613 | // A session history navigation should have been accompanied by state. |
[email protected] | cbc0cb7 | 2011-12-06 18:58:23 | [diff] [blame] | 1614 | CHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1615 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1616 | if (frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1617 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1618 | |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1619 | if (params.referrer.url.is_valid()) { |
| 1620 | WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
| 1621 | params.referrer.policy, |
| 1622 | params.url, |
| 1623 | WebString::fromUTF8(params.referrer.url.spec())); |
| 1624 | if (!referrer.isEmpty()) |
| 1625 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1626 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1627 | |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 1628 | if (!params.extra_headers.empty()) { |
| 1629 | for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), |
| 1630 | params.extra_headers.end(), "\n"); |
| 1631 | i.GetNext(); ) { |
| 1632 | request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 1633 | WebString::fromUTF8(i.values())); |
| 1634 | } |
| 1635 | } |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1636 | |
| 1637 | if (params.is_post) { |
| 1638 | request.setHTTPMethod(WebString::fromUTF8("POST")); |
| 1639 | |
| 1640 | // Set post data. |
| 1641 | WebHTTPBody http_body; |
| 1642 | http_body.initialize(); |
| 1643 | http_body.appendData(WebData( |
| 1644 | reinterpret_cast<const char*>( |
| 1645 | ¶ms.browser_initiated_post_data.front()), |
| 1646 | params.browser_initiated_post_data.size())); |
| 1647 | request.setHTTPBody(http_body); |
| 1648 | } |
| 1649 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1650 | frame->loadRequest(request); |
[email protected] | 198a95d6 | 2013-04-11 00:44:21 | [diff] [blame] | 1651 | |
| 1652 | // If this is a cross-process navigation, the browser process will send |
| 1653 | // along the proper navigation start value. |
| 1654 | if (!params.browser_navigation_start.is_null() && |
| 1655 | frame->provisionalDataSource()) { |
| 1656 | // browser_navigation_start is likely before this process existed, so we |
| 1657 | // can't use InterProcessTimeTicksConverter. Instead, the best we can do |
| 1658 | // is just ensure we don't report a bogus value in the future. |
| 1659 | base::TimeTicks navigation_start = std::min( |
| 1660 | base::TimeTicks::Now(), params.browser_navigation_start); |
| 1661 | double navigation_start_seconds = |
| 1662 | (navigation_start - base::TimeTicks()).InSecondsF(); |
| 1663 | frame->provisionalDataSource()->setNavigationStartTime( |
| 1664 | navigation_start_seconds); |
| 1665 | } |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1666 | } |
| 1667 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1668 | // In case LoadRequest failed before DidCreateDataSource was called. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1669 | pending_navigation_params_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1670 | } |
| 1671 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1672 | bool RenderViewImpl::IsBackForwardToStaleEntry( |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1673 | const ViewMsg_Navigate_Params& params, |
| 1674 | bool is_reload) { |
| 1675 | // Make sure this isn't a back/forward to an entry we have already cropped |
| 1676 | // or replaced from our history, before the browser knew about it. If so, |
| 1677 | // a new navigation has committed in the mean time, and we can ignore this. |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1678 | bool is_back_forward = !is_reload && params.page_state.IsValid(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1679 | |
| 1680 | // Note: if the history_list_length_ is 0 for a back/forward, we must be |
| 1681 | // restoring from a previous session. We'll update our state in OnNavigate. |
| 1682 | if (!is_back_forward || history_list_length_ <= 0) |
| 1683 | return false; |
| 1684 | |
| 1685 | DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_); |
| 1686 | |
| 1687 | // Check for whether the forward history has been cropped due to a recent |
| 1688 | // navigation the browser didn't know about. |
| 1689 | if (params.pending_history_list_offset >= history_list_length_) |
| 1690 | return true; |
| 1691 | |
| 1692 | // Check for whether this entry has been replaced with a new one. |
| 1693 | int expected_page_id = |
| 1694 | history_page_ids_[params.pending_history_list_offset]; |
[email protected] | 9978b8f0 | 2011-08-13 16:17:44 | [diff] [blame] | 1695 | if (expected_page_id > 0 && params.page_id != expected_page_id) { |
| 1696 | if (params.page_id < expected_page_id) |
| 1697 | return true; |
| 1698 | |
| 1699 | // Otherwise we've removed an earlier entry and should have shifted all |
| 1700 | // entries left. For now, it's ok to lazily update the list. |
| 1701 | // TODO(creis): Notify all live renderers when we remove entries from |
| 1702 | // the front of the list, so that we don't hit this case. |
| 1703 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
| 1704 | } |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1705 | |
| 1706 | return false; |
| 1707 | } |
| 1708 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1709 | // Stop loading the current page |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1710 | void RenderViewImpl::OnStop() { |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 1711 | if (webview()) { |
| 1712 | WebFrame* main_frame = webview()->mainFrame(); |
| 1713 | // Stop the alt error page fetcher. If we let it continue it may complete |
| 1714 | // and cause RenderViewHostManager to swap to this RenderView, even though |
| 1715 | // it may no longer be active. |
| 1716 | StopAltErrorPageFetcher(main_frame->provisionalDataSource()); |
| 1717 | StopAltErrorPageFetcher(main_frame->dataSource()); |
| 1718 | main_frame->stopLoading(); |
| 1719 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1720 | } |
| 1721 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1722 | // Reload current focused frame. |
| 1723 | // E.g. called by right-clicking on the frame and picking "reload this frame". |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1724 | void RenderViewImpl::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1725 | if (webview() && webview()->focusedFrame()) { |
| 1726 | // We always obey the cache (ignore_cache=false) here. |
| 1727 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1728 | // a cache-ignoring reload of the frame. |
| 1729 | webview()->focusedFrame()->reload(false); |
| 1730 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1731 | } |
| 1732 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1733 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1734 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1735 | } |
| 1736 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1737 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1738 | // Check if there is a targeturl waiting to be sent. |
| 1739 | if (target_url_status_ == TARGET_PENDING) { |
| 1740 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1741 | pending_target_url_)); |
| 1742 | } |
| 1743 | |
| 1744 | target_url_status_ = TARGET_NONE; |
| 1745 | } |
| 1746 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1747 | void RenderViewImpl::OnCopy() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1748 | if (!webview()) |
| 1749 | return; |
| 1750 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1751 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1752 | WebNode current_node = context_menu_node_.isNull() ? |
| 1753 | GetFocusedNode() : context_menu_node_; |
[email protected] | f6b1856b | 2011-06-29 22:02:53 | [diff] [blame] | 1754 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"), |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1755 | current_node); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1756 | } |
| 1757 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1758 | void RenderViewImpl::OnCut() { |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1759 | if (!webview()) |
| 1760 | return; |
| 1761 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1762 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1763 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"), |
| 1764 | GetFocusedNode()); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1765 | } |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1766 | |
| 1767 | void RenderViewImpl::OnDelete() { |
| 1768 | if (!webview()) |
| 1769 | return; |
| 1770 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1771 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"), |
| 1772 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
| 1776 | const std::string& value) { |
| 1777 | if (!webview() || !webview()->focusedFrame()) |
| 1778 | return; |
| 1779 | |
| 1780 | webview()->focusedFrame()->executeCommand( |
| 1781 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
| 1782 | } |
| 1783 | |
| 1784 | void RenderViewImpl::OnMoveCaret(const gfx::Point& point) { |
| 1785 | if (!webview()) |
| 1786 | return; |
| 1787 | |
| 1788 | Send(new ViewHostMsg_MoveCaret_ACK(routing_id_)); |
| 1789 | |
| 1790 | webview()->focusedFrame()->moveCaretSelectionTowardsWindowPoint(point); |
| 1791 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1792 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1793 | void RenderViewImpl::OnPaste() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1794 | if (!webview()) |
| 1795 | return; |
| 1796 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1797 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1798 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"), |
| 1799 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1800 | } |
| 1801 | |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1802 | void RenderViewImpl::OnPasteAndMatchStyle() { |
| 1803 | if (!webview()) |
| 1804 | return; |
| 1805 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1806 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1807 | webview()->focusedFrame()->executeCommand( |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1808 | WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode()); |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1809 | } |
| 1810 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1811 | void RenderViewImpl::OnRedo() { |
| 1812 | if (!webview()) |
| 1813 | return; |
| 1814 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1815 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"), |
| 1816 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1817 | } |
| 1818 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1819 | void RenderViewImpl::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1820 | if (!webview()) |
| 1821 | return; |
| 1822 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1823 | WebFrame* frame = webview()->focusedFrame(); |
| 1824 | if (!frame->hasSelection()) |
| 1825 | frame->selectWordAroundCaret(); |
[email protected] | 2365c64 | 2013-02-12 19:16:47 | [diff] [blame] | 1826 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1827 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1828 | } |
| 1829 | |
[email protected] | 2365c64 | 2013-02-12 19:16:47 | [diff] [blame] | 1830 | void RenderViewImpl::OnReplaceMisspelling(const string16& text) { |
| 1831 | if (!webview()) |
| 1832 | return; |
| 1833 | |
| 1834 | WebFrame* frame = webview()->focusedFrame(); |
| 1835 | if (!frame->hasSelection()) |
| 1836 | return; |
| 1837 | |
| 1838 | frame->replaceMisspelledRange(text); |
| 1839 | } |
| 1840 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1841 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1842 | const gfx::Rect& rect) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 1843 | blink::WebNode node = GetFocusedNode(); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1844 | if (!node.isNull()) { |
| 1845 | if (IsEditableNode(node)) { |
| 1846 | webview()->saveScrollAndScaleState(); |
| 1847 | webview()->scrollFocusedNodeIntoRect(rect); |
| 1848 | } |
| 1849 | } |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1850 | } |
| 1851 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1852 | void RenderViewImpl::OnSelectAll() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1853 | if (!webview()) |
| 1854 | return; |
| 1855 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1856 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1857 | webview()->focusedFrame()->executeCommand( |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1858 | WebString::fromUTF8("SelectAll"), GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1859 | } |
| 1860 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1861 | void RenderViewImpl::OnSelectRange(const gfx::Point& start, |
| 1862 | const gfx::Point& end) { |
| 1863 | if (!webview()) |
| 1864 | return; |
| 1865 | |
| 1866 | Send(new ViewHostMsg_SelectRange_ACK(routing_id_)); |
| 1867 | |
| 1868 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1869 | webview()->focusedFrame()->selectRange(start, end); |
| 1870 | } |
| 1871 | |
| 1872 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
| 1873 | const EditCommands& edit_commands) { |
| 1874 | edit_commands_ = edit_commands; |
| 1875 | } |
| 1876 | |
| 1877 | void RenderViewImpl::OnUndo() { |
| 1878 | if (!webview()) |
| 1879 | return; |
| 1880 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1881 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"), |
| 1882 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1883 | } |
| 1884 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1885 | void RenderViewImpl::OnUnselect() { |
| 1886 | if (!webview()) |
| 1887 | return; |
| 1888 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1889 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1890 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
| 1891 | GetFocusedNode()); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1892 | } |
| 1893 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1894 | #if defined(OS_MACOSX) |
| 1895 | void RenderViewImpl::OnCopyToFindPboard() { |
| 1896 | if (!webview()) |
| 1897 | return; |
| 1898 | |
| 1899 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1900 | // than the |OnCopy()| case. |
| 1901 | WebFrame* frame = webview()->focusedFrame(); |
| 1902 | if (frame->hasSelection()) { |
| 1903 | string16 selection = frame->selectionAsText(); |
| 1904 | RenderThread::Get()->Send( |
| 1905 | new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); |
| 1906 | } |
| 1907 | } |
| 1908 | #endif |
| 1909 | |
| 1910 | void RenderViewImpl::OnSetName(const std::string& name) { |
| 1911 | if (!webview()) |
| 1912 | return; |
| 1913 | |
| 1914 | webview()->mainFrame()->setName(WebString::fromUTF8(name)); |
| 1915 | } |
| 1916 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1917 | void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) { |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1918 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1919 | if (!ShouldHandleImeEvent()) |
| 1920 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1921 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1922 | webview()->setEditableSelectionOffsets(start, end); |
| 1923 | } |
| 1924 | |
| 1925 | void RenderViewImpl::OnSetCompositionFromExistingText( |
| 1926 | int start, int end, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 1927 | const std::vector<blink::WebCompositionUnderline>& underlines) { |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1928 | if (!ShouldHandleImeEvent()) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1929 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1930 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1931 | webview()->setCompositionFromExistingText(start, end, underlines); |
| 1932 | } |
| 1933 | |
| 1934 | void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) { |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1935 | if (!ShouldHandleImeEvent()) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1936 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1937 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1938 | webview()->extendSelectionAndDelete(before, after); |
| 1939 | } |
| 1940 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1941 | void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length, |
| 1942 | int32 minimum_page_id) { |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1943 | DCHECK_GE(history_length, 0); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1944 | DCHECK(history_list_offset_ == history_list_length_ - 1); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1945 | DCHECK_GE(minimum_page_id, -1); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1946 | |
| 1947 | // Generate the new list. |
| 1948 | std::vector<int32> new_history_page_ids(history_length, -1); |
| 1949 | for (size_t i = 0; i < history_page_ids_.size(); ++i) { |
| 1950 | if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id) |
| 1951 | continue; |
| 1952 | new_history_page_ids.push_back(history_page_ids_[i]); |
| 1953 | } |
| 1954 | new_history_page_ids.swap(history_page_ids_); |
| 1955 | |
| 1956 | // Update indexes. |
| 1957 | history_list_length_ = history_page_ids_.size(); |
| 1958 | history_list_offset_ = history_list_length_ - 1; |
| 1959 | } |
| 1960 | |
| 1961 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1962 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1963 | if (!webview()) |
| 1964 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1965 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1966 | } |
| 1967 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1968 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1969 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1970 | if (!webview()) |
| 1971 | return; |
| 1972 | if (in_live_resize) |
| 1973 | webview()->willStartLiveResize(); |
| 1974 | else |
| 1975 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1976 | } |
| 1977 | #endif |
| 1978 | |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1979 | #if defined(OS_ANDROID) |
| 1980 | void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() { |
| 1981 | const WebNode node = GetFocusedNode(); |
| 1982 | if (!node.isNull() && IsEditableNode(node)) |
| 1983 | webview()->restoreScrollAndScaleState(); |
| 1984 | } |
[email protected] | 68877c28 | 2013-09-20 05:52:42 | [diff] [blame] | 1985 | |
| 1986 | void RenderViewImpl::OnPauseVideo() { |
| 1987 | // Inform RendererMediaPlayerManager to release all video player resources. |
| 1988 | // If something is in progress the resource will not be freed, it will |
| 1989 | // only be freed once the tab is destroyed or if the user navigates away |
| 1990 | // via WebMediaPlayerAndroid::Destroy. |
| 1991 | media_player_manager_->ReleaseVideoResources(); |
| 1992 | } |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1993 | #endif |
| 1994 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1995 | /////////////////////////////////////////////////////////////////////////////// |
| 1996 | |
| 1997 | // Tell the embedding application that the URL of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1998 | void RenderViewImpl::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1999 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2000 | DCHECK(ds); |
| 2001 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 2002 | const WebURLRequest& request = ds->request(); |
| 2003 | const WebURLRequest& original_request = ds->originalRequest(); |
| 2004 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2005 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2006 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 2007 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2008 | InternalDocumentStateData* internal_data = |
| 2009 | InternalDocumentStateData::FromDocumentState(document_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2010 | |
| 2011 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 2012 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2013 | params.is_post = false; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 2014 | params.post_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2015 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 2016 | params.frame_id = frame->identifier(); |
[email protected] | 2f673064c | 2013-10-22 04:01:44 | [diff] [blame] | 2017 | params.frame_unique_name = frame->uniqueName(); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 2018 | params.socket_address.set_host(response.remoteIPAddress().utf8()); |
| 2019 | params.socket_address.set_port(response.remotePort()); |
[email protected] | e07ddafe | 2013-03-05 21:03:36 | [diff] [blame] | 2020 | WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response); |
| 2021 | if (extra_data) { |
| 2022 | params.was_fetched_via_proxy = extra_data->was_fetched_via_proxy(); |
| 2023 | } |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 2024 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2025 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2026 | |
| 2027 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 2028 | params.url = GetLoadingUrl(frame); |
[email protected] | 809be03 | 2013-03-19 01:56:56 | [diff] [blame] | 2029 | DCHECK(!is_swapped_out_ || params.url == GURL(kSwappedOutURL)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2030 | |
[email protected] | 5f9b871 | 2011-11-23 08:55:57 | [diff] [blame] | 2031 | if (frame->document().baseURL() != params.url) |
| 2032 | params.base_url = frame->document().baseURL(); |
| 2033 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 2034 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 2035 | params.should_update_history = !ds->hasUnreachableURL() && |
[email protected] | b7df1b7 | 2011-02-10 00:08:04 | [diff] [blame] | 2036 | !response.isMultipartPayload() && (response.httpStatusCode() != 404); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2037 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2038 | params.searchable_form_url = internal_data->searchable_form_url(); |
| 2039 | params.searchable_form_encoding = internal_data->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2040 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2041 | params.gesture = navigation_gesture_; |
| 2042 | navigation_gesture_ = NavigationGestureUnknown; |
| 2043 | |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 2044 | // Make navigation state a part of the FrameNavigate message so that commited |
| 2045 | // entry had it at all times. |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 2046 | WebHistoryItem item = frame->currentHistoryItem(); |
| 2047 | if (item.isNull()) { |
| 2048 | item.initialize(); |
| 2049 | item.setURLString(request.url().spec().utf16()); |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 2050 | } |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 2051 | params.page_state = HistoryItemToPageState(item); |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 2052 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 2053 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2054 | // Top-level navigation. |
| 2055 | |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 2056 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 2057 | // will also call us back which will cause us to send a message to |
| 2058 | // update WebContentsImpl. |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 2059 | webview()->zoomLimitsChanged(ZoomFactorToZoomLevel(kMinimumZoomFactor), |
| 2060 | ZoomFactorToZoomLevel(kMaximumZoomFactor)); |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 2061 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2062 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 2063 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 2064 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 2065 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2066 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 2067 | // Reset the zoom levels for plugins. |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 2068 | webview()->setZoomLevel(0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2069 | } else { |
| 2070 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 2071 | webview()->setZoomLevel(host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2072 | } |
| 2073 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 2074 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2075 | // This zoom level was merely recorded transiently for this load. We can |
| 2076 | // erase it now. If at some point we reload this page, the browser will |
| 2077 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 2078 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2079 | } |
| 2080 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2081 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 2082 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2083 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 2084 | params.transition = navigation_state->transition_type(); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2085 | if (!PageTransitionIsMainFrame(params.transition)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2086 | // If the main frame does a load, it should not be reported as a subframe |
| 2087 | // navigation. This can occur in the following case: |
| 2088 | // 1. You're on a site with frames. |
| 2089 | // 2. You do a subframe navigation. This is stored with transition type |
| 2090 | // MANUAL_SUBFRAME. |
| 2091 | // 3. You navigate to some non-frame site, say, google.com. |
| 2092 | // 4. You navigate back to the page from step 2. Since it was initially |
| 2093 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 2094 | // We don't want that, because any navigation that changes the toplevel |
| 2095 | // frame should be tracked as a toplevel navigation (this allows us to |
| 2096 | // update the URL bar, etc). |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2097 | params.transition = PAGE_TRANSITION_LINK; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2098 | } |
| 2099 | |
[email protected] | a00a2e3 | 2013-07-31 05:08:33 | [diff] [blame] | 2100 | // If the page contained a client redirect (meta refresh, document.loc...), |
| 2101 | // set the referrer and transition appropriately. |
| 2102 | if (ds->isClientRedirect()) { |
| 2103 | params.referrer = Referrer(params.redirects[0], |
| 2104 | GetReferrerPolicyFromRequest(frame, ds->request())); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2105 | params.transition = static_cast<PageTransition>( |
| 2106 | params.transition | PAGE_TRANSITION_CLIENT_REDIRECT); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2107 | } else { |
| 2108 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 2109 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 2110 | params.referrer = GetReferrerFromRequest(frame, original_request); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2111 | } |
| 2112 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 2113 | string16 method = request.httpMethod(); |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 2114 | if (EqualsASCII(method, "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2115 | params.is_post = true; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 2116 | params.post_id = ExtractPostId(item); |
| 2117 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2118 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2119 | // Send the user agent override back. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2120 | params.is_overriding_user_agent = internal_data->is_overriding_user_agent(); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2121 | |
[email protected] | f887290 | 2013-10-30 03:18:57 | [diff] [blame] | 2122 | // Track the URL of the original request. We use the first entry of the |
| 2123 | // redirect chain if it exists because the chain may have started in another |
| 2124 | // process. |
| 2125 | if (params.redirects.size() > 0) |
| 2126 | params.original_request_url = params.redirects.at(0); |
| 2127 | else |
| 2128 | params.original_request_url = original_request.url(); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 2129 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 2130 | params.history_list_was_cleared = |
| 2131 | navigation_state->history_list_was_cleared(); |
| 2132 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 2133 | // Save some histogram data so we can compute the average memory used per |
| 2134 | // page load of the glyphs. |
| 2135 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2136 | blink::WebGlyphCache::pageCount()); |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 2137 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 2138 | // This message needs to be sent before any of allowScripts(), |
| 2139 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 2140 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 2141 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2142 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 2143 | } else { |
| 2144 | // Subframe navigation: the type depends on whether this navigation |
| 2145 | // generated a new session history entry. When they do generate a session |
| 2146 | // history entry, it means the user initiated the navigation and we should |
| 2147 | // mark it as such. This test checks if this is the first time UpdateURL |
| 2148 | // has been called since WillNavigateToURL was called to initiate the load. |
| 2149 | if (page_id_ > last_page_id_sent_to_browser_) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2150 | params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2151 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2152 | params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2153 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 2154 | DCHECK(!navigation_state->history_list_was_cleared()); |
| 2155 | params.history_list_was_cleared = false; |
| 2156 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2157 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 2158 | } |
| 2159 | |
| 2160 | last_page_id_sent_to_browser_ = |
| 2161 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 2162 | |
| 2163 | // If we end up reusing this WebRequest (for example, due to a #ref click), |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 2164 | // we don't want the transition type to persist. Just clear it. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2165 | navigation_state->set_transition_type(PAGE_TRANSITION_LINK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2169 | void RenderViewImpl::UpdateTitle(WebFrame* frame, |
| 2170 | const string16& title, |
| 2171 | WebTextDirection title_direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 2172 | // Ignore all but top level navigations. |
| 2173 | if (frame->parent()) |
| 2174 | return; |
| 2175 | |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 2176 | base::debug::TraceLog::GetInstance()->UpdateProcessLabel( |
| 2177 | routing_id_, UTF16ToUTF8(title)); |
| 2178 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2179 | string16 shortened_title = title.substr(0, kMaxTitleChars); |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 2180 | Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title, |
| 2181 | title_direction)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2182 | } |
| 2183 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2184 | void RenderViewImpl::UpdateEncoding(WebFrame* frame, |
| 2185 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2186 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2187 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2188 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 2189 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2190 | last_encoding_name_ = encoding_name; |
| 2191 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 2192 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2193 | } |
| 2194 | } |
| 2195 | |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 2196 | // Sends the last committed session history state to the browser so it will be |
| 2197 | // saved before we navigate to a new page. This must be called *before* the |
| 2198 | // page ID has been updated so we know what it was. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2199 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2200 | // If we have a valid page ID at this point, then it corresponds to the page |
| 2201 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 2202 | // there is no past session history to record. |
| 2203 | if (page_id_ == -1) |
| 2204 | return; |
| 2205 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2206 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2207 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 2208 | SendUpdateState(item); |
| 2209 | } |
| 2210 | |
| 2211 | void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2212 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2213 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2214 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2215 | // Don't send state updates for kSwappedOutURL. |
| 2216 | if (item.urlString() == WebString::fromUTF8(kSwappedOutURL)) |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 2217 | return; |
| 2218 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 2219 | Send(new ViewHostMsg_UpdateState( |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 2220 | routing_id_, page_id_, HistoryItemToPageState(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2221 | } |
| 2222 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2223 | void RenderViewImpl::OpenURL(WebFrame* frame, |
| 2224 | const GURL& url, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2225 | const Referrer& referrer, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2226 | WebNavigationPolicy policy) { |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 2227 | ViewHostMsg_OpenURL_Params params; |
| 2228 | params.url = url; |
| 2229 | params.referrer = referrer; |
| 2230 | params.disposition = NavigationPolicyToDisposition(policy); |
| 2231 | params.frame_id = frame->identifier(); |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 2232 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2233 | if (ds) { |
[email protected] | 866fa2cc | 2013-07-22 22:19:52 | [diff] [blame] | 2234 | params.should_replace_current_entry = ds->replacesCurrentHistoryItem(); |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 2235 | } else { |
[email protected] | 866fa2cc | 2013-07-22 22:19:52 | [diff] [blame] | 2236 | params.should_replace_current_entry = false; |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 2237 | } |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 2238 | params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame] | 2239 | if (GetContentClient()->renderer()->AllowPopup()) |
| 2240 | params.user_gesture = true; |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 2241 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2242 | if (policy == blink::WebNavigationPolicyNewBackgroundTab || |
| 2243 | policy == blink::WebNavigationPolicyNewForegroundTab || |
| 2244 | policy == blink::WebNavigationPolicyNewWindow || |
| 2245 | policy == blink::WebNavigationPolicyNewPopup) { |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 2246 | WebUserGestureIndicator::consumeUserGesture(); |
| 2247 | } |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 2248 | |
| 2249 | Send(new ViewHostMsg_OpenURL(routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2250 | } |
| 2251 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2252 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2253 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2254 | void RenderViewImpl::LoadNavigationErrorPage( |
| 2255 | WebFrame* frame, |
| 2256 | const WebURLRequest& failed_request, |
| 2257 | const WebURLError& error, |
| 2258 | const std::string& html, |
| 2259 | bool replace) { |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2260 | std::string alt_html; |
| 2261 | const std::string* error_html; |
| 2262 | |
| 2263 | if (!html.empty()) { |
| 2264 | error_html = &html; |
| 2265 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2266 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 2267 | frame, failed_request, error, renderer_preferences_.accept_languages, |
| 2268 | &alt_html, NULL); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2269 | error_html = &alt_html; |
| 2270 | } |
| 2271 | |
| 2272 | frame->loadHTMLString(*error_html, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2273 | GURL(kUnreachableWebDataURL), |
[email protected] | 21d61e5 | 2011-03-18 19:08:25 | [diff] [blame] | 2274 | error.unreachableURL, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 2275 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2276 | } |
| 2277 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2278 | bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2279 | const string16& message, |
| 2280 | const string16& default_value, |
| 2281 | const GURL& frame_url, |
| 2282 | string16* result) { |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 2283 | // Don't allow further dialogs if we are waiting to swap out, since the |
| 2284 | // PageGroupLoadDeferrer in our stack prevents it. |
| 2285 | if (suppress_dialogs_until_swap_out_) |
| 2286 | return false; |
| 2287 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2288 | bool success = false; |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2289 | string16 result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2290 | if (!result) |
| 2291 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2292 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2293 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
[email protected] | 688e2ee | 2013-09-12 20:48:14 | [diff] [blame] | 2294 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2295 | return success; |
| 2296 | } |
| 2297 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2298 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2299 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 2300 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 2301 | // it is particularly important that we do not call willEnterModalLoop as |
| 2302 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2303 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2304 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2305 | |
| 2306 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 2307 | return Send(message); |
| 2308 | } |
| 2309 | |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 2310 | void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) { |
| 2311 | int id = next_snapshot_id_++; |
| 2312 | pending_snapshots_.insert(std::make_pair(id, callback)); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 2313 | ui::LatencyInfo latency_info; |
| 2314 | latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
| 2315 | GetLatencyComponentId(), |
| 2316 | id); |
| 2317 | if (RenderWidgetCompositor* rwc = compositor()) { |
| 2318 | rwc->SetLatencyInfo(latency_info); |
| 2319 | } else { |
| 2320 | latency_info_.MergeWith(latency_info); |
| 2321 | } |
| 2322 | ScheduleCompositeWithForcedRedraw(); |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, |
| 2326 | const gfx::Size& size, const std::vector<unsigned char>& png) { |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 2327 | |
| 2328 | // Any pending snapshots with a lower ID than the one received are considered |
| 2329 | // to be implicitly complete, and returned the same snapshot data. |
| 2330 | PendingSnapshotMap::iterator it = pending_snapshots_.begin(); |
| 2331 | while(it != pending_snapshots_.end()) { |
| 2332 | if (it->first <= snapshot_id) { |
| 2333 | it->second.Run(size, png); |
| 2334 | pending_snapshots_.erase(it++); |
| 2335 | } else { |
| 2336 | ++it; |
| 2337 | } |
| 2338 | } |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 2339 | } |
| 2340 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2341 | // blink::WebViewClient ------------------------------------------------------ |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2342 | |
[email protected] | 916dfb6 | 2012-03-05 03:39:37 | [diff] [blame] | 2343 | WebView* RenderViewImpl::createView( |
| 2344 | WebFrame* creator, |
| 2345 | const WebURLRequest& request, |
| 2346 | const WebWindowFeatures& features, |
| 2347 | const WebString& frame_name, |
| 2348 | WebNavigationPolicy policy) { |
[email protected] | 147b2bf | 2013-11-05 04:00:04 | [diff] [blame] | 2349 | return createView(creator, request, features, frame_name, policy, |
| 2350 | creator->willSuppressOpenerInNewFrame()); |
| 2351 | } |
| 2352 | |
| 2353 | WebView* RenderViewImpl::createView( |
| 2354 | WebFrame* creator, |
| 2355 | const WebURLRequest& request, |
| 2356 | const WebWindowFeatures& features, |
| 2357 | const WebString& frame_name, |
| 2358 | WebNavigationPolicy policy, |
| 2359 | bool suppress_opener) { |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2360 | ViewHostMsg_CreateWindow_Params params; |
| 2361 | params.opener_id = routing_id_; |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2362 | params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame] | 2363 | if (GetContentClient()->renderer()->AllowPopup()) |
| 2364 | params.user_gesture = true; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2365 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 2366 | params.session_storage_namespace_id = session_storage_namespace_id_; |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 2367 | if (frame_name != "_blank") |
| 2368 | params.frame_name = frame_name; |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 2369 | params.opener_frame_id = creator->identifier(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2370 | params.opener_url = creator->document().url(); |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2371 | params.opener_top_level_frame_url = creator->top()->document().url(); |
[email protected] | 7f48b71 | 2013-01-25 01:48:30 | [diff] [blame] | 2372 | GURL security_url(creator->document().securityOrigin().toString().utf8()); |
| 2373 | if (!security_url.is_valid()) |
| 2374 | security_url = GURL(); |
| 2375 | params.opener_security_origin = security_url; |
[email protected] | 147b2bf | 2013-11-05 04:00:04 | [diff] [blame] | 2376 | params.opener_suppressed = suppress_opener; |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2377 | params.disposition = NavigationPolicyToDisposition(policy); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 2378 | if (!request.isNull()) { |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 2379 | params.target_url = request.url(); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 2380 | params.referrer = GetReferrerFromRequest(creator, request); |
| 2381 | } |
[email protected] | 453c1b2 | 2013-07-23 09:31:48 | [diff] [blame] | 2382 | params.features = features; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2383 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2384 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2385 | int32 main_frame_routing_id = MSG_ROUTING_NONE; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2386 | int32 surface_id = 0; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 2387 | int64 cloned_session_storage_namespace_id; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2388 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 2389 | RenderThread::Get()->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2390 | new ViewHostMsg_CreateWindow(params, |
| 2391 | &routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2392 | &main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2393 | &surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2394 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2395 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2396 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2397 | |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2398 | WebUserGestureIndicator::consumeUserGesture(); |
[email protected] | c5926242 | 2012-11-30 21:20:52 | [diff] [blame] | 2399 | |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 2400 | WebPreferences transferred_preferences = webkit_preferences_; |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 2401 | |
| 2402 | // Unless accelerated compositing has been explicitly disabled from the |
| 2403 | // command line (e.g. via the blacklist or about:flags) re-enable it for |
| 2404 | // new views that get spawned by this view. This gets around the issue that |
| 2405 | // background extension pages disable accelerated compositing via web prefs |
| 2406 | // but can themselves spawn a visible render view which should be allowed |
| 2407 | // use gpu acceleration. |
| 2408 | if (!webkit_preferences_.accelerated_compositing_enabled) { |
| 2409 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 2410 | if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing)) |
| 2411 | transferred_preferences.accelerated_compositing_enabled = true; |
| 2412 | } |
| 2413 | |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 2414 | // The initial hidden state for the RenderViewImpl here has to match what the |
| 2415 | // browser will eventually decide for the given disposition. Since we have to |
| 2416 | // return from this call synchronously, we just have to make our best guess |
| 2417 | // and rely on the browser sending a WasHidden / WasShown message if it |
| 2418 | // disagrees. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2419 | RenderViewImpl* view = RenderViewImpl::Create( |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2420 | routing_id_, |
| 2421 | renderer_preferences_, |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 2422 | transferred_preferences, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2423 | routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2424 | main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2425 | surface_id, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2426 | cloned_session_storage_namespace_id, |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 2427 | string16(), // WebCore will take care of setting the correct name. |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 2428 | true, // is_renderer_created |
| 2429 | false, // swapped_out |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 2430 | params.disposition == NEW_BACKGROUND_TAB, // hidden |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 2431 | 1, // next_page_id |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 2432 | screen_info_, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 2433 | accessibility_mode_, |
| 2434 | allow_partial_swap_); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2435 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2436 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2437 | // Record whether the creator frame is trying to suppress the opener field. |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2438 | view->opener_suppressed_ = params.opener_suppressed; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2439 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2440 | // Copy over the alternate error page URL so we can have alt error pages in |
| 2441 | // the new render view (we don't need the browser to send the URL back down). |
| 2442 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 2443 | |
| 2444 | return view->webview(); |
| 2445 | } |
| 2446 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2447 | WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) { |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 2448 | RenderWidget* widget = |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 2449 | RenderWidget::Create(routing_id_, popup_type, screen_info_); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 2450 | if (screen_metrics_emulator_) { |
| 2451 | widget->SetPopupOriginAdjustmentsForEmulation( |
| 2452 | screen_metrics_emulator_.get()); |
| 2453 | } |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2454 | return widget->webwidget(); |
| 2455 | } |
| 2456 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2457 | WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu( |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2458 | const WebPopupMenuInfo& popup_menu_info, |
| 2459 | WebExternalPopupMenuClient* popup_menu_client) { |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 2460 | // An IPC message is sent to the browser to build and display the actual |
| 2461 | // popup. The user could have time to click a different select by the time |
| 2462 | // the popup is shown. In that case external_popup_menu_ is non NULL. |
| 2463 | // By returning NULL in that case, we instruct WebKit to cancel that new |
| 2464 | // popup. So from the user perspective, only the first one will show, and |
| 2465 | // will have to close the first one before another one can be shown. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 2466 | if (external_popup_menu_) |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 2467 | return NULL; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2468 | external_popup_menu_.reset( |
| 2469 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 2470 | if (screen_metrics_emulator_) { |
| 2471 | SetExternalPopupOriginAdjustmentsForEmulation( |
| 2472 | external_popup_menu_.get(), screen_metrics_emulator_.get()); |
| 2473 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2474 | return external_popup_menu_.get(); |
| 2475 | } |
| 2476 | |
[email protected] | 2336748 | 2013-06-27 21:06:54 | [diff] [blame] | 2477 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() { |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 2478 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 2479 | return new WebStorageNamespaceImpl(session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 2480 | } |
| 2481 | |
[email protected] | fd8eb74 | 2013-08-22 00:42:00 | [diff] [blame] | 2482 | bool RenderViewImpl::shouldReportDetailedMessageForSource( |
| 2483 | const WebString& source) { |
| 2484 | return GetContentClient()->renderer()->ShouldReportDetailedMessageForSource( |
| 2485 | source); |
| 2486 | } |
| 2487 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2488 | void RenderViewImpl::didAddMessageToConsole( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2489 | const WebConsoleMessage& message, const WebString& source_name, |
[email protected] | fd8eb74 | 2013-08-22 00:42:00 | [diff] [blame] | 2490 | unsigned source_line, const WebString& stack_trace) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2491 | logging::LogSeverity log_severity = logging::LOG_VERBOSE; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 2492 | switch (message.level) { |
[email protected] | 80ac894 | 2013-01-30 22:53:22 | [diff] [blame] | 2493 | case WebConsoleMessage::LevelDebug: |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2494 | log_severity = logging::LOG_VERBOSE; |
| 2495 | break; |
| 2496 | case WebConsoleMessage::LevelLog: |
[email protected] | 69c84d15 | 2013-10-25 18:53:09 | [diff] [blame] | 2497 | case WebConsoleMessage::LevelInfo: |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2498 | log_severity = logging::LOG_INFO; |
| 2499 | break; |
| 2500 | case WebConsoleMessage::LevelWarning: |
| 2501 | log_severity = logging::LOG_WARNING; |
| 2502 | break; |
| 2503 | case WebConsoleMessage::LevelError: |
| 2504 | log_severity = logging::LOG_ERROR; |
| 2505 | break; |
| 2506 | default: |
| 2507 | NOTREACHED(); |
| 2508 | } |
| 2509 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 2510 | if (shouldReportDetailedMessageForSource(source_name)) { |
| 2511 | FOR_EACH_OBSERVER( |
| 2512 | RenderViewObserver, |
| 2513 | observers_, |
| 2514 | DetailedConsoleMessageAdded(message.text, |
| 2515 | source_name, |
| 2516 | stack_trace, |
| 2517 | source_line, |
| 2518 | static_cast<int32>(log_severity))); |
| 2519 | } |
| 2520 | |
[email protected] | 07fb8d5 | 2013-08-07 17:03:51 | [diff] [blame] | 2521 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
| 2522 | static_cast<int32>(log_severity), |
| 2523 | message.text, |
| 2524 | static_cast<int32>(source_line), |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 2525 | source_name)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2526 | } |
| 2527 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2528 | void RenderViewImpl::printPage(WebFrame* frame) { |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 2529 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2530 | PrintPage(frame, handling_input_event_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2531 | } |
| 2532 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2533 | blink::WebNotificationPresenter* RenderViewImpl::notificationPresenter() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2534 | return notification_provider_; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 2535 | } |
| 2536 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2537 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 2538 | const WebString& path, |
| 2539 | WebFileChooserCompletion* chooser_completion) { |
| 2540 | int id = enumeration_completion_id_++; |
| 2541 | enumeration_completions_[id] = chooser_completion; |
| 2542 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 2543 | routing_id_, |
| 2544 | id, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 2545 | base::FilePath::FromUTF16Unsafe(path))); |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 2546 | } |
| 2547 | |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 2548 | void RenderViewImpl::initializeHelperPluginWebFrame( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2549 | blink::WebHelperPlugin* plugin) { |
[email protected] | 2f61bdd | 2013-07-02 18:38:47 | [diff] [blame] | 2550 | plugin->initializeFrame(main_render_frame_.get()); |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 2551 | } |
| 2552 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2553 | void RenderViewImpl::didStartLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2554 | if (is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 2555 | DVLOG(1) << "didStartLoading called while loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2556 | return; |
| 2557 | } |
| 2558 | |
| 2559 | is_loading_ = true; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2560 | |
| 2561 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 2562 | |
| 2563 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2564 | } |
| 2565 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2566 | void RenderViewImpl::didStopLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2567 | if (!is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 2568 | DVLOG(1) << "DidStopLoading called while not loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2569 | return; |
| 2570 | } |
| 2571 | |
| 2572 | is_loading_ = false; |
| 2573 | |
| 2574 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 2575 | // when done loading. This currently isn't an issue as the favicon is only |
| 2576 | // displayed when done loading. Ideally we would send notification when |
| 2577 | // finished parsing the head, but webkit doesn't support that yet. |
| 2578 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2579 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 2580 | |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2581 | if (load_progress_tracker_ != NULL) |
| 2582 | load_progress_tracker_->DidStopLoading(); |
| 2583 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 2584 | DidStopLoadingIcons(); |
| 2585 | |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 2586 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2587 | } |
| 2588 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2589 | void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, |
| 2590 | double load_progress) { |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2591 | if (load_progress_tracker_ != NULL) |
| 2592 | load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); |
| 2593 | } |
| 2594 | |
[email protected] | 550b0c9 | 2013-02-04 05:09:15 | [diff] [blame] | 2595 | void RenderViewImpl::didCancelCompositionOnSelectionChange() { |
| 2596 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 2597 | } |
| 2598 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2599 | void RenderViewImpl::didChangeSelection(bool is_empty_selection) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 2600 | if (!handling_input_event_ && !handling_select_range_) |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 2601 | return; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 2602 | |
[email protected] | fca5202 | 2012-04-03 17:00:50 | [diff] [blame] | 2603 | if (is_empty_selection) |
| 2604 | selection_text_.clear(); |
| 2605 | |
[email protected] | 087edc7 | 2013-11-07 01:00:35 | [diff] [blame] | 2606 | // UpdateTextInputType should be called before SyncSelectionIfRequired. |
| 2607 | // UpdateTextInputType may send TextInputTypeChanged to notify the focus |
| 2608 | // was changed, and SyncSelectionIfRequired may send SelectionChanged |
| 2609 | // to notify the selection was changed. Focus change should be notified |
| 2610 | // before selection change. |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2611 | UpdateTextInputType(); |
[email protected] | 087edc7 | 2013-11-07 01:00:35 | [diff] [blame] | 2612 | SyncSelectionIfRequired(); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2613 | #if defined(OS_ANDROID) |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 2614 | UpdateTextInputState(false, true); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2615 | #endif |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2616 | } |
| 2617 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2618 | void RenderViewImpl::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 2619 | const std::string& name = UTF16ToUTF8(command_name); |
| 2620 | if (StartsWithASCII(name, "Move", true) || |
| 2621 | StartsWithASCII(name, "Insert", true) || |
| 2622 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2623 | return; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2624 | RenderThreadImpl::current()->RecordUserMetrics(name); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2625 | } |
| 2626 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2627 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2628 | if (edit_commands_.empty()) |
| 2629 | return false; |
| 2630 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2631 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2632 | if (!frame) |
| 2633 | return false; |
| 2634 | |
| 2635 | EditCommands::iterator it = edit_commands_.begin(); |
| 2636 | EditCommands::iterator end = edit_commands_.end(); |
| 2637 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2638 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2639 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 2640 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 2641 | // key (but it's the exception). Once one edit command is not executed, it |
| 2642 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2643 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 2644 | WebString::fromUTF8(it->value), |
| 2645 | GetFocusedNode())) |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2646 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2647 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2648 | } |
| 2649 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2650 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2651 | } |
| 2652 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2653 | blink::WebColorChooser* RenderViewImpl::createColorChooser( |
| 2654 | blink::WebColorChooserClient* client, |
| 2655 | const blink::WebColor& initial_color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2656 | RendererWebColorChooserImpl* color_chooser = |
| 2657 | new RendererWebColorChooserImpl(this, client); |
| 2658 | color_chooser->Open(static_cast<SkColor>(initial_color)); |
| 2659 | return color_chooser; |
| 2660 | } |
| 2661 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2662 | bool RenderViewImpl::runFileChooser( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2663 | const blink::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2664 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 2665 | // Do not open the file dialog in a hidden RenderView. |
| 2666 | if (is_hidden()) |
| 2667 | return false; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2668 | FileChooserParams ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2669 | if (params.directory) |
[email protected] | 6bedbef | 2013-07-31 06:33:49 | [diff] [blame] | 2670 | ipc_params.mode = FileChooserParams::UploadFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2671 | else if (params.multiSelect) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2672 | ipc_params.mode = FileChooserParams::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame] | 2673 | else if (params.saveAs) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2674 | ipc_params.mode = FileChooserParams::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2675 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2676 | ipc_params.mode = FileChooserParams::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2677 | ipc_params.title = params.title; |
| 2678 | ipc_params.default_file_name = |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 2679 | base::FilePath::FromUTF16Unsafe(params.initialValue); |
[email protected] | f9a4c41a | 2012-05-30 00:05:32 | [diff] [blame] | 2680 | ipc_params.accept_types.reserve(params.acceptTypes.size()); |
| 2681 | for (size_t i = 0; i < params.acceptTypes.size(); ++i) |
| 2682 | ipc_params.accept_types.push_back(params.acceptTypes[i]); |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 2683 | #if defined(OS_ANDROID) |
[email protected] | b7b4beb | 2013-07-09 14:06:50 | [diff] [blame] | 2684 | ipc_params.capture = params.useMediaCapture; |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 2685 | #endif |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2686 | |
| 2687 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2688 | } |
| 2689 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2690 | void RenderViewImpl::runModalAlertDialog(WebFrame* frame, |
| 2691 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2692 | RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2693 | message, |
| 2694 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2695 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2696 | NULL); |
| 2697 | } |
| 2698 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2699 | bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame, |
| 2700 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2701 | return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2702 | message, |
| 2703 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2704 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2705 | NULL); |
| 2706 | } |
| 2707 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2708 | bool RenderViewImpl::runModalPromptDialog(WebFrame* frame, |
| 2709 | const WebString& message, |
| 2710 | const WebString& default_value, |
| 2711 | WebString* actual_value) { |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2712 | string16 result; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2713 | bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2714 | message, |
| 2715 | default_value, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2716 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2717 | &result); |
| 2718 | if (ok) |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2719 | actual_value->assign(result); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2720 | return ok; |
| 2721 | } |
| 2722 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2723 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2724 | WebFrame* frame, const WebString& message) { |
[email protected] | ab533826b | 2013-05-10 23:54:56 | [diff] [blame] | 2725 | bool is_reload = false; |
| 2726 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2727 | if (ds) |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2728 | is_reload = (ds->navigationType() == blink::WebNavigationTypeReload); |
[email protected] | ab533826b | 2013-05-10 23:54:56 | [diff] [blame] | 2729 | return runModalBeforeUnloadDialog(frame, is_reload, message); |
| 2730 | } |
| 2731 | |
| 2732 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
| 2733 | WebFrame* frame, bool is_reload, const WebString& message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2734 | // If we are swapping out, we have already run the beforeunload handler. |
| 2735 | // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 2736 | // at all, to avoid running it twice. |
| 2737 | if (is_swapped_out_) |
| 2738 | return true; |
| 2739 | |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 2740 | // Don't allow further dialogs if we are waiting to swap out, since the |
| 2741 | // PageGroupLoadDeferrer in our stack prevents it. |
| 2742 | if (suppress_dialogs_until_swap_out_) |
| 2743 | return false; |
| 2744 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2745 | bool success = false; |
| 2746 | // This is an ignored return value, but is included so we can accept the same |
| 2747 | // response as RunJavaScriptMessage. |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2748 | string16 ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2749 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2750 | routing_id_, frame->document().url(), message, is_reload, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2751 | &success, &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2752 | return success; |
| 2753 | } |
| 2754 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2755 | void RenderViewImpl::showContextMenu( |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2756 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | 3175fea | 2013-05-16 10:57:48 | [diff] [blame] | 2757 | ContextMenuParams params = ContextMenuParamsBuilder::Build(data); |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 2758 | params.source_type = context_menu_source_type_; |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 2759 | if (context_menu_source_type_ == ui::MENU_SOURCE_TOUCH_EDIT_MENU) { |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 2760 | params.x = touch_editing_context_menu_location_.x(); |
| 2761 | params.y = touch_editing_context_menu_location_.y(); |
| 2762 | } |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 2763 | OnShowHostContextMenu(¶ms); |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2764 | |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2765 | // Plugins, e.g. PDF, don't currently update the render view when their |
| 2766 | // selected text changes, but the context menu params do contain the updated |
| 2767 | // selection. If that's the case, update the render view's state just prior |
| 2768 | // to showing the context menu. |
| 2769 | // TODO(asvitkine): http://crbug.com/152432 |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 2770 | if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_, |
| 2771 | selection_text_offset_, |
| 2772 | selection_range_, |
| 2773 | params)) { |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2774 | selection_text_ = params.selection_text; |
| 2775 | // TODO(asvitkine): Text offset and range is not available in this case. |
| 2776 | selection_text_offset_ = 0; |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2777 | selection_range_ = gfx::Range(0, selection_text_.length()); |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2778 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 2779 | selection_text_, |
| 2780 | selection_text_offset_, |
| 2781 | selection_range_)); |
| 2782 | } |
| 2783 | |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2784 | // frame is NULL if invoked by BlockedPlugin. |
| 2785 | if (frame) |
| 2786 | params.frame_id = frame->identifier(); |
| 2787 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2788 | // Serializing a GURL longer than kMaxURLChars will fail, so don't do |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2789 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2790 | // in the context menu. |
| 2791 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2792 | // data encoded images. We should have a way to save them. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2793 | if (params.src_url.spec().size() > kMaxURLChars) |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2794 | params.src_url = GURL(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 2795 | context_menu_node_ = data.node; |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2796 | |
| 2797 | #if defined(OS_ANDROID) |
| 2798 | gfx::Rect start_rect; |
| 2799 | gfx::Rect end_rect; |
| 2800 | GetSelectionBounds(&start_rect, &end_rect); |
[email protected] | 326a234 | 2013-02-15 15:47:51 | [diff] [blame] | 2801 | params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom()); |
| 2802 | params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom()); |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2803 | #endif |
| 2804 | |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2805 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 2806 | |
| 2807 | FOR_EACH_OBSERVER( |
| 2808 | RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2809 | } |
| 2810 | |
[email protected] | 8b67f78f | 2013-08-13 12:04:30 | [diff] [blame] | 2811 | void RenderViewImpl::clearContextMenu() { |
| 2812 | context_menu_node_.reset(); |
| 2813 | } |
| 2814 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2815 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2816 | } |
| 2817 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2818 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 2819 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2820 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2821 | if (latest_url == target_url_) |
| 2822 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2823 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2824 | // Tell the browser to display a destination link. |
| 2825 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2826 | target_url_status_ == TARGET_PENDING) { |
| 2827 | // If we have a request in-flight, save the URL to be sent when we |
| 2828 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2829 | // any existing pending sends. |
| 2830 | pending_target_url_ = latest_url; |
| 2831 | target_url_status_ = TARGET_PENDING; |
| 2832 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2833 | // URLs larger than |kMaxURLChars| cannot be sent through IPC - |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2834 | // see |ParamTraits<GURL>|. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2835 | if (latest_url.possibly_invalid_spec().size() > kMaxURLChars) |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2836 | latest_url = GURL(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2837 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2838 | target_url_ = latest_url; |
| 2839 | target_url_status_ = TARGET_INFLIGHT; |
| 2840 | } |
| 2841 | } |
| 2842 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 2843 | gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect( |
| 2844 | const gfx::RectF& rect) const { |
| 2845 | gfx::RectF window_rect = rect; |
| 2846 | window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor()); |
| 2847 | return window_rect; |
| 2848 | } |
| 2849 | |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 2850 | int64 RenderViewImpl::GetLatencyComponentId() { |
| 2851 | // Note: this must match the logic in RenderWidgetHostImpl. |
| 2852 | return GetRoutingID() | (static_cast<int64>( |
| 2853 | RenderThreadImpl::current()->renderer_process_id()) << 32); |
| 2854 | } |
| 2855 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2856 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
[email protected] | a183fb8 | 2012-12-14 04:46:22 | [diff] [blame] | 2857 | // No need to update state if no page has committed yet. |
| 2858 | if (page_id_ == -1) |
| 2859 | return; |
| 2860 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2861 | int delay; |
| 2862 | if (send_content_state_immediately_) |
| 2863 | delay = 0; |
| 2864 | else if (is_hidden()) |
| 2865 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2866 | else |
| 2867 | delay = kDelaySecondsForContentStateSync; |
| 2868 | |
| 2869 | if (nav_state_sync_timer_.IsRunning()) { |
| 2870 | // The timer is already running. If the delay of the timer maches the amount |
| 2871 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2872 | // gets started with the right delay. |
| 2873 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2874 | return; |
| 2875 | nav_state_sync_timer_.Stop(); |
| 2876 | } |
| 2877 | |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 2878 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2879 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2880 | } |
| 2881 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2882 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2883 | mouse_over_url_ = GURL(url); |
| 2884 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2885 | } |
| 2886 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2887 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2888 | focus_url_ = GURL(url); |
| 2889 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2890 | } |
| 2891 | |
[email protected] | 0407e42 | 2012-05-18 19:51:25 | [diff] [blame] | 2892 | void RenderViewImpl::startDragging(WebFrame* frame, |
| 2893 | const WebDragData& data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2894 | WebDragOperationsMask mask, |
| 2895 | const WebImage& image, |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2896 | const WebPoint& webImageOffset) { |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 2897 | DropData drop_data(DropDataBuilder::Build(data)); |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2898 | drop_data.referrer_policy = frame->document().referrerPolicy(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2899 | gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2900 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2901 | drop_data, |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2902 | mask, |
[email protected] | 97612707 | 2012-05-10 20:08:11 | [diff] [blame] | 2903 | image.getSkBitmap(), |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 2904 | imageOffset, |
| 2905 | possible_drag_event_info_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2906 | } |
| 2907 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2908 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2909 | return renderer_preferences_.can_accept_load_drops; |
| 2910 | } |
| 2911 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2912 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2913 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2914 | } |
| 2915 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2916 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2917 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2918 | } |
| 2919 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2920 | void RenderViewImpl::focusedNodeChanged(const WebNode& node) { |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 2921 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 2922 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 2923 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node)); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2924 | } |
| 2925 | |
[email protected] | 572a6ca | 2012-10-11 19:38:01 | [diff] [blame] | 2926 | void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
| 2927 | Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
| 2928 | } |
| 2929 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 2930 | void RenderViewImpl::didUpdateLayout() { |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 2931 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout()); |
| 2932 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 2933 | // We don't always want to set up a timer, only if we've been put in that |
| 2934 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 2935 | // message. |
| 2936 | if (!send_preferred_size_changes_ || !webview()) |
| 2937 | return; |
| 2938 | |
| 2939 | if (check_preferred_size_timer_.IsRunning()) |
| 2940 | return; |
| 2941 | check_preferred_size_timer_.Start(FROM_HERE, |
| 2942 | TimeDelta::FromMilliseconds(0), this, |
| 2943 | &RenderViewImpl::CheckPreferredSize); |
| 2944 | } |
| 2945 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2946 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2947 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2948 | } |
| 2949 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2950 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2951 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2952 | } |
| 2953 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2954 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2955 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2956 | } |
| 2957 | |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 2958 | void RenderViewImpl::postAccessibilityEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2959 | const WebAXObject& obj, blink::WebAXEvent event) { |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2960 | if (renderer_accessibility_) { |
[email protected] | 10760e4a | 2013-09-04 23:32:20 | [diff] [blame] | 2961 | renderer_accessibility_->HandleWebAccessibilityEvent(obj, event); |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2962 | } |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2963 | } |
| 2964 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2965 | void RenderViewImpl::didUpdateInspectorSetting(const WebString& key, |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2966 | const WebString& value) { |
| 2967 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2968 | key.utf8(), |
| 2969 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2970 | } |
| 2971 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 2972 | // blink::WebWidgetClient ---------------------------------------------------- |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2973 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2974 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2975 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2976 | // we won't have to test for user gesture anymore and we can |
| 2977 | // move that code back to render_widget.cc |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2978 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 2979 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 2980 | Send(new ViewHostMsg_Focus(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2981 | } |
| 2982 | } |
| 2983 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2984 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2985 | // TODO(jcivelli): see TODO above in didFocus(). |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2986 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 2987 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 2988 | Send(new ViewHostMsg_Blur(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2989 | } |
| 2990 | } |
| 2991 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2992 | // 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] | 2993 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2994 | // point to dispatch the ShowView message. |
| 2995 | // |
| 2996 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 2997 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2998 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2999 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 3000 | if (did_show_) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 3001 | // When supports_multiple_windows is disabled, popups are reusing |
| 3002 | // the same view. In some scenarios, this makes WebKit to call show() twice. |
[email protected] | c9edabd | 2013-05-23 13:56:24 | [diff] [blame] | 3003 | if (webkit_preferences_.supports_multiple_windows) |
| 3004 | NOTREACHED() << "received extraneous Show call"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3005 | return; |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 3006 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3007 | did_show_ = true; |
| 3008 | |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 3009 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 3010 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 3011 | // Force new windows to a popup if they were not opened with a user gesture. |
| 3012 | if (!opened_by_user_gesture_) { |
| 3013 | // We exempt background tabs for compat with older versions of Chrome. |
| 3014 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 3015 | // we probably don't need this check. |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3016 | if (policy != blink::WebNavigationPolicyNewBackgroundTab) |
| 3017 | policy = blink::WebNavigationPolicyNewPopup; |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 3018 | } |
| 3019 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3020 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 3021 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 3022 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 3023 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 3024 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 3025 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 3026 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3027 | } |
| 3028 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3029 | void RenderViewImpl::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3030 | DCHECK(did_show_) << "should already have shown the view"; |
| 3031 | |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 3032 | // Don't allow further dialogs if we are waiting to swap out, since the |
| 3033 | // PageGroupLoadDeferrer in our stack prevents it. |
| 3034 | if (suppress_dialogs_until_swap_out_) |
| 3035 | return; |
| 3036 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 3037 | // We must keep WebKit's shared timer running in this case in order to allow |
| 3038 | // showModalDialog to function properly. |
| 3039 | // |
| 3040 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 3041 | // timers so that we do not need to manage the shared timer in such a heavy |
| 3042 | // handed manner. |
| 3043 | // |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 3044 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 3045 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 3046 | |
[email protected] | 08a1c810 | 2012-05-11 23:14:26 | [diff] [blame] | 3047 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal( |
| 3048 | routing_id_, opener_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3049 | } |
| 3050 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 3051 | bool RenderViewImpl::enterFullScreen() { |
| 3052 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 3053 | return true; |
| 3054 | } |
| 3055 | |
| 3056 | void RenderViewImpl::exitFullScreen() { |
| 3057 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 3058 | } |
| 3059 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 3060 | bool RenderViewImpl::requestPointerLock() { |
| 3061 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 3062 | } |
| 3063 | |
| 3064 | void RenderViewImpl::requestPointerUnlock() { |
| 3065 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 3066 | } |
| 3067 | |
| 3068 | bool RenderViewImpl::isPointerLocked() { |
| 3069 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 3070 | webwidget_mouse_lock_target_.get()); |
| 3071 | } |
| 3072 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 3073 | void RenderViewImpl::didActivateCompositor(int input_handler_identifier) { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 3074 | #if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003 |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 3075 | InputHandlerManager* input_handler_manager = |
| 3076 | RenderThreadImpl::current()->input_handler_manager(); |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 3077 | if (input_handler_manager) { |
| 3078 | input_handler_manager->AddInputHandler( |
| 3079 | routing_id_, |
| 3080 | compositor_->GetInputHandler(), |
| 3081 | AsWeakPtr()); |
| 3082 | } |
[email protected] | 70cff2750 | 2013-01-17 09:16:49 | [diff] [blame] | 3083 | #endif |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 3084 | |
| 3085 | RenderWidget::didActivateCompositor(input_handler_identifier); |
| 3086 | } |
| 3087 | |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 3088 | void RenderViewImpl::didHandleGestureEvent( |
| 3089 | const WebGestureEvent& event, |
| 3090 | bool event_cancelled) { |
| 3091 | RenderWidget::didHandleGestureEvent(event, event_cancelled); |
| 3092 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3093 | DidHandleGestureEvent(event)); |
| 3094 | } |
| 3095 | |
[email protected] | 6e89eb7 | 2013-07-23 13:28:22 | [diff] [blame] | 3096 | void RenderViewImpl::initializeLayerTreeView() { |
| 3097 | RenderWidget::initializeLayerTreeView(); |
| 3098 | RenderWidgetCompositor* rwc = compositor(); |
| 3099 | if (!rwc || !webview() || !webview()->devToolsAgent()) |
| 3100 | return; |
| 3101 | webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId()); |
| 3102 | } |
| 3103 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3104 | // blink::WebFrameClient ----------------------------------------------------- |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3105 | |
[email protected] | 97b150db | 2012-08-16 18:26:02 | [diff] [blame] | 3106 | WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3107 | WebFrame* frame, const blink::WebURL& url, WebMediaPlayerClient* client) { |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 3108 | FOR_EACH_OBSERVER( |
| 3109 | RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client)); |
[email protected] | 7198402c | 2011-04-11 12:15:17 | [diff] [blame] | 3110 | |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 3111 | WebMediaPlayer* player = CreateWebMediaPlayerForMediaStream(frame, url, |
| 3112 | client); |
| 3113 | if (player) |
| 3114 | return player; |
[email protected] | d05e216 | 2012-11-16 22:21:46 | [diff] [blame] | 3115 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 3116 | #if defined(OS_ANDROID) |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 3117 | return CreateAndroidWebMediaPlayer(frame, url, client); |
| 3118 | #else |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 3119 | scoped_refptr<media::AudioRendererSink> sink; |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 3120 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAudio)) { |
[email protected] | 17c4ce62f | 2013-05-03 19:54:02 | [diff] [blame] | 3121 | sink = RenderThreadImpl::current()->GetAudioRendererMixerManager()-> |
| 3122 | CreateInput(routing_id_); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 3123 | DVLOG(1) << "Using AudioRendererMixerManager-provided sink: " << sink.get(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3124 | } |
| 3125 | |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 3126 | WebMediaPlayerParams params( |
[email protected] | c1330c8 | 2013-06-06 02:23:25 | [diff] [blame] | 3127 | RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(), |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 3128 | base::Bind(&ContentRendererClient::DeferMediaLoad, |
| 3129 | base::Unretained(GetContentClient()->renderer()), |
| 3130 | static_cast<RenderView*>(this)), |
| 3131 | sink, |
[email protected] | c50edb96 | 2013-10-19 18:05:07 | [diff] [blame] | 3132 | RenderThreadImpl::current()->GetGpuFactories(), |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 3133 | new RenderMediaLog()); |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 3134 | return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params); |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 3135 | #endif // defined(OS_ANDROID) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3136 | } |
| 3137 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3138 | WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { |
[email protected] | 8ff18107 | 2010-11-29 17:09:38 | [diff] [blame] | 3139 | return &cookie_jar_; |
| 3140 | } |
| 3141 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 3142 | void RenderViewImpl::didAccessInitialDocument(WebFrame* frame) { |
| 3143 | // Notify the browser process that it is no longer safe to show the pending |
| 3144 | // URL of the main frame, since a URL spoof is now possible. |
| 3145 | if (!frame->parent() && page_id_ == -1) |
| 3146 | Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_)); |
| 3147 | } |
| 3148 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3149 | void RenderViewImpl::didDisownOpener(blink::WebFrame* frame) { |
[email protected] | 29ece2e | 2013-04-03 04:53:52 | [diff] [blame] | 3150 | // We only need to notify the browser if the active, top-level frame clears |
| 3151 | // its opener. We can ignore cases where a swapped out frame clears its |
| 3152 | // opener after hearing about it from the browser, and the browser does not |
| 3153 | // (yet) care about subframe openers. |
| 3154 | if (is_swapped_out_ || frame->parent()) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 3155 | return; |
| 3156 | |
| 3157 | // Notify WebContents and all its swapped out RenderViews. |
| 3158 | Send(new ViewHostMsg_DidDisownOpener(routing_id_)); |
| 3159 | } |
| 3160 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3161 | void RenderViewImpl::frameDetached(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3162 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 3163 | } |
| 3164 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3165 | void RenderViewImpl::willClose(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3166 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3167 | } |
| 3168 | |
[email protected] | f5b6dd112 | 2013-10-04 02:42:50 | [diff] [blame] | 3169 | void RenderViewImpl::didMatchCSS( |
| 3170 | WebFrame* frame, |
| 3171 | const WebVector<WebString>& newly_matching_selectors, |
| 3172 | const WebVector<WebString>& stopped_matching_selectors) { |
| 3173 | FOR_EACH_OBSERVER( |
| 3174 | RenderViewObserver, observers_, |
| 3175 | DidMatchCSS(frame, newly_matching_selectors, stopped_matching_selectors)); |
| 3176 | } |
| 3177 | |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 3178 | void RenderViewImpl::Repaint(const gfx::Size& size) { |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 3179 | OnRepaint(size); |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 3180 | } |
| 3181 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 3182 | void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name, |
| 3183 | const std::string& value) { |
| 3184 | EditCommands edit_commands; |
| 3185 | edit_commands.push_back(EditCommand(name, value)); |
| 3186 | OnSetEditCommandsForNextKeyEvent(edit_commands); |
| 3187 | } |
| 3188 | |
| 3189 | void RenderViewImpl::ClearEditCommands() { |
| 3190 | edit_commands_.clear(); |
| 3191 | } |
| 3192 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3193 | SSLStatus RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame* frame) const { |
[email protected] | 83c0abca | 2013-07-23 20:09:42 | [diff] [blame] | 3194 | std::string security_info; |
| 3195 | if (frame && frame->dataSource()) |
| 3196 | security_info = frame->dataSource()->response().securityInfo(); |
| 3197 | |
| 3198 | SSLStatus ssl_status; |
| 3199 | DeserializeSecurityInfo(security_info, |
| 3200 | &ssl_status.cert_id, |
| 3201 | &ssl_status.cert_status, |
| 3202 | &ssl_status.security_bits, |
| 3203 | &ssl_status.connection_status); |
| 3204 | return ssl_status; |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 3205 | } |
| 3206 | |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 3207 | const std::string& RenderViewImpl::GetAcceptLanguages() const { |
| 3208 | return renderer_preferences_.accept_languages; |
| 3209 | } |
| 3210 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3211 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3212 | WebFrame* frame, WebDataSource::ExtraData* extraData, |
| 3213 | const WebURLRequest& request, WebNavigationType type, |
| 3214 | WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 099df81cf | 2012-11-14 17:44:04 | [diff] [blame] | 3215 | if (request.url() != GURL(kSwappedOutURL) && |
| 3216 | GetContentClient()->renderer()->HandleNavigation(frame, request, type, |
| 3217 | default_policy, |
| 3218 | is_redirect)) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3219 | return blink::WebNavigationPolicyIgnore; |
[email protected] | 099df81cf | 2012-11-14 17:44:04 | [diff] [blame] | 3220 | } |
| 3221 | |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 3222 | Referrer referrer(GetReferrerFromRequest(frame, request)); |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3223 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3224 | if (is_swapped_out_) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3225 | if (request.url() != GURL(kSwappedOutURL)) { |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3226 | // Targeted links may try to navigate a swapped out frame. Allow the |
| 3227 | // browser process to navigate the tab instead. Note that it is also |
| 3228 | // possible for non-targeted navigations (from this view) to arrive |
| 3229 | // here just after we are swapped out. It's ok to send them to the |
| 3230 | // browser, as long as they're for the top level frame. |
| 3231 | // TODO(creis): Ensure this supports targeted form submissions when |
| 3232 | // fixing http://crbug.com/101395. |
| 3233 | if (frame->parent() == NULL) { |
| 3234 | OpenURL(frame, request.url(), referrer, default_policy); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3235 | return blink::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | // We should otherwise ignore in-process iframe navigations, if they |
| 3239 | // arrive just after we are swapped out. |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3240 | return blink::WebNavigationPolicyIgnore; |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 3241 | } |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 3242 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3243 | // Allow kSwappedOutURL to complete. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3244 | return default_policy; |
| 3245 | } |
| 3246 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3247 | // Webkit is asking whether to navigate to a new URL. |
| 3248 | // This is fine normally, except if we're showing UI from one security |
| 3249 | // context and they're trying to navigate to a different context. |
| 3250 | const GURL& url = request.url(); |
| 3251 | |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 3252 | // A content initiated navigation may have originated from a link-click, |
| 3253 | // script, drag-n-drop operation, etc. |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3254 | bool is_content_initiated = static_cast<DocumentState*>(extraData)-> |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3255 | navigation_state()->is_content_initiated(); |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 3256 | |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3257 | // Experimental: |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 3258 | // If --enable-strict-site-isolation or --site-per-process is enabled, send |
| 3259 | // all top-level navigations to the browser to let it swap processes when |
| 3260 | // crossing site boundaries. This is currently expected to break some script |
| 3261 | // calls and navigations, such as form submissions. |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3262 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 3263 | bool force_swap_due_to_flag = |
| 3264 | command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
| 3265 | command_line.HasSwitch(switches::kSitePerProcess); |
| 3266 | if (force_swap_due_to_flag && |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3267 | !frame->parent() && (is_content_initiated || is_redirect)) { |
| 3268 | WebString origin_str = frame->document().securityOrigin().toString(); |
| 3269 | GURL frame_url(origin_str.utf8().data()); |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 3270 | // TODO(cevans): revisit whether this site check is still necessary once |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3271 | // crbug.com/101395 is fixed. |
[email protected] | ed32c21 | 2013-05-14 20:49:29 | [diff] [blame] | 3272 | bool same_domain_or_host = |
| 3273 | net::registry_controlled_domains::SameDomainOrHost( |
| 3274 | frame_url, |
| 3275 | url, |
| 3276 | net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 3277 | if (!same_domain_or_host || frame_url.scheme() != url.scheme()) { |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3278 | OpenURL(frame, url, referrer, default_policy); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3279 | return blink::WebNavigationPolicyIgnore; |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3280 | } |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3281 | } |
| 3282 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3283 | // If the browser is interested, then give it a chance to look at the request. |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 3284 | if (is_content_initiated) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3285 | bool is_form_post = ((type == blink::WebNavigationTypeFormSubmitted) || |
| 3286 | (type == blink::WebNavigationTypeFormResubmitted)) && |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 3287 | EqualsASCII(request.httpMethod(), "POST"); |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3288 | bool browser_handles_request = |
| 3289 | renderer_preferences_.browser_handles_non_local_top_level_requests && |
[email protected] | 140a588 | 2013-07-23 19:30:33 | [diff] [blame] | 3290 | IsNonLocalTopLevelNavigation(url, frame, type, is_form_post); |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3291 | if (!browser_handles_request) { |
| 3292 | browser_handles_request = |
| 3293 | renderer_preferences_.browser_handles_all_top_level_requests && |
| 3294 | IsTopLevelNavigation(frame); |
| 3295 | } |
| 3296 | |
| 3297 | if (browser_handles_request) { |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 3298 | // Reset these counters as the RenderView could be reused for the next |
| 3299 | // navigation. |
| 3300 | page_id_ = -1; |
| 3301 | last_page_id_sent_to_browser_ = -1; |
| 3302 | OpenURL(frame, url, referrer, default_policy); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3303 | return blink::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 3304 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3305 | } |
| 3306 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3307 | // Use the frame's original request's URL rather than the document's URL for |
| 3308 | // subsequent checks. For a popup, the document's URL may become the opener |
| 3309 | // window's URL if the opener has called document.write(). |
| 3310 | // See http://crbug.com/93517. |
| 3311 | GURL old_url(frame->dataSource()->request().url()); |
| 3312 | |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3313 | // Detect when we're crossing a permission-based boundary (e.g. into or out of |
[email protected] | c39f9bf | 2011-02-12 00:43:55 | [diff] [blame] | 3314 | // an extension or app origin, leaving a WebUI page, etc). We only care about |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3315 | // top-level navigations (not iframes). But we sometimes navigate to |
| 3316 | // about:blank to clear a tab, and we want to still allow that. |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3317 | // |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3318 | // Note: this is known to break POST submissions when crossing process |
| 3319 | // boundaries until http://crbug.com/101395 is fixed. This is better for |
| 3320 | // security than loading a WebUI, extension or app page in the wrong process. |
| 3321 | // POST requests don't work because this mechanism does not preserve form |
| 3322 | // POST data. We will need to send the request's httpBody data up to the |
| 3323 | // browser process, and issue a special POST navigation in WebKit (via |
[email protected] | 8f4da8c | 2011-02-09 19:49:57 | [diff] [blame] | 3324 | // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl |
| 3325 | // for examples of how to send the httpBody data. |
[email protected] | 2762a1b | 2011-12-09 15:25:22 | [diff] [blame] | 3326 | if (!frame->parent() && is_content_initiated && |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3327 | !url.SchemeIs(chrome::kAboutScheme)) { |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3328 | bool send_referrer = false; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3329 | |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 3330 | // All navigations to or from WebUI URLs or within WebUI-enabled |
| 3331 | // RenderProcesses must be handled by the browser process so that the |
| 3332 | // correct bindings and data sources can be registered. |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3333 | // Similarly, navigations to view-source URLs or within ViewSource mode |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 3334 | // must be handled by the browser process (except for reloads - those are |
| 3335 | // safe to leave within the renderer). |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3336 | // Lastly, access to file:// URLs from non-file:// URL pages must be |
| 3337 | // handled by the browser so that ordinary renderer processes don't get |
| 3338 | // blessed with file permissions. |
| 3339 | int cumulative_bindings = RenderProcess::current()->GetEnabledBindings(); |
| 3340 | bool is_initial_navigation = page_id_ == -1; |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 3341 | bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) || |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3342 | (cumulative_bindings & BINDINGS_POLICY_WEB_UI) || |
[email protected] | dbdda540 | 2013-05-30 22:13:48 | [diff] [blame] | 3343 | url.SchemeIs(kViewSourceScheme) || |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 3344 | (frame->isViewSourceModeEnabled() && |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3345 | type != blink::WebNavigationTypeReload); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3346 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3347 | if (!should_fork && url.SchemeIs(chrome::kFileScheme)) { |
| 3348 | // Fork non-file to file opens. Check the opener URL if this is the |
| 3349 | // initial navigation in a newly opened window. |
| 3350 | GURL source_url(old_url); |
| 3351 | if (is_initial_navigation && source_url.is_empty() && frame->opener()) |
| 3352 | source_url = frame->opener()->top()->document().url(); |
| 3353 | DCHECK(!source_url.is_empty()); |
| 3354 | should_fork = !source_url.SchemeIs(chrome::kFileScheme); |
| 3355 | } |
| 3356 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3357 | if (!should_fork) { |
| 3358 | // Give the embedder a chance. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 3359 | should_fork = GetContentClient()->renderer()->ShouldFork( |
| 3360 | frame, url, request.httpMethod().utf8(), is_initial_navigation, |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 3361 | is_redirect, &send_referrer); |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | if (should_fork) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3365 | OpenURL( |
| 3366 | frame, url, send_referrer ? referrer : Referrer(), default_policy); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3367 | return blink::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3368 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 3372 | // its own process. This is done by sites like Gmail that try to open links |
| 3373 | // in new windows without script connections back to the original page. We |
| 3374 | // treat such cases as browser navigations (in which we will create a new |
| 3375 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 3376 | // |
| 3377 | // We use the following heuristic to decide whether to fork a new page in its |
| 3378 | // own process: |
| 3379 | // The parent page must open a new tab to about:blank, set the new tab's |
| 3380 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 3381 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 3382 | // |
| 3383 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 3384 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3385 | bool is_fork = |
| 3386 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 3387 | old_url == GURL(kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3388 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3389 | historyBackListCount() < 1 && |
| 3390 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3391 | // The parent page must have set the child's window.opener to null before |
| 3392 | // redirecting to the desired URL. |
| 3393 | frame->opener() == NULL && |
| 3394 | // Must be a top-level frame. |
| 3395 | frame->parent() == NULL && |
| 3396 | // Must not have issued the request from this page. |
| 3397 | is_content_initiated && |
| 3398 | // Must be targeted at the current tab. |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3399 | default_policy == blink::WebNavigationPolicyCurrentTab && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3400 | // Must be a JavaScript navigation, which appears as "other". |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3401 | type == blink::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 3402 | |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 3403 | if (is_fork) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3404 | // Open the URL via the browser, not via WebKit. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3405 | OpenURL(frame, url, Referrer(), default_policy); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3406 | return blink::WebNavigationPolicyIgnore; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | return default_policy; |
| 3410 | } |
| 3411 | |
[email protected] | f4f40a05 | 2013-04-19 15:28:11 | [diff] [blame] | 3412 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
| 3413 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 89bc54c6 | 2013-04-24 01:51:33 | [diff] [blame] | 3414 | WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3415 | return decidePolicyForNavigation(frame, |
| 3416 | frame->provisionalDataSource()->extraData(), |
[email protected] | 89bc54c6 | 2013-04-24 01:51:33 | [diff] [blame] | 3417 | request, type, default_policy, is_redirect); |
[email protected] | f4f40a05 | 2013-04-19 15:28:11 | [diff] [blame] | 3418 | } |
| 3419 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 3420 | void RenderViewImpl::willSendSubmitEvent(blink::WebFrame* frame, |
| 3421 | const blink::WebFormElement& form) { |
[email protected] | 0660a8c | 2013-08-16 01:09:12 | [diff] [blame] | 3422 | FOR_EACH_OBSERVER( |
| 3423 | RenderViewObserver, observers_, WillSendSubmitEvent(frame, form)); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 3424 | } |
| 3425 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3426 | void RenderViewImpl::willSubmitForm(WebFrame* frame, |
| 3427 | const WebFormElement& form) { |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 3428 | FOR_EACH_OBSERVER( |
| 3429 | RenderViewObserver, observers_, WillSubmitForm(frame, form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3430 | } |
| 3431 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3432 | void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3433 | bool content_initiated = !pending_navigation_params_.get(); |
| 3434 | |
[email protected] | f887290 | 2013-10-30 03:18:57 | [diff] [blame] | 3435 | // Make sure any previous redirect URLs end up in our new data source. |
| 3436 | if (pending_navigation_params_.get()) { |
| 3437 | for (std::vector<GURL>::const_iterator i = |
| 3438 | pending_navigation_params_->redirects.begin(); |
| 3439 | i != pending_navigation_params_->redirects.end(); ++i) { |
| 3440 | ds->appendRedirect(*i); |
| 3441 | } |
| 3442 | } |
| 3443 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3444 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3445 | if (!document_state) { |
| 3446 | document_state = new DocumentState; |
| 3447 | ds->setExtraData(document_state); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3448 | if (!content_initiated) |
| 3449 | PopulateDocumentStateFromPending(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3450 | } |
| 3451 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3452 | // Carry over the user agent override flag, if it exists. |
| 3453 | if (content_initiated && webview() && webview()->mainFrame() && |
| 3454 | webview()->mainFrame()->dataSource()) { |
| 3455 | DocumentState* old_document_state = |
| 3456 | DocumentState::FromDataSource(webview()->mainFrame()->dataSource()); |
| 3457 | if (old_document_state) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3458 | InternalDocumentStateData* internal_data = |
| 3459 | InternalDocumentStateData::FromDocumentState(document_state); |
| 3460 | InternalDocumentStateData* old_internal_data = |
| 3461 | InternalDocumentStateData::FromDocumentState(old_document_state); |
| 3462 | internal_data->set_is_overriding_user_agent( |
| 3463 | old_internal_data->is_overriding_user_agent()); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3464 | } |
| 3465 | } |
| 3466 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3467 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 3468 | // non-null NavigationState. |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3469 | if (content_initiated) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3470 | document_state->set_navigation_state( |
| 3471 | NavigationState::CreateContentInitiated()); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3472 | } else { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3473 | document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 3474 | pending_navigation_params_.reset(); |
| 3475 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3476 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3477 | // DocumentState::referred_by_prefetcher_ is true if we are |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3478 | // navigating from a page that used prefetching using a link on that |
| 3479 | // page. We are early enough in the request process here that we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3480 | // can still see the DocumentState of the previous page and set |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3481 | // this value appropriately. |
| 3482 | // TODO(gavinp): catch the important case of navigation in a new |
| 3483 | // renderer process. |
| 3484 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 3485 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3486 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3487 | const GURL referrer( |
| 3488 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 3489 | if (!referrer.is_empty() && |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3490 | DocumentState::FromDataSource( |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3491 | old_frame->dataSource())->was_prefetcher()) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 3492 | for (; old_frame; old_frame = old_frame->traverseNext(false)) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3493 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 3494 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3495 | document_state->set_was_referred_by_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3496 | break; |
| 3497 | } |
| 3498 | } |
| 3499 | } |
| 3500 | } |
| 3501 | } |
| 3502 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3503 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3504 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3505 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3506 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3507 | document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3508 | break; |
| 3509 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3510 | document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3511 | break; |
| 3512 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3513 | document_state->set_load_type( |
| 3514 | DocumentState::LINK_LOAD_CACHE_STALE_OK); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3515 | break; |
| 3516 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3517 | document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3518 | break; |
| 3519 | } |
| 3520 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3521 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 3522 | FOR_EACH_OBSERVER( |
| 3523 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3524 | } |
| 3525 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3526 | void RenderViewImpl::PopulateDocumentStateFromPending( |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3527 | DocumentState* document_state) { |
| 3528 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3529 | document_state->set_request_time(params.request_time); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3530 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3531 | InternalDocumentStateData* internal_data = |
| 3532 | InternalDocumentStateData::FromDocumentState(document_state); |
| 3533 | |
[email protected] | 44b0581 | 2013-08-19 07:59:35 | [diff] [blame] | 3534 | if (!params.url.SchemeIs(kJavaScriptScheme) && |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3535 | params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { |
| 3536 | // We're doing a load of a page that was restored from the last session. By |
| 3537 | // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which |
| 3538 | // can result in stale data for pages that are set to expire. We explicitly |
| 3539 | // override that by setting the policy here so that as necessary we load |
| 3540 | // from the network. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3541 | internal_data->set_cache_policy_override( |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3542 | WebURLRequest::UseProtocolCachePolicy); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | if (IsReload(params)) |
| 3546 | document_state->set_load_type(DocumentState::RELOAD); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 3547 | else if (params.page_state.IsValid()) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3548 | document_state->set_load_type(DocumentState::HISTORY_LOAD); |
| 3549 | else |
| 3550 | document_state->set_load_type(DocumentState::NORMAL_LOAD); |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3551 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3552 | internal_data->set_referrer_policy(params.referrer.policy); |
| 3553 | internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent); |
| 3554 | internal_data->set_must_reset_scroll_and_scale_state( |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3555 | params.navigation_type == |
| 3556 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 3557 | document_state->set_can_load_local_resources(params.can_load_local_resources); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3558 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3559 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3560 | NavigationState* RenderViewImpl::CreateNavigationStateFromPending() { |
| 3561 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
| 3562 | NavigationState* navigation_state = NULL; |
| 3563 | |
| 3564 | // A navigation resulting from loading a javascript URL should not be treated |
| 3565 | // as a browser initiated event. Instead, we want it to look as if the page |
| 3566 | // initiated any load resulting from JS execution. |
[email protected] | 44b0581 | 2013-08-19 07:59:35 | [diff] [blame] | 3567 | if (!params.url.SchemeIs(kJavaScriptScheme)) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3568 | navigation_state = NavigationState::CreateBrowserInitiated( |
| 3569 | params.page_id, |
| 3570 | params.pending_history_list_offset, |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 3571 | params.should_clear_history_list, |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3572 | params.transition); |
| 3573 | navigation_state->set_transferred_request_child_id( |
| 3574 | params.transferred_request_child_id); |
| 3575 | navigation_state->set_transferred_request_request_id( |
| 3576 | params.transferred_request_request_id); |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 3577 | navigation_state->set_allow_download(params.allow_download); |
[email protected] | f050fde | 2013-03-21 00:40:45 | [diff] [blame] | 3578 | navigation_state->set_extra_headers(params.extra_headers); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3579 | } else { |
| 3580 | navigation_state = NavigationState::CreateContentInitiated(); |
| 3581 | } |
| 3582 | return navigation_state; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3583 | } |
| 3584 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3585 | void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) { |
| 3586 | bool enable_viewport = |
[email protected] | 06ea34a | 2012-05-07 18:52:10 | [diff] [blame] | 3587 | command_line.HasSwitch(switches::kEnableViewport); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3588 | |
[email protected] | 47e932da | 2013-03-07 00:11:24 | [diff] [blame] | 3589 | // If viewport tag is enabled, then the WebKit side will take care |
| 3590 | // of setting the fixed layout size and page scale limits. |
| 3591 | if (enable_viewport) |
| 3592 | return; |
| 3593 | |
[email protected] | a02a0c9 | 2013-08-12 20:18:58 | [diff] [blame] | 3594 | // When navigating to a new page, reset the page scale factor to be 1.0. |
| 3595 | webview()->setInitialPageScaleOverride(1.f); |
| 3596 | |
[email protected] | e4cd82e | 2013-04-10 15:20:38 | [diff] [blame] | 3597 | float maxPageScaleFactor = |
| 3598 | command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ; |
| 3599 | webview()->setPageScaleFactorLimits(1, maxPageScaleFactor); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3600 | } |
| 3601 | |
[email protected] | 8672bbf | 2013-10-22 13:37:08 | [diff] [blame] | 3602 | // TODO(nasko): Remove this method once WebTestProxy in Blink is fixed. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3603 | void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3604 | } |
| 3605 | |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3606 | void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad( |
| 3607 | WebFrame* frame) { |
| 3608 | if (frame->parent()) |
| 3609 | return; |
| 3610 | // Received a redirect on the main frame. |
| 3611 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 3612 | if (!data_source) { |
| 3613 | // Should only be invoked when we have a data source. |
| 3614 | NOTREACHED(); |
| 3615 | return; |
| 3616 | } |
| 3617 | std::vector<GURL> redirects; |
| 3618 | GetRedirectChain(data_source, &redirects); |
| 3619 | if (redirects.size() >= 2) { |
| 3620 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
[email protected] | 434bc9b | 2012-11-27 21:22:14 | [diff] [blame] | 3621 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3622 | } |
| 3623 | } |
| 3624 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3625 | void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame, |
| 3626 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3627 | // Notify the browser that we failed a provisional load with an error. |
| 3628 | // |
| 3629 | // Note: It is important this notification occur before DidStopLoading so the |
| 3630 | // SSL manager can react to the provisional load failure before being |
| 3631 | // notified the load stopped. |
| 3632 | // |
| 3633 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3634 | DCHECK(ds); |
| 3635 | |
| 3636 | const WebURLRequest& failed_request = ds->request(); |
| 3637 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3638 | FOR_EACH_OBSERVER( |
| 3639 | RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error)); |
| 3640 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3641 | bool show_repost_interstitial = |
| 3642 | (error.reason == net::ERR_CACHE_MISS && |
| 3643 | EqualsASCII(failed_request.httpMethod(), "POST")); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3644 | |
| 3645 | ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 3646 | params.frame_id = frame->identifier(); |
[email protected] | 2f673064c | 2013-10-22 04:01:44 | [diff] [blame] | 3647 | params.frame_unique_name = frame->uniqueName(); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3648 | params.is_main_frame = !frame->parent(); |
| 3649 | params.error_code = error.reason; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3650 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 3651 | frame, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3652 | failed_request, |
| 3653 | error, |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 3654 | renderer_preferences_.accept_languages, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3655 | NULL, |
| 3656 | ¶ms.error_description); |
| 3657 | params.url = error.unreachableURL; |
| 3658 | params.showing_repost_interstitial = show_repost_interstitial; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3659 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3660 | routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3661 | |
| 3662 | // Don't display an error page if this is simply a cancelled load. Aside |
| 3663 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 3664 | if (error.reason == net::ERR_ABORTED) |
| 3665 | return; |
| 3666 | |
[email protected] | f677288e | 2013-09-18 02:11:00 | [diff] [blame] | 3667 | // Don't display "client blocked" error page if browser has asked us not to. |
| 3668 | if (error.reason == net::ERR_BLOCKED_BY_CLIENT && |
| 3669 | renderer_preferences_.disable_client_blocked_error_page) { |
| 3670 | return; |
| 3671 | } |
| 3672 | |
[email protected] | 2309e91 | 2013-10-01 01:33:30 | [diff] [blame] | 3673 | // Allow the embedder to suppress an error page. |
| 3674 | if (GetContentClient()->renderer()->ShouldSuppressErrorPage( |
| 3675 | error.unreachableURL)) { |
[email protected] | ac7f5a0 | 2013-03-16 16:14:41 | [diff] [blame] | 3676 | return; |
[email protected] | 2309e91 | 2013-10-01 01:33:30 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | if (RenderThreadImpl::current() && |
| 3680 | RenderThreadImpl::current()->layout_test_mode()) { |
| 3681 | return; |
| 3682 | } |
[email protected] | ac7f5a0 | 2013-03-16 16:14:41 | [diff] [blame] | 3683 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3684 | // Make sure we never show errors in view source mode. |
| 3685 | frame->enableViewSourceMode(false); |
| 3686 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3687 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3688 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3689 | |
| 3690 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 3691 | // 'replace' load. This is necessary to avoid messing up session history. |
| 3692 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 3693 | // as session history is concerned. |
| 3694 | // |
| 3695 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 3696 | // the page id. |
| 3697 | // |
| 3698 | bool replace = |
| 3699 | navigation_state->pending_page_id() != -1 || |
[email protected] | 026aac2 | 2013-07-10 02:09:11 | [diff] [blame] | 3700 | PageTransitionCoreTypeIs(navigation_state->transition_type(), |
| 3701 | PAGE_TRANSITION_AUTO_SUBFRAME); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3702 | |
| 3703 | // If we failed on a browser initiated request, then make sure that our error |
| 3704 | // page load is regarded as the same browser initiated request. |
| 3705 | if (!navigation_state->is_content_initiated()) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3706 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 3707 | pending_navigation_params_->page_id = |
| 3708 | navigation_state->pending_page_id(); |
| 3709 | pending_navigation_params_->pending_history_list_offset = |
| 3710 | navigation_state->pending_history_list_offset(); |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 3711 | pending_navigation_params_->should_clear_history_list = |
| 3712 | navigation_state->history_list_was_cleared(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3713 | pending_navigation_params_->transition = |
| 3714 | navigation_state->transition_type(); |
| 3715 | pending_navigation_params_->request_time = |
| 3716 | document_state->request_time(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | // Provide the user with a more helpful error page? |
| 3720 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 3721 | return; |
| 3722 | |
| 3723 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3724 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3725 | } |
| 3726 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3727 | void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame, |
| 3728 | bool is_new_navigation) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3729 | DocumentState* document_state = |
| 3730 | DocumentState::FromDataSource(frame->dataSource()); |
| 3731 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3732 | InternalDocumentStateData* internal_data = |
| 3733 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3734 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3735 | if (document_state->commit_load_time().is_null()) |
| 3736 | document_state->set_commit_load_time(Time::Now()); |
| 3737 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3738 | if (internal_data->must_reset_scroll_and_scale_state()) { |
[email protected] | 06c7ba02 | 2012-12-17 19:24:12 | [diff] [blame] | 3739 | webview()->resetScrollAndScaleState(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3740 | internal_data->set_must_reset_scroll_and_scale_state(false); |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3741 | } |
[email protected] | 4b9c9e29 | 2013-07-18 19:13:28 | [diff] [blame] | 3742 | internal_data->set_use_error_page(false); |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3743 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3744 | if (is_new_navigation) { |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 3745 | // When we perform a new navigation, we need to update the last committed |
| 3746 | // session history entry with state for the page we are leaving. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3747 | UpdateSessionHistory(frame); |
| 3748 | |
| 3749 | // We bump our Page ID to correspond with the new session history entry. |
| 3750 | page_id_ = next_page_id_++; |
| 3751 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3752 | // Don't update history_page_ids_ (etc) for kSwappedOutURL, since |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 3753 | // we don't want to forget the entry that was there, and since we will |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3754 | // never come back to kSwappedOutURL. Note that we have to call |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3755 | // UpdateSessionHistory and update page_id_ even in this case, so that |
| 3756 | // the current entry gets a state update and so that we don't send a |
| 3757 | // state update to the wrong entry when we swap back in. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3758 | if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3759 | // Advance our offset in session history, applying the length limit. |
| 3760 | // There is now no forward history. |
| 3761 | history_list_offset_++; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3762 | if (history_list_offset_ >= kMaxSessionHistoryEntries) |
| 3763 | history_list_offset_ = kMaxSessionHistoryEntries - 1; |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3764 | history_list_length_ = history_list_offset_ + 1; |
| 3765 | history_page_ids_.resize(history_list_length_, -1); |
| 3766 | history_page_ids_[history_list_offset_] = page_id_; |
| 3767 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3768 | } else { |
| 3769 | // Inspect the navigation_state on this frame to see if the navigation |
| 3770 | // corresponds to a session history navigation... Note: |frame| may or |
| 3771 | // may not be the toplevel frame, but for the case of capturing session |
| 3772 | // history, the first committed frame suffices. We keep track of whether |
| 3773 | // we've seen this commit before so that only capture session history once |
| 3774 | // per navigation. |
| 3775 | // |
| 3776 | // Note that we need to check if the page ID changed. In the case of a |
| 3777 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 3778 | // previous URL and the current page ID, which would be wrong. |
| 3779 | if (navigation_state->pending_page_id() != -1 && |
| 3780 | navigation_state->pending_page_id() != page_id_ && |
| 3781 | !navigation_state->request_committed()) { |
| 3782 | // This is a successful session history navigation! |
| 3783 | UpdateSessionHistory(frame); |
| 3784 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3785 | |
| 3786 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 3787 | |
| 3788 | // If the history list is valid, our list of page IDs should be correct. |
| 3789 | DCHECK(history_list_length_ <= 0 || |
| 3790 | history_list_offset_ < 0 || |
| 3791 | history_list_offset_ >= history_list_length_ || |
| 3792 | history_page_ids_[history_list_offset_] == page_id_); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3793 | } |
| 3794 | } |
| 3795 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3796 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3797 | DidCommitProvisionalLoad(frame, is_new_navigation)); |
| 3798 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3799 | // Remember that we've already processed this request, so we don't update |
| 3800 | // the session history again. We do this regardless of whether this is |
| 3801 | // a session history navigation, because if we attempted a session history |
| 3802 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3803 | // new navigation. |
| 3804 | navigation_state->set_request_committed(true); |
| 3805 | |
| 3806 | UpdateURL(frame); |
| 3807 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3808 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3809 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 3810 | |
| 3811 | if (!frame->parent()) { // Only for top frames. |
| 3812 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 3813 | if (render_thread_impl) { // Can be NULL in tests. |
| 3814 | render_thread_impl->histogram_customizer()-> |
| 3815 | RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(), |
| 3816 | g_view_map.Get().size()); |
| 3817 | } |
| 3818 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3819 | } |
| 3820 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3821 | void RenderViewImpl::didClearWindowObject(WebFrame* frame) { |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 3822 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3823 | DidClearWindowObject(frame)); |
| 3824 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3825 | if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 3826 | if (!dom_automation_controller_) |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3827 | dom_automation_controller_.reset(new DomAutomationController()); |
| 3828 | dom_automation_controller_->set_message_sender( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3829 | static_cast<RenderView*>(this)); |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3830 | dom_automation_controller_->set_routing_id(routing_id()); |
| 3831 | dom_automation_controller_->BindToJavascript(frame, |
| 3832 | "domAutomationController"); |
| 3833 | } |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 3834 | |
| 3835 | if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) { |
| 3836 | if (!stats_collection_controller_.get()) |
| 3837 | stats_collection_controller_.reset(new StatsCollectionController()); |
| 3838 | stats_collection_controller_->set_message_sender( |
| 3839 | static_cast<RenderView*>(this)); |
| 3840 | stats_collection_controller_->BindToJavascript(frame, |
| 3841 | "statsCollectionController"); |
| 3842 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3843 | } |
| 3844 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3845 | void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) { |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3846 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3847 | DidCreateDocumentElement(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3848 | } |
| 3849 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3850 | void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title, |
| 3851 | WebTextDirection direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 3852 | UpdateTitle(frame, title, direction); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3853 | |
| 3854 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3855 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3856 | } |
| 3857 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 3858 | void RenderViewImpl::didChangeIcon(WebFrame* frame, |
| 3859 | WebIconURL::Type icon_type) { |
| 3860 | if (frame->parent()) |
| 3861 | return; |
| 3862 | |
| 3863 | if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon) |
| 3864 | return; |
| 3865 | |
| 3866 | WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
| 3867 | std::vector<FaviconURL> urls; |
| 3868 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 3869 | urls.push_back(FaviconURL(icon_urls[i].iconURL(), |
| 3870 | ToFaviconType(icon_urls[i].iconType()))); |
| 3871 | } |
| 3872 | SendUpdateFaviconURL(urls); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3873 | } |
| 3874 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3875 | void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3876 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3877 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3878 | document_state->set_finish_document_load_time(Time::Now()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3879 | |
[email protected] | 622474d | 2010-11-04 09:21:08 | [diff] [blame] | 3880 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3881 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3882 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3883 | DidFinishDocumentLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3884 | |
| 3885 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3886 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3887 | } |
| 3888 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3889 | void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 3890 | if (webview()->mainFrame() == frame) { |
| 3891 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 3892 | page_id_)); |
| 3893 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3894 | } |
| 3895 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3896 | void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) { |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3897 | WebDataSource* ds = frame->dataSource(); |
| 3898 | DCHECK(ds); |
| 3899 | |
| 3900 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3901 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3902 | |
| 3903 | const WebURLRequest& failed_request = ds->request(); |
| 3904 | string16 error_description; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3905 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 3906 | frame, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3907 | failed_request, |
| 3908 | error, |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 3909 | renderer_preferences_.accept_languages, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3910 | NULL, |
| 3911 | &error_description); |
| 3912 | Send(new ViewHostMsg_DidFailLoadWithError(routing_id_, |
| 3913 | frame->identifier(), |
| 3914 | failed_request.url(), |
| 3915 | !frame->parent(), |
| 3916 | error.reason, |
| 3917 | error_description)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3918 | } |
| 3919 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3920 | void RenderViewImpl::didFinishLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3921 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3922 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 1ac2ff1 | 2013-07-16 20:53:53 | [diff] [blame] | 3923 | if (document_state->finish_load_time().is_null()) { |
| 3924 | if (!frame->parent()) { |
| 3925 | TRACE_EVENT_INSTANT0("WebCore", "LoadFinished", |
| 3926 | TRACE_EVENT_SCOPE_PROCESS); |
| 3927 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3928 | document_state->set_finish_load_time(Time::Now()); |
[email protected] | 1ac2ff1 | 2013-07-16 20:53:53 | [diff] [blame] | 3929 | } |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3930 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3931 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); |
[email protected] | fdd94a0 | 2010-11-05 08:07:17 | [diff] [blame] | 3932 | |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3933 | Send(new ViewHostMsg_DidFinishLoad(routing_id_, |
| 3934 | frame->identifier(), |
| 3935 | ds->request().url(), |
| 3936 | !frame->parent())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3937 | } |
| 3938 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3939 | void RenderViewImpl::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3940 | WebFrame* frame, bool is_new_navigation) { |
| 3941 | // If this was a reference fragment navigation that we initiated, then we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3942 | // could end up having a non-null pending navigation params. We just need to |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3943 | // update the ExtraData on the datasource so that others who read the |
| 3944 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3945 | // initiate this navigation, then we need to take care to reset any pre- |
| 3946 | // existing navigation state to a content-initiated navigation state. |
| 3947 | // DidCreateDataSource conveniently takes care of this for us. |
| 3948 | didCreateDataSource(frame, frame->dataSource()); |
| 3949 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3950 | DocumentState* document_state = |
| 3951 | DocumentState::FromDataSource(frame->dataSource()); |
| 3952 | NavigationState* new_state = document_state->navigation_state(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3953 | new_state->set_was_within_same_page(true); |
| 3954 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3955 | didCommitProvisionalLoad(frame, is_new_navigation); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3956 | } |
| 3957 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3958 | void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3959 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3960 | } |
| 3961 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3962 | void RenderViewImpl::willSendRequest(WebFrame* frame, |
| 3963 | unsigned identifier, |
| 3964 | WebURLRequest& request, |
| 3965 | const WebURLResponse& redirect_response) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3966 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3967 | } |
| 3968 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3969 | void RenderViewImpl::didReceiveResponse( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3970 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 3971 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3972 | } |
| 3973 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3974 | void RenderViewImpl::didFinishResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3975 | WebFrame* frame, unsigned identifier) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3976 | InternalDocumentStateData* internal_data = |
| 3977 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 3978 | if (!internal_data->use_error_page()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3979 | return; |
| 3980 | |
[email protected] | 7bfc153f | 2011-09-23 22:00:20 | [diff] [blame] | 3981 | // Do not show error page when DevTools is attached. |
| 3982 | if (devtools_agent_->IsAttached()) |
| 3983 | return; |
| 3984 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3985 | // Display error page, if appropriate. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3986 | int http_status_code = internal_data->http_status_code(); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3987 | if (http_status_code == 404) { |
| 3988 | // On 404s, try a remote search page as a fallback. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3989 | const GURL& document_url = frame->document().url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3990 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3991 | const GURL& error_page_url = |
| 3992 | GetAlternateErrorPageURL(document_url, HTTP_404); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3993 | if (error_page_url.is_valid()) { |
| 3994 | WebURLError original_error; |
[email protected] | 2e9706c | 2011-06-09 16:49:47 | [diff] [blame] | 3995 | original_error.domain = "http"; |
| 3996 | original_error.reason = 404; |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3997 | original_error.unreachableURL = document_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3998 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3999 | internal_data->set_alt_error_page_fetcher( |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 4000 | new AltErrorPageResourceFetcher( |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 4001 | error_page_url, frame, frame->dataSource()->request(), |
| 4002 | original_error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 4003 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 4004 | base::Unretained(this)))); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 4005 | return; |
| 4006 | } |
| 4007 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4008 | |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 4009 | std::string error_domain; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4010 | if (GetContentClient()->renderer()->HasErrorPage( |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 4011 | http_status_code, &error_domain)) { |
| 4012 | WebURLError error; |
| 4013 | error.unreachableURL = frame->document().url(); |
| 4014 | error.domain = WebString::fromUTF8(error_domain); |
| 4015 | error.reason = http_status_code; |
| 4016 | |
| 4017 | LoadNavigationErrorPage( |
| 4018 | frame, frame->dataSource()->request(), error, std::string(), true); |
| 4019 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4020 | } |
| 4021 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4022 | void RenderViewImpl::didLoadResourceFromMemoryCache( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4023 | WebFrame* frame, const WebURLRequest& request, |
| 4024 | const WebURLResponse& response) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4025 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4026 | } |
| 4027 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4028 | void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4029 | NOTREACHED(); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 4030 | } |
| 4031 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4032 | void RenderViewImpl::didRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 4033 | WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4034 | NOTREACHED(); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 4035 | } |
| 4036 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4037 | void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4038 | NOTREACHED(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4039 | } |
| 4040 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4041 | void RenderViewImpl::didCreateScriptContext(WebFrame* frame, |
| 4042 | v8::Handle<v8::Context> context, |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 4043 | int extension_group, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4044 | int world_id) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4045 | NOTREACHED(); |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 4046 | } |
| 4047 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4048 | void RenderViewImpl::willReleaseScriptContext(WebFrame* frame, |
| 4049 | v8::Handle<v8::Context> context, |
| 4050 | int world_id) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4051 | NOTREACHED(); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 4052 | } |
| 4053 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4054 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 4055 | // We don't always want to send the change messages over IPC, only if we've |
| 4056 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 4057 | // message. |
| 4058 | if (!send_preferred_size_changes_ || !webview()) |
| 4059 | return; |
| 4060 | |
[email protected] | e76b797 | 2013-06-06 02:58:48 | [diff] [blame] | 4061 | gfx::Size size = webview()->contentsPreferredMinimumSize(); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 4062 | |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 4063 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 4064 | // so we need to adjust. |
| 4065 | double zoom_factor = ZoomLevelToZoomFactor(webview()->zoomLevel()); |
| 4066 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 4067 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 4068 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 4069 | if (size == preferred_size_) |
| 4070 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 4071 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 4072 | preferred_size_ = size; |
| 4073 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 4074 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4075 | } |
| 4076 | |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 4077 | BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 4078 | if (!browser_plugin_manager_.get()) |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 4079 | browser_plugin_manager_ = BrowserPluginManager::Create(this); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 4080 | return browser_plugin_manager_.get(); |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 4081 | } |
| 4082 | |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 4083 | bool RenderViewImpl::InitializeMediaStreamClient() { |
| 4084 | if (media_stream_client_) |
| 4085 | return true; |
| 4086 | |
[email protected] | 7082fb94 | 2012-05-16 23:44:59 | [diff] [blame] | 4087 | if (!RenderThreadImpl::current()) // Will be NULL during unit tests. |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 4088 | return false; |
[email protected] | 0838156 | 2012-05-15 20:55:40 | [diff] [blame] | 4089 | |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 4090 | #if defined(OS_ANDROID) |
[email protected] | ce585bf | 2013-03-14 16:25:16 | [diff] [blame] | 4091 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC)) |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 4092 | return false; |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 4093 | #endif |
| 4094 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 4095 | #if defined(ENABLE_WEBRTC) |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4096 | if (!media_stream_dispatcher_) |
| 4097 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 4098 | |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 4099 | MediaStreamImpl* media_stream_impl = new MediaStreamImpl( |
| 4100 | this, |
| 4101 | media_stream_dispatcher_, |
| 4102 | RenderThreadImpl::current()->GetMediaStreamDependencyFactory()); |
| 4103 | media_stream_client_ = media_stream_impl; |
| 4104 | web_user_media_client_ = media_stream_impl; |
| 4105 | return true; |
| 4106 | #else |
| 4107 | return false; |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 4108 | #endif |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4109 | } |
| 4110 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4111 | void RenderViewImpl::didChangeContentsSize(WebFrame* frame, |
| 4112 | const WebSize& size) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4113 | if (webview()->mainFrame() != frame) |
| 4114 | return; |
| 4115 | WebView* frameView = frame->view(); |
| 4116 | if (!frameView) |
| 4117 | return; |
| 4118 | |
| 4119 | bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); |
| 4120 | bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); |
| 4121 | |
| 4122 | if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || |
| 4123 | has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { |
| 4124 | Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( |
| 4125 | routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); |
| 4126 | |
| 4127 | cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; |
| 4128 | cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; |
| 4129 | } |
| 4130 | } |
| 4131 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4132 | void RenderViewImpl::UpdateScrollState(WebFrame* frame) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4133 | WebSize offset = frame->scrollOffset(); |
| 4134 | WebSize minimum_offset = frame->minimumScrollOffset(); |
| 4135 | WebSize maximum_offset = frame->maximumScrollOffset(); |
| 4136 | |
| 4137 | bool is_pinned_to_left = offset.width <= minimum_offset.width; |
| 4138 | bool is_pinned_to_right = offset.width >= maximum_offset.width; |
| 4139 | |
| 4140 | if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || |
| 4141 | is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { |
| 4142 | Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( |
| 4143 | routing_id_, is_pinned_to_left, is_pinned_to_right)); |
| 4144 | |
| 4145 | cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; |
| 4146 | cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; |
| 4147 | } |
[email protected] | 4e72174 | 2013-02-04 21:39:30 | [diff] [blame] | 4148 | |
| 4149 | Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4150 | } |
| 4151 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4152 | void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) { |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 4153 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4154 | |
| 4155 | if (webview()->mainFrame() == frame) |
| 4156 | UpdateScrollState(frame); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 4157 | |
| 4158 | FOR_EACH_OBSERVER( |
| 4159 | RenderViewObserver, observers_, DidChangeScrollOffset(frame)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4160 | } |
| 4161 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4162 | void RenderViewImpl::willInsertBody(blink::WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4163 | NOTREACHED(); |
[email protected] | a9344092d | 2013-02-27 00:56:45 | [diff] [blame] | 4164 | } |
| 4165 | |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4166 | void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) { |
| 4167 | if (frame != webview()->mainFrame()) |
| 4168 | return; |
| 4169 | |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 4170 | InternalDocumentStateData* data = |
| 4171 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 4172 | data->set_did_first_visually_non_empty_layout(true); |
| 4173 | |
| 4174 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4175 | // Update body background color if necessary. |
| 4176 | SkColor bg_color = webwidget_->backgroundColor(); |
| 4177 | |
| 4178 | // If not initialized, default to white. Note that 0 is different from black |
| 4179 | // as black still has alpha 0xFF. |
| 4180 | if (!bg_color) |
| 4181 | bg_color = SK_ColorWHITE; |
| 4182 | |
| 4183 | if (bg_color != body_background_color_) { |
| 4184 | body_background_color_ = bg_color; |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4185 | Send(new ViewHostMsg_DidChangeBodyBackgroundColor( |
| 4186 | GetRoutingID(), bg_color)); |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4187 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4188 | #endif |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 4189 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4190 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4191 | void RenderViewImpl::SendFindReply(int request_id, |
| 4192 | int match_count, |
| 4193 | int ordinal, |
| 4194 | const WebRect& selection_rect, |
| 4195 | bool final_status_update) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4196 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 4197 | request_id, |
| 4198 | match_count, |
| 4199 | selection_rect, |
| 4200 | ordinal, |
| 4201 | final_status_update)); |
| 4202 | } |
| 4203 | |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 4204 | // static |
| 4205 | bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams( |
| 4206 | const string16& selection_text, |
| 4207 | size_t selection_text_offset, |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 4208 | const gfx::Range& selection_range, |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 4209 | const ContextMenuParams& params) { |
| 4210 | string16 trimmed_selection_text; |
| 4211 | if (!selection_text.empty() && !selection_range.is_empty()) { |
| 4212 | const int start = selection_range.GetMin() - selection_text_offset; |
| 4213 | const size_t length = selection_range.length(); |
| 4214 | if (start >= 0 && start + length <= selection_text.length()) { |
| 4215 | TrimWhitespace(selection_text.substr(start, length), TRIM_ALL, |
| 4216 | &trimmed_selection_text); |
| 4217 | } |
| 4218 | } |
| 4219 | string16 trimmed_params_text; |
| 4220 | TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text); |
| 4221 | return trimmed_params_text != trimmed_selection_text; |
| 4222 | } |
| 4223 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4224 | void RenderViewImpl::reportFindInPageMatchCount(int request_id, |
| 4225 | int count, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4226 | bool final_update) { |
[email protected] | 1f35b45e | 2013-08-29 17:36:46 | [diff] [blame] | 4227 | // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame |
| 4228 | main_render_frame_->reportFindInPageMatchCount( |
| 4229 | request_id, count, final_update); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 4230 | } |
| 4231 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4232 | void RenderViewImpl::reportFindInPageSelection(int request_id, |
| 4233 | int active_match_ordinal, |
| 4234 | const WebRect& selection_rect) { |
[email protected] | 1f35b45e | 2013-08-29 17:36:46 | [diff] [blame] | 4235 | // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame |
| 4236 | main_render_frame_->reportFindInPageSelection( |
| 4237 | request_id, active_match_ordinal, selection_rect); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 4238 | } |
| 4239 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4240 | void RenderViewImpl::requestStorageQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4241 | WebFrame* frame, |
| 4242 | WebStorageQuotaType type, |
| 4243 | unsigned long long requested_size, |
| 4244 | WebStorageQuotaCallbacks* callbacks) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4245 | NOTREACHED(); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4246 | } |
| 4247 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4248 | bool RenderViewImpl::willCheckAndDispatchMessageEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4249 | blink::WebFrame* sourceFrame, |
| 4250 | blink::WebFrame* targetFrame, |
| 4251 | blink::WebSecurityOrigin target_origin, |
| 4252 | blink::WebDOMMessageEvent event) { |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4253 | if (!is_swapped_out_) |
| 4254 | return false; |
| 4255 | |
| 4256 | ViewMsg_PostMessage_Params params; |
| 4257 | params.data = event.data().toString(); |
| 4258 | params.source_origin = event.origin(); |
| 4259 | if (!target_origin.isNull()) |
| 4260 | params.target_origin = target_origin.toString(); |
| 4261 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4262 | blink::WebMessagePortChannelArray channels = event.releaseChannels(); |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 4263 | if (!channels.isEmpty()) { |
| 4264 | std::vector<int> message_port_ids(channels.size()); |
| 4265 | // Extract the port IDs from the channel array. |
| 4266 | for (size_t i = 0; i < channels.size(); ++i) { |
| 4267 | WebMessagePortChannelImpl* webchannel = |
| 4268 | static_cast<WebMessagePortChannelImpl*>(channels[i]); |
| 4269 | message_port_ids[i] = webchannel->message_port_id(); |
| 4270 | webchannel->QueueMessages(); |
| 4271 | DCHECK_NE(message_port_ids[i], MSG_ROUTING_NONE); |
| 4272 | } |
| 4273 | params.message_port_ids = message_port_ids; |
| 4274 | } |
| 4275 | |
[email protected] | 2bb45f5 | 2013-11-02 02:15:08 | [diff] [blame] | 4276 | // Include the routing ID for the source frame (if one exists), which the |
| 4277 | // browser process will translate into the routing ID for the equivalent |
| 4278 | // frame in the target process. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4279 | params.source_routing_id = MSG_ROUTING_NONE; |
[email protected] | 2bb45f5 | 2013-11-02 02:15:08 | [diff] [blame] | 4280 | if (sourceFrame) { |
| 4281 | RenderViewImpl* source_view = FromWebView(sourceFrame->view()); |
| 4282 | if (source_view) |
| 4283 | params.source_routing_id = source_view->routing_id(); |
| 4284 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4285 | |
| 4286 | Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
| 4287 | return true; |
| 4288 | } |
| 4289 | |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 4290 | void RenderViewImpl::willOpenSocketStream( |
| 4291 | WebSocketStreamHandle* handle) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4292 | NOTREACHED(); |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 4293 | } |
| 4294 | |
[email protected] | ccee486 | 2012-10-03 18:34:26 | [diff] [blame] | 4295 | void RenderViewImpl::willStartUsingPeerConnectionHandler( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4296 | blink::WebFrame* frame, blink::WebRTCPeerConnectionHandler* handler) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4297 | NOTREACHED(); |
[email protected] | ccee486 | 2012-10-03 18:34:26 | [diff] [blame] | 4298 | } |
| 4299 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4300 | blink::WebString RenderViewImpl::acceptLanguages() { |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame] | 4301 | return WebString::fromUTF8(renderer_preferences_.accept_languages); |
| 4302 | } |
| 4303 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4304 | blink::WebString RenderViewImpl::userAgentOverride( |
| 4305 | blink::WebFrame* frame, |
| 4306 | const blink::WebURL& url) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4307 | NOTREACHED(); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4308 | return blink::WebString(); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 4309 | } |
| 4310 | |
[email protected] | a3e217f | 2013-04-12 22:38:34 | [diff] [blame] | 4311 | WebString RenderViewImpl::doNotTrackValue(WebFrame* frame) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4312 | NOTREACHED(); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4313 | return blink::WebString(); |
[email protected] | a3e217f | 2013-04-12 22:38:34 | [diff] [blame] | 4314 | } |
| 4315 | |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 4316 | bool RenderViewImpl::allowWebGL(WebFrame* frame, bool default_value) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4317 | NOTREACHED(); |
| 4318 | return false; |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | void RenderViewImpl::didLoseWebGLContext( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4322 | blink::WebFrame* frame, |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 4323 | int arb_robustness_status_code) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4324 | NOTREACHED(); |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 4325 | } |
| 4326 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4327 | // blink::WebPageSerializerClient implementation ------------------------------ |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4328 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4329 | void RenderViewImpl::didSerializeDataForFrame( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4330 | const WebURL& frame_url, |
| 4331 | const WebCString& data, |
| 4332 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4333 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4334 | routing_id(), |
| 4335 | frame_url, |
| 4336 | data.data(), |
| 4337 | static_cast<int32>(status))); |
| 4338 | } |
| 4339 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4340 | // RenderView implementation --------------------------------------------------- |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4341 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4342 | bool RenderViewImpl::Send(IPC::Message* message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4343 | return RenderWidget::Send(message); |
| 4344 | } |
| 4345 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4346 | int RenderViewImpl::GetRoutingID() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4347 | return routing_id_; |
| 4348 | } |
| 4349 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4350 | int RenderViewImpl::GetPageId() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4351 | return page_id_; |
| 4352 | } |
| 4353 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4354 | gfx::Size RenderViewImpl::GetSize() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4355 | return size(); |
| 4356 | } |
| 4357 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4358 | WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4359 | return webkit_preferences_; |
| 4360 | } |
| 4361 | |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 4362 | void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) { |
| 4363 | OnUpdateWebPreferences(preferences); |
| 4364 | } |
| 4365 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4366 | blink::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4367 | return webview(); |
| 4368 | } |
| 4369 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4370 | blink::WebNode RenderViewImpl::GetFocusedNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4371 | if (!webview()) |
| 4372 | return WebNode(); |
| 4373 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 4374 | if (focused_frame) { |
| 4375 | WebDocument doc = focused_frame->document(); |
| 4376 | if (!doc.isNull()) |
| 4377 | return doc.focusedNode(); |
| 4378 | } |
| 4379 | |
| 4380 | return WebNode(); |
| 4381 | } |
| 4382 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4383 | blink::WebNode RenderViewImpl::GetContextMenuNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4384 | return context_menu_node_; |
| 4385 | } |
| 4386 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4387 | bool RenderViewImpl::IsEditableNode(const WebNode& node) const { |
| 4388 | if (node.isNull()) |
| 4389 | return false; |
| 4390 | |
| 4391 | if (node.isContentEditable()) |
| 4392 | return true; |
| 4393 | |
| 4394 | if (node.isElementNode()) { |
| 4395 | const WebElement& element = node.toConst<WebElement>(); |
| 4396 | if (element.isTextFormControlElement()) |
| 4397 | return true; |
| 4398 | |
| 4399 | // Also return true if it has an ARIA role of 'textbox'. |
| 4400 | for (unsigned i = 0; i < element.attributeCount(); ++i) { |
| 4401 | if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) { |
| 4402 | if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox")) |
| 4403 | return true; |
| 4404 | break; |
| 4405 | } |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4406 | } |
| 4407 | } |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4408 | |
| 4409 | return false; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4410 | } |
| 4411 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4412 | blink::WebPlugin* RenderViewImpl::CreatePlugin( |
| 4413 | blink::WebFrame* frame, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 4414 | const WebPluginInfo& info, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4415 | const blink::WebPluginParams& params) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4416 | #if defined(ENABLE_PLUGINS) |
| 4417 | bool pepper_plugin_was_registered = false; |
| 4418 | scoped_refptr<PluginModule> pepper_module(PluginModule::Create( |
| 4419 | this, info, &pepper_plugin_was_registered)); |
| 4420 | if (pepper_plugin_was_registered) { |
| 4421 | if (pepper_module.get()) |
| 4422 | return new PepperWebPluginImpl(pepper_module.get(), params, AsWeakPtr()); |
| 4423 | } |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4424 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 4425 | return new WebPluginImpl(frame, params, info.path, AsWeakPtr()); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4426 | #else |
| 4427 | return NULL; |
| 4428 | #endif |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4429 | } |
| 4430 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4431 | void RenderViewImpl::EvaluateScript(const string16& frame_xpath, |
| 4432 | const string16& jscript, |
| 4433 | int id, |
| 4434 | bool notify_result) { |
[email protected] | e1907b43 | 2013-09-04 16:11:14 | [diff] [blame] | 4435 | v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4436 | v8::Handle<v8::Value> result; |
| 4437 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4438 | if (web_frame) |
| 4439 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); |
| 4440 | if (notify_result) { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4441 | base::ListValue list; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4442 | if (!result.IsEmpty() && web_frame) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4443 | v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 4444 | v8::Context::Scope context_scope(context); |
| 4445 | V8ValueConverterImpl converter; |
[email protected] | 3de391e8 | 2012-05-16 17:50:51 | [diff] [blame] | 4446 | converter.SetDateAllowed(true); |
[email protected] | e0658bc | 2012-09-17 04:05:24 | [diff] [blame] | 4447 | converter.SetRegExpAllowed(true); |
| 4448 | base::Value* result_value = converter.FromV8Value(result, context); |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4449 | list.Set(0, result_value ? result_value : base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4450 | } else { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4451 | list.Set(0, base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4452 | } |
| 4453 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
| 4454 | } |
| 4455 | } |
| 4456 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4457 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4458 | return (!send_preferred_size_changes_ || |
| 4459 | (disable_scrollbars_size_limit_.width() <= width || |
| 4460 | disable_scrollbars_size_limit_.height() <= height)); |
| 4461 | } |
| 4462 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4463 | int RenderViewImpl::GetEnabledBindings() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4464 | return enabled_bindings_; |
| 4465 | } |
| 4466 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4467 | bool RenderViewImpl::GetContentStateImmediately() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4468 | return send_content_state_immediately_; |
| 4469 | } |
| 4470 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4471 | float RenderViewImpl::GetFilteredTimePerFrame() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4472 | return filtered_time_per_frame(); |
| 4473 | } |
| 4474 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4475 | int RenderViewImpl::ShowContextMenu(ContextMenuClient* client, |
| 4476 | const ContextMenuParams& params) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4477 | DCHECK(client); // A null client means "internal" when we issue callbacks. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4478 | ContextMenuParams our_params(params); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4479 | our_params.custom_context.request_id = pending_context_menus_.Add(client); |
| 4480 | Send(new ViewHostMsg_ContextMenu(routing_id_, our_params)); |
| 4481 | return our_params.custom_context.request_id; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4482 | } |
| 4483 | |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 4484 | void RenderViewImpl::CancelContextMenu(int request_id) { |
| 4485 | DCHECK(pending_context_menus_.Lookup(request_id)); |
| 4486 | pending_context_menus_.Remove(request_id); |
| 4487 | } |
| 4488 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4489 | blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4490 | return visibilityState(); |
| 4491 | } |
| 4492 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4493 | void RenderViewImpl::RunModalAlertDialog(blink::WebFrame* frame, |
| 4494 | const blink::WebString& message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4495 | return runModalAlertDialog(frame, message); |
| 4496 | } |
| 4497 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4498 | void RenderViewImpl::LoadURLExternally( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4499 | blink::WebFrame* frame, |
| 4500 | const blink::WebURLRequest& request, |
| 4501 | blink::WebNavigationPolicy policy) { |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 4502 | main_render_frame_->loadURLExternally(frame, request, policy); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4503 | } |
| 4504 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4505 | void RenderViewImpl::DidStartLoading() { |
| 4506 | didStartLoading(); |
| 4507 | } |
| 4508 | |
| 4509 | void RenderViewImpl::DidStopLoading() { |
| 4510 | didStopLoading(); |
| 4511 | } |
| 4512 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4513 | void RenderViewImpl::DidPlay(blink::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4514 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4515 | reinterpret_cast<int64>(player), |
| 4516 | player->hasVideo(), |
| 4517 | player->hasAudio(), |
| 4518 | true)); |
| 4519 | } |
| 4520 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4521 | void RenderViewImpl::DidPause(blink::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4522 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4523 | reinterpret_cast<int64>(player), |
| 4524 | player->hasVideo(), |
| 4525 | player->hasAudio(), |
| 4526 | false)); |
| 4527 | } |
| 4528 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4529 | void RenderViewImpl::PlayerGone(blink::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4530 | DidPause(player); |
| 4531 | } |
| 4532 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4533 | void RenderViewImpl::SyncNavigationState() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4534 | if (!webview()) |
| 4535 | return; |
| 4536 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4537 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 4538 | SendUpdateState(item); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4539 | } |
| 4540 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4541 | void RenderViewImpl::SyncSelectionIfRequired() { |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4542 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4543 | if (!frame) |
| 4544 | return; |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4545 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4546 | string16 text; |
| 4547 | size_t offset; |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 4548 | gfx::Range range; |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4549 | #if defined(ENABLE_PLUGINS) |
| 4550 | if (focused_pepper_plugin_) { |
| 4551 | focused_pepper_plugin_->GetSurroundingText(&text, &range); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4552 | offset = 0; // Pepper API does not support offset reporting. |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4553 | // TODO(kinaba): cut as needed. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 4554 | } else |
| 4555 | #endif |
| 4556 | { |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4557 | size_t location, length; |
| 4558 | if (!webview()->caretOrSelectionRange(&location, &length)) |
| 4559 | return; |
| 4560 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 4561 | range = gfx::Range(location, location + length); |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4562 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4563 | if (webview()->textInputInfo().type != blink::WebTextInputTypeNone) { |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4564 | // If current focused element is editable, we will send 100 more chars |
| 4565 | // before and after selection. It is for input method surrounding text |
| 4566 | // feature. |
| 4567 | if (location > kExtraCharsBeforeAndAfterSelection) |
| 4568 | offset = location - kExtraCharsBeforeAndAfterSelection; |
| 4569 | else |
| 4570 | offset = 0; |
| 4571 | length = location + length - offset + kExtraCharsBeforeAndAfterSelection; |
| 4572 | WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); |
| 4573 | if (!webrange.isNull()) |
| 4574 | text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); |
| 4575 | } else { |
| 4576 | offset = location; |
| 4577 | text = frame->selectionAsText(); |
| 4578 | // http://crbug.com/101435 |
| 4579 | // In some case, frame->selectionAsText() returned text's length is not |
| 4580 | // equal to the length returned from webview()->caretOrSelectionRange(). |
| 4581 | // So we have to set the range according to text.length(). |
| 4582 | range.set_end(range.start() + text.length()); |
| 4583 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4584 | } |
| 4585 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4586 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 4587 | // the selection hasn't actually changed. We don't want to report these |
| 4588 | // because it will cause us to continually claim the X clipboard. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4589 | if (selection_text_offset_ != offset || |
| 4590 | selection_range_ != range || |
| 4591 | selection_text_ != text) { |
| 4592 | selection_text_ = text; |
| 4593 | selection_text_offset_ = offset; |
| 4594 | selection_range_ = range; |
| 4595 | Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range)); |
| 4596 | } |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 4597 | UpdateSelectionBounds(); |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4598 | } |
| 4599 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4600 | GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, |
| 4601 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4602 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4603 | // If the URL that failed was secure, then the embedding web page was not |
| 4604 | // expecting a network attacker to be able to manipulate its contents. As |
| 4605 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 4606 | // attacker to manipulate the contents of the response if we tried to use |
| 4607 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4608 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4609 | } |
| 4610 | |
| 4611 | // Grab the base URL from the browser process. |
| 4612 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4613 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4614 | |
| 4615 | // Strip query params from the failed URL. |
| 4616 | GURL::Replacements remove_params; |
| 4617 | remove_params.ClearUsername(); |
| 4618 | remove_params.ClearPassword(); |
| 4619 | remove_params.ClearQuery(); |
| 4620 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4621 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 4622 | // TODO(yuusuke): change to net::FormatUrl when link doctor |
| 4623 | // becomes unicode-capable. |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 4624 | std::string spec_to_send = url_to_send.spec(); |
| 4625 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 4626 | if (failed_url.has_query()) |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4627 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4628 | |
| 4629 | // Construct the query params to send to link doctor. |
| 4630 | std::string params(alternate_error_page_url_.query()); |
| 4631 | params.append("&url="); |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 4632 | params.append(net::EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4633 | params.append("&sourceid=chrome"); |
| 4634 | params.append("&error="); |
| 4635 | switch (error_type) { |
| 4636 | case DNS_ERROR: |
| 4637 | params.append("dnserror"); |
| 4638 | break; |
| 4639 | |
| 4640 | case HTTP_404: |
| 4641 | params.append("http404"); |
| 4642 | break; |
| 4643 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4644 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 4645 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4646 | break; |
| 4647 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4648 | default: |
| 4649 | NOTREACHED() << "unknown ErrorPageType"; |
| 4650 | } |
| 4651 | |
| 4652 | // OK, build the final url to return. |
| 4653 | GURL::Replacements link_doctor_params; |
| 4654 | link_doctor_params.SetQueryStr(params); |
| 4655 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 4656 | return url; |
| 4657 | } |
| 4658 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4659 | GURL RenderViewImpl::GetLoadingUrl(blink::WebFrame* frame) const { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 4660 | WebDataSource* ds = frame->dataSource(); |
| 4661 | if (ds->hasUnreachableURL()) |
| 4662 | return ds->unreachableURL(); |
| 4663 | |
| 4664 | const WebURLRequest& request = ds->request(); |
| 4665 | return request.url(); |
| 4666 | } |
| 4667 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 4668 | blink::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4669 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4670 | } |
| 4671 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4672 | void RenderViewImpl::OnFind(int request_id, |
| 4673 | const string16& search_text, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4674 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4675 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4676 | |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4677 | // Check if the plugin still exists in the document. |
| 4678 | if (main_frame->document().isPluginDocument() && |
| 4679 | GetWebPluginFromPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4680 | if (options.findNext) { |
| 4681 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4682 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4683 | } else { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4684 | if (!GetWebPluginFromPluginDocument()->startFind( |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 4685 | search_text, options.matchCase, request_id)) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 4686 | // Send "no results". |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4687 | SendFindReply(request_id, 0, 0, gfx::Rect(), true); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4688 | } |
| 4689 | } |
| 4690 | return; |
| 4691 | } |
| 4692 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4693 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4694 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4695 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 4696 | |
| 4697 | bool multi_frame = (frame_after_main != main_frame); |
| 4698 | |
| 4699 | // If we have multiple frames, we don't want to wrap the search within the |
| 4700 | // frame, so we check here if we only have main_frame in the chain. |
| 4701 | bool wrap_within_frame = !multi_frame; |
| 4702 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 4703 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4704 | bool result = false; |
| 4705 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4706 | // If something is selected when we start searching it means we cannot just |
| 4707 | // increment the current match ordinal; we need to re-generate it. |
| 4708 | WebRange current_selection = focused_frame->selectionRange(); |
| 4709 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4710 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4711 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4712 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4713 | |
| 4714 | if (!result) { |
| 4715 | // don't leave text selected as you move to the next frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4716 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
| 4717 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4718 | |
| 4719 | // Find the next frame, but skip the invisible ones. |
| 4720 | do { |
| 4721 | // What is the next frame to search? (we might be going backwards). Note |
| 4722 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4723 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4724 | search_frame->traverseNext(true) : |
| 4725 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4726 | } while (!search_frame->hasVisibleContent() && |
| 4727 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4728 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 4729 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4730 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
| 4731 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4732 | |
| 4733 | // If we have multiple frames and we have wrapped back around to the |
| 4734 | // focused frame, we need to search it once more allowing wrap within |
| 4735 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 4736 | // reported matches, but no frames after the focused_frame contain a |
| 4737 | // match for the search word(s). |
| 4738 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4739 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4740 | request_id, search_text, options, true, // Force wrapping. |
| 4741 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4742 | } |
| 4743 | } |
| 4744 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4745 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4746 | } while (!result && search_frame != focused_frame); |
| 4747 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4748 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4749 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4750 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4751 | } else { |
| 4752 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 4753 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 4754 | // yet what is active. |
| 4755 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 4756 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4757 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4758 | // If we find no matches then this will be our last status update. |
| 4759 | // Otherwise the scoping effort will send more results. |
| 4760 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4761 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4762 | SendFindReply(request_id, match_count, ordinal, selection_rect, |
| 4763 | final_status_update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4764 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4765 | // Scoping effort begins, starting with the mainframe. |
| 4766 | search_frame = main_frame; |
| 4767 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4768 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4769 | |
| 4770 | do { |
| 4771 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4772 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4773 | |
| 4774 | // We don't start another scoping effort unless at least one match has |
| 4775 | // been found. |
| 4776 | if (result) { |
| 4777 | // Start new scoping request. If the scoping function determines that it |
| 4778 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4779 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4780 | search_text, |
| 4781 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4782 | true); // reset the tickmarks |
| 4783 | } |
| 4784 | |
| 4785 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 4786 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4787 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4788 | } while (search_frame != main_frame); |
| 4789 | } |
| 4790 | } |
| 4791 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4792 | void RenderViewImpl::OnStopFinding(StopFindAction action) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4793 | WebView* view = webview(); |
| 4794 | if (!view) |
| 4795 | return; |
| 4796 | |
| 4797 | WebDocument doc = view->mainFrame()->document(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4798 | if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4799 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4800 | return; |
| 4801 | } |
| 4802 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4803 | bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4804 | if (clear_selection) { |
| 4805 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
| 4806 | GetFocusedNode()); |
| 4807 | } |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4808 | |
| 4809 | WebFrame* frame = view->mainFrame(); |
| 4810 | while (frame) { |
| 4811 | frame->stopFinding(clear_selection); |
| 4812 | frame = frame->traverseNext(false); |
| 4813 | } |
| 4814 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4815 | if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4816 | WebFrame* focused_frame = view->focusedFrame(); |
| 4817 | if (focused_frame) { |
| 4818 | WebDocument doc = focused_frame->document(); |
| 4819 | if (!doc.isNull()) { |
| 4820 | WebNode node = doc.focusedNode(); |
| 4821 | if (!node.isNull()) |
| 4822 | node.simulateClick(); |
| 4823 | } |
| 4824 | } |
| 4825 | } |
| 4826 | } |
| 4827 | |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4828 | #if defined(OS_ANDROID) |
| 4829 | void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| 4830 | float x, float y) { |
| 4831 | if (!webview()) |
| 4832 | return; |
| 4833 | |
| 4834 | WebFrame* main_frame = webview()->mainFrame(); |
| 4835 | WebRect selection_rect; |
| 4836 | int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), |
| 4837 | &selection_rect); |
| 4838 | if (ordinal == -1) { |
| 4839 | // Something went wrong, so send a no-op reply (force the main_frame to |
| 4840 | // report the current match count) in case the host is waiting for a |
| 4841 | // response due to rate-limiting). |
| 4842 | main_frame->increaseMatchCount(0, request_id); |
| 4843 | return; |
| 4844 | } |
| 4845 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4846 | SendFindReply(request_id, |
| 4847 | -1 /* number_of_matches */, |
| 4848 | ordinal, |
| 4849 | selection_rect, |
| 4850 | true /* final_update */); |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4851 | } |
| 4852 | |
| 4853 | void RenderViewImpl::OnFindMatchRects(int current_version) { |
| 4854 | if (!webview()) |
| 4855 | return; |
| 4856 | |
| 4857 | WebFrame* main_frame = webview()->mainFrame(); |
| 4858 | std::vector<gfx::RectF> match_rects; |
| 4859 | |
| 4860 | int rects_version = main_frame->findMatchMarkersVersion(); |
| 4861 | if (current_version != rects_version) { |
| 4862 | WebVector<WebFloatRect> web_match_rects; |
| 4863 | main_frame->findMatchRects(web_match_rects); |
| 4864 | match_rects.reserve(web_match_rects.size()); |
| 4865 | for (size_t i = 0; i < web_match_rects.size(); ++i) |
| 4866 | match_rects.push_back(gfx::RectF(web_match_rects[i])); |
| 4867 | } |
| 4868 | |
| 4869 | gfx::RectF active_rect = main_frame->activeFindMatchRect(); |
| 4870 | Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_, |
| 4871 | rects_version, |
| 4872 | match_rects, |
| 4873 | active_rect)); |
| 4874 | } |
| 4875 | #endif |
| 4876 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4877 | void RenderViewImpl::OnZoom(PageZoom zoom) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4878 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4879 | return; |
| 4880 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 4881 | webview()->hidePopups(); |
[email protected] | 854ab546 | 2011-11-22 20:48:10 | [diff] [blame] | 4882 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4883 | double old_zoom_level = webview()->zoomLevel(); |
| 4884 | double zoom_level; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4885 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4886 | zoom_level = 0; |
| 4887 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 4888 | // Previous zoom level is a whole number, so just increment/decrement. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4889 | zoom_level = old_zoom_level + zoom; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4890 | } else { |
| 4891 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 4892 | // not a whole number, or a plugin changed it to a custom value. We want |
| 4893 | // to go to the next whole number so that the user can always get back to |
| 4894 | // 100% with the keyboard/menu. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4895 | if ((old_zoom_level > 1 && zoom > 0) || |
| 4896 | (old_zoom_level < 1 && zoom < 0)) { |
| 4897 | zoom_level = static_cast<int>(old_zoom_level + zoom); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4898 | } else { |
| 4899 | // We're going towards 100%, so first go to the next whole number. |
| 4900 | zoom_level = static_cast<int>(old_zoom_level); |
| 4901 | } |
| 4902 | } |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 4903 | webview()->setZoomLevel(zoom_level); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4904 | zoomLevelChanged(); |
| 4905 | } |
| 4906 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4907 | void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x, |
| 4908 | int zoom_center_y) { |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4909 | ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y, |
| 4910 | kScalingIncrementForGesture); |
| 4911 | } |
| 4912 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4913 | void RenderViewImpl::ZoomFactorHelper(PageZoom zoom, |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4914 | int zoom_center_x, |
| 4915 | int zoom_center_y, |
| 4916 | float scaling_increment) { |
| 4917 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4918 | return; |
| 4919 | |
[email protected] | c514d63 | 2011-08-16 22:54:44 | [diff] [blame] | 4920 | double old_page_scale_factor = webview()->pageScaleFactor(); |
| 4921 | double page_scale_factor; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4922 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | c514d63 | 2011-08-16 22:54:44 | [diff] [blame] | 4923 | page_scale_factor = 1.0; |
| 4924 | } else { |
| 4925 | page_scale_factor = old_page_scale_factor + |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4926 | (zoom > 0 ? scaling_increment : -scaling_increment); |
[email protected] | c514d63 | 2011-08-16 22:54:44 | [diff] [blame] | 4927 | } |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4928 | if (page_scale_factor > 0) { |
[email protected] | 8519136 | 2011-11-08 18:53:09 | [diff] [blame] | 4929 | webview()->setPageScaleFactor(page_scale_factor, |
| 4930 | WebPoint(zoom_center_x, zoom_center_y)); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4931 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4932 | } |
| 4933 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4934 | void RenderViewImpl::OnSetZoomLevel(double zoom_level) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 4935 | webview()->hidePopups(); |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 4936 | webview()->setZoomLevel(zoom_level); |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 4937 | zoomLevelChanged(); |
| 4938 | } |
| 4939 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4940 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 4941 | double zoom_level) { |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 4942 | #if !defined(OS_ANDROID) |
| 4943 | // On Android, page zoom isn't used, and in case of WebView, text zoom is used |
| 4944 | // for legacy WebView text scaling emulation. Thus, the code that resets |
| 4945 | // the zoom level from this map will be effectively resetting text zoom level. |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4946 | host_zoom_levels_[url] = zoom_level; |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 4947 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4948 | } |
| 4949 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4950 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4951 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4952 | } |
| 4953 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4954 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4955 | WebString no_encoding; |
| 4956 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4957 | } |
| 4958 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4959 | WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4960 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4961 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4962 | |
| 4963 | // xpath string can represent a frame deep down the tree (across multiple |
| 4964 | // frame DOMs). |
| 4965 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 4966 | // should break into 2 xpaths |
| 4967 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4968 | std::vector<string16> xpaths; |
| 4969 | base::SplitString(xpath, '\n', &xpaths); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4970 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4971 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4972 | for (std::vector<string16>::const_iterator i = xpaths.begin(); |
| 4973 | frame && i != xpaths.end(); ++i) { |
| 4974 | frame = frame->findChildByExpression(*i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4975 | } |
| 4976 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4977 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4978 | } |
| 4979 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4980 | void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, |
| 4981 | const string16& jscript, |
| 4982 | int id, |
| 4983 | bool notify_result) { |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 4984 | TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest", |
| 4985 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4986 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4987 | } |
| 4988 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4989 | void RenderViewImpl::OnPostMessageEvent( |
| 4990 | const ViewMsg_PostMessage_Params& params) { |
[email protected] | bf4a231 | 2013-04-23 00:32:11 | [diff] [blame] | 4991 | // TODO(nasko): Support sending to subframes. |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 4992 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4993 | |
| 4994 | // Find the source frame if it exists. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4995 | WebFrame* source_frame = NULL; |
| 4996 | if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 4997 | RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
| 4998 | if (source_view) |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 4999 | source_frame = source_view->webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5000 | } |
| 5001 | |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 5002 | // If the message contained MessagePorts, create the corresponding endpoints. |
| 5003 | DCHECK_EQ(params.message_port_ids.size(), params.new_routing_ids.size()); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5004 | blink::WebMessagePortChannelArray channels(params.message_port_ids.size()); |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 5005 | for (size_t i = 0; |
| 5006 | i < params.message_port_ids.size() && i < params.new_routing_ids.size(); |
| 5007 | ++i) { |
| 5008 | channels[i] = |
| 5009 | new WebMessagePortChannelImpl(params.new_routing_ids[i], |
| 5010 | params.message_port_ids[i], |
| 5011 | base::MessageLoopProxy::current().get()); |
| 5012 | } |
| 5013 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5014 | // Create an event with the message. The final parameter to initMessageEvent |
| 5015 | // is the last event ID, which is not used with postMessage. |
| 5016 | WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
| 5017 | WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 5018 | msg_event.initMessageEvent("message", |
| 5019 | // |canBubble| and |cancellable| are always false |
| 5020 | false, false, |
| 5021 | WebSerializedScriptValue::fromString(params.data), |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 5022 | params.source_origin, source_frame, "", channels); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5023 | |
| 5024 | // We must pass in the target_origin to do the security check on this side, |
| 5025 | // since it may have changed since the original postMessage call was made. |
| 5026 | WebSecurityOrigin target_origin; |
| 5027 | if (!params.target_origin.empty()) { |
| 5028 | target_origin = |
| 5029 | WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 5030 | } |
| 5031 | frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 5032 | } |
| 5033 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5034 | void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath, |
| 5035 | const std::string& css) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 5036 | WebFrame* frame = GetChildFrame(frame_xpath); |
| 5037 | if (!frame) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 5038 | return; |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 5039 | |
[email protected] | 01cf589c | 2011-07-28 18:04:03 | [diff] [blame] | 5040 | frame->document().insertUserStyleSheet( |
| 5041 | WebString::fromUTF8(css), |
| 5042 | WebDocument::UserStyleAuthorLevel); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 5043 | } |
| 5044 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5045 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 5046 | if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && |
| 5047 | !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { |
[email protected] | 91f0576 | 2013-08-21 02:55:09 | [diff] [blame] | 5048 | // WebUI uses <dialog> which is not yet enabled by default in Chrome. |
| 5049 | WebRuntimeFeatures::enableDialogElement(true); |
| 5050 | |
[email protected] | dcc72db | 2013-01-02 00:44:18 | [diff] [blame] | 5051 | RenderThread::Get()->RegisterExtension(WebUIExtension::Get()); |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 5052 | new WebUIExtensionData(this); |
| 5053 | } |
| 5054 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 5055 | enabled_bindings_ |= enabled_bindings_flags; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 5056 | |
| 5057 | // Keep track of the total bindings accumulated in this process. |
| 5058 | RenderProcess::current()->AddBindings(enabled_bindings_flags); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5059 | } |
| 5060 | |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 5061 | void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5062 | const gfx::Point& client_point, |
| 5063 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5064 | WebDragOperationsMask ops, |
| 5065 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5066 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 5067 | DropDataToWebDragData(drop_data), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5068 | client_point, |
| 5069 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5070 | ops, |
| 5071 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5072 | |
| 5073 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 5074 | } |
| 5075 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5076 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 5077 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5078 | WebDragOperationsMask ops, |
| 5079 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5080 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 5081 | client_point, |
| 5082 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5083 | ops, |
| 5084 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5085 | |
| 5086 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 5087 | } |
| 5088 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5089 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5090 | webview()->dragTargetDragLeave(); |
| 5091 | } |
| 5092 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5093 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5094 | const gfx::Point& screen_point, |
| 5095 | int key_modifiers) { |
| 5096 | webview()->dragTargetDrop(client_point, screen_point, key_modifiers); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 5097 | |
| 5098 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5099 | } |
| 5100 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5101 | void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 5102 | const gfx::Point& screen_point, |
| 5103 | bool ended, |
| 5104 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5105 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5106 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 5107 | } else { |
| 5108 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5109 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5110 | } |
| 5111 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5112 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5113 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5114 | } |
| 5115 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5116 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 5117 | webkit_preferences_ = prefs; |
[email protected] | 49a2000 | 2013-08-18 12:43:31 | [diff] [blame] | 5118 | ApplyWebPreferences(webkit_preferences_, webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5119 | } |
| 5120 | |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 5121 | void RenderViewImpl::OnUpdateTimezone() { |
| 5122 | if (webview()) |
| 5123 | NotifyTimezoneChange(webview()->mainFrame()); |
| 5124 | } |
| 5125 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5126 | void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5127 | alternate_error_page_url_ = url; |
| 5128 | } |
| 5129 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5130 | void RenderViewImpl::OnCustomContextMenuAction( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5131 | const CustomContextMenuContext& custom_context, |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5132 | unsigned action) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5133 | if (custom_context.request_id) { |
| 5134 | // External context menu request, look in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5135 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5136 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 5137 | if (client) |
| 5138 | client->OnMenuAction(custom_context.request_id, action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5139 | } else { |
| 5140 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5141 | webview()->performCustomContextMenuAction(action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5142 | } |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 5143 | } |
| 5144 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5145 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5146 | int id, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 5147 | const std::vector<base::FilePath>& paths) { |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5148 | if (!enumeration_completions_[id]) |
| 5149 | return; |
| 5150 | |
| 5151 | WebVector<WebString> ws_file_names(paths.size()); |
| 5152 | for (size_t i = 0; i < paths.size(); ++i) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5153 | ws_file_names[i] = paths[i].AsUTF16Unsafe(); |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5154 | |
| 5155 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 5156 | enumeration_completions_.erase(id); |
| 5157 | } |
| 5158 | |
[email protected] | fb11b6a4 | 2012-03-14 07:25:12 | [diff] [blame] | 5159 | void RenderViewImpl::OnFileChooserResponse( |
[email protected] | ddb034b | 2012-06-26 20:31:39 | [diff] [blame] | 5160 | const std::vector<ui::SelectedFileInfo>& files) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5161 | // This could happen if we navigated to a different page before the user |
| 5162 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5163 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5164 | return; |
| 5165 | |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5166 | // Convert Chrome's SelectedFileInfo list to WebKit's. |
| 5167 | WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files( |
| 5168 | files.size()); |
| 5169 | for (size_t i = 0; i < files.size(); ++i) { |
| 5170 | WebFileChooserCompletion::SelectedFileInfo selected_file; |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5171 | selected_file.path = files[i].local_path.AsUTF16Unsafe(); |
| 5172 | selected_file.displayName = |
| 5173 | base::FilePath(files[i].display_name).AsUTF16Unsafe(); |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5174 | selected_files[i] = selected_file; |
| 5175 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 5176 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5177 | if (file_chooser_completions_.front()->completion) |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5178 | file_chooser_completions_.front()->completion->didChooseFile( |
| 5179 | selected_files); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5180 | file_chooser_completions_.pop_front(); |
| 5181 | |
| 5182 | // If there are more pending file chooser requests, schedule one now. |
| 5183 | if (!file_chooser_completions_.empty()) { |
| 5184 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 5185 | file_chooser_completions_.front()->params)); |
| 5186 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5187 | } |
| 5188 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5189 | void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
| 5190 | const gfx::Size& max_size) { |
| 5191 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5192 | if (!webview()) |
| 5193 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 5194 | auto_resize_mode_ = true; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5195 | webview()->enableAutoResizeMode(min_size, max_size); |
| 5196 | } |
| 5197 | |
| 5198 | void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) { |
| 5199 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5200 | if (!webview()) |
| 5201 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 5202 | auto_resize_mode_ = false; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5203 | webview()->disableAutoResizeMode(); |
| 5204 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 5205 | if (!new_size.IsEmpty()) { |
| 5206 | Resize(new_size, |
| 5207 | physical_backing_size_, |
| 5208 | overdraw_bottom_height_, |
| 5209 | resizer_rect_, |
| 5210 | is_fullscreen_, |
| 5211 | NO_RESIZE_ACK); |
| 5212 | } |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5213 | } |
| 5214 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 5215 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5216 | if (send_preferred_size_changes_) |
| 5217 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5218 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 5219 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5220 | // Start off with an initial preferred size notification (in case |
| 5221 | // |didUpdateLayout| was already called). |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 5222 | didUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 5223 | } |
| 5224 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5225 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5226 | const gfx::Size& disable_scrollbar_size_limit) { |
| 5227 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 5228 | } |
| 5229 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5230 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5231 | const RendererPreferences& renderer_prefs) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5232 | double old_zoom_level = renderer_preferences_.default_zoom_level; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5233 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 5234 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5235 | |
| 5236 | #if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5237 | if (renderer_prefs.use_custom_colors) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5238 | WebColorName name = blink::WebColorWebkitFocusRingColor; |
| 5239 | blink::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
| 5240 | blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5241 | #if defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5242 | ui::NativeTheme::instance()->SetScrollbarColors( |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 5243 | renderer_prefs.thumb_inactive_color, |
| 5244 | renderer_prefs.thumb_active_color, |
| 5245 | renderer_prefs.track_color); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5246 | #endif // defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5247 | |
| 5248 | if (webview()) { |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5249 | webview()->setSelectionColors( |
| 5250 | renderer_prefs.active_selection_bg_color, |
| 5251 | renderer_prefs.active_selection_fg_color, |
| 5252 | renderer_prefs.inactive_selection_bg_color, |
| 5253 | renderer_prefs.inactive_selection_fg_color); |
| 5254 | webview()->themeChanged(); |
| 5255 | } |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5256 | } |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5257 | #endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5258 | |
[email protected] | 107c053 | 2013-02-06 02:34:09 | [diff] [blame] | 5259 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 5260 | RenderThreadImpl::current()->SetFlingCurveParameters( |
| 5261 | renderer_prefs.touchpad_fling_profile, |
| 5262 | renderer_prefs.touchscreen_fling_profile); |
| 5263 | |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5264 | // If the zoom level for this page matches the old zoom default, and this |
| 5265 | // is not a plugin, update the zoom level to match the new default. |
| 5266 | if (webview() && !webview()->mainFrame()->document().isPluginDocument() && |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 5267 | !ZoomValuesEqual(old_zoom_level, |
| 5268 | renderer_preferences_.default_zoom_level) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5269 | ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) { |
[email protected] | 9121970 | 2013-09-18 07:33:51 | [diff] [blame] | 5270 | webview()->setZoomLevel(renderer_preferences_.default_zoom_level); |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5271 | zoomLevelChanged(); |
| 5272 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5273 | } |
| 5274 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5275 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 5276 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 5277 | if (webview()) |
| 5278 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 5279 | } |
| 5280 | |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 5281 | void RenderViewImpl::OnOrientationChangeEvent(int orientation) { |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 5282 | // Screen has rotated. 0 = default (portrait), 90 = one turn right, and so on. |
[email protected] | 652ad83 | 2013-08-16 11:47:04 | [diff] [blame] | 5283 | FOR_EACH_OBSERVER(RenderViewObserver, |
| 5284 | observers_, |
| 5285 | OrientationChangeEvent(orientation)); |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 5286 | webview()->mainFrame()->sendOrientationChangeEvent(orientation); |
| 5287 | } |
| 5288 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 5289 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 5290 | const WebPluginAction& action) { |
| 5291 | if (webview()) |
| 5292 | webview()->performPluginAction(action, location); |
| 5293 | } |
| 5294 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5295 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5296 | const GURL& page_url) { |
| 5297 | // Prepare list to storage all savable resource links. |
| 5298 | std::vector<GURL> resources_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5299 | std::vector<GURL> referrer_urls_list; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5300 | std::vector<blink::WebReferrerPolicy> referrer_policies_list; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5301 | std::vector<GURL> frames_list; |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 5302 | SavableResourcesResult result(&resources_list, |
| 5303 | &referrer_urls_list, |
| 5304 | &referrer_policies_list, |
| 5305 | &frames_list); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5306 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5307 | // webkit/ doesn't know about Referrer. |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 5308 | if (!GetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5309 | webview(), |
| 5310 | page_url, |
| 5311 | &result, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5312 | const_cast<const char**>(GetSavableSchemes()))) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5313 | // If something is wrong when collecting all savable resource links, |
| 5314 | // send empty list to embedder(browser) to tell it failed. |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5315 | referrer_urls_list.clear(); |
| 5316 | referrer_policies_list.clear(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5317 | resources_list.clear(); |
| 5318 | frames_list.clear(); |
| 5319 | } |
| 5320 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5321 | std::vector<Referrer> referrers_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5322 | CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size()); |
| 5323 | for (unsigned i = 0; i < referrer_urls_list.size(); ++i) { |
| 5324 | referrers_list.push_back( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5325 | Referrer(referrer_urls_list[i], referrer_policies_list[i])); |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5326 | } |
| 5327 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5328 | // Send result of all savable resource links to embedder. |
| 5329 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 5330 | resources_list, |
| 5331 | referrers_list, |
| 5332 | frames_list)); |
| 5333 | } |
| 5334 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5335 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5336 | const std::vector<GURL>& links, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 5337 | const std::vector<base::FilePath>& local_paths, |
| 5338 | const base::FilePath& local_directory_name) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5339 | |
| 5340 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 5341 | WebVector<WebURL> weburl_links(links); |
| 5342 | |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5343 | // Convert std::vector of base::FilePath to WebVector<WebString> |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5344 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 5345 | for (size_t i = 0; i < local_paths.size(); i++) |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5346 | webstring_paths[i] = local_paths[i].AsUTF16Unsafe(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5347 | |
| 5348 | WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links, |
| 5349 | webstring_paths, |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 5350 | local_directory_name.AsUTF16Unsafe()); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5351 | } |
| 5352 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5353 | void RenderViewImpl::OnShouldClose() { |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5354 | base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5355 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5356 | base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); |
| 5357 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, |
| 5358 | before_unload_start_time, |
| 5359 | before_unload_end_time)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5360 | } |
| 5361 | |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 5362 | void RenderViewImpl::OnSuppressDialogsUntilSwapOut() { |
| 5363 | // Don't show any more dialogs until we finish OnSwapOut. |
| 5364 | suppress_dialogs_until_swap_out_ = true; |
| 5365 | } |
| 5366 | |
[email protected] | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 5367 | void RenderViewImpl::OnSwapOut() { |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5368 | // Only run unload if we're not swapped out yet, but send the ack either way. |
| 5369 | if (!is_swapped_out_) { |
| 5370 | // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 5371 | // different process. This involves running the unload handler and clearing |
| 5372 | // the page. Once WasSwappedOut is called, we also allow this process to |
| 5373 | // exit if there are no other active RenderViews in it. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5374 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5375 | // Send an UpdateState message before we get swapped out. |
| 5376 | SyncNavigationState(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5377 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5378 | // Synchronously run the unload handler before sending the ACK. |
| 5379 | webview()->dispatchUnloadEvent(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5380 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5381 | // Swap out and stop sending any IPC messages that are not ACKs. |
| 5382 | SetSwappedOut(true); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5383 | |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 5384 | // Now that we're swapped out and filtering IPC messages, stop loading to |
| 5385 | // ensure that no other in-progress navigation continues. We do this here |
| 5386 | // to avoid sending a DidStopLoading message to the browser process. |
| 5387 | OnStop(); |
| 5388 | |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 5389 | // Replace the page with a blank dummy URL. The unload handler will not be |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5390 | // run a second time, thanks to a check in FrameLoader::stopLoading. |
| 5391 | // TODO(creis): Need to add a better way to do this that avoids running the |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 5392 | // beforeunload handler. For now, we just run it a second time silently. |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5393 | NavigateToSwappedOutURL(webview()->mainFrame()); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 5394 | |
| 5395 | // Let WebKit know that this view is hidden so it can drop resources and |
| 5396 | // stop compositing. |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5397 | webview()->setVisibilityState(blink::WebPageVisibilityStateHidden, false); |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5398 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5399 | |
[email protected] | 88f10a2 | 2013-11-06 21:22:12 | [diff] [blame] | 5400 | // It is now safe to show modal dialogs again. |
| 5401 | suppress_dialogs_until_swap_out_ = false; |
| 5402 | |
[email protected] | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 5403 | Send(new ViewHostMsg_SwapOut_ACK(routing_id_)); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5404 | } |
| 5405 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5406 | void RenderViewImpl::NavigateToSwappedOutURL(blink::WebFrame* frame) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5407 | // We use loadRequest instead of loadHTMLString because the former commits |
| 5408 | // synchronously. Otherwise a new navigation can interrupt the navigation |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5409 | // to kSwappedOutURL. If that happens to be to the page we had been |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5410 | // showing, then WebKit will never send a commit and we'll be left spinning. |
[email protected] | 890b06ca | 2012-12-13 21:07:36 | [diff] [blame] | 5411 | CHECK(is_swapped_out_); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5412 | GURL swappedOutURL(kSwappedOutURL); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5413 | WebURLRequest request(swappedOutURL); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5414 | frame->loadRequest(request); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5415 | } |
| 5416 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5417 | void RenderViewImpl::OnClosePage() { |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 5418 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5419 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 5420 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 5421 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 5422 | // calling the FrameLoader's CloseURL method directly. This should be |
| 5423 | // revisited to avoid having two ways to close a page. Having a single way |
| 5424 | // to close that can run onunload is also useful for fixing |
| 5425 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5426 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5427 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5428 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5429 | } |
| 5430 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5431 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 5432 | #if defined(USE_AURA) |
| 5433 | // Aura doesn't care if we switch themes. |
| 5434 | #elif defined(OS_WIN) |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 5435 | ui::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 5436 | if (webview()) |
| 5437 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 5438 | #else // defined(OS_WIN) |
| 5439 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 5440 | NOTIMPLEMENTED(); |
| 5441 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5442 | } |
| 5443 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5444 | bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 5445 | const WebURLError& error, |
| 5446 | bool replace) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5447 | // We only show alternate error pages in the main frame. They are |
| 5448 | // intended to assist the user when navigating, so there is not much |
| 5449 | // value in showing them for failed subframes. Ideally, we would be |
| 5450 | // able to use the TYPED transition type for this, but that flag is |
| 5451 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5452 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5453 | return false; |
| 5454 | |
| 5455 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 5456 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5457 | int ec = error.reason; |
| 5458 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 5459 | ec != net::ERR_CONNECTION_FAILED && |
| 5460 | ec != net::ERR_CONNECTION_REFUSED && |
| 5461 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5462 | ec != net::ERR_CONNECTION_TIMED_OUT) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5463 | return false; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5464 | } |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5465 | |
| 5466 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5467 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5468 | if (!error_page_url.is_valid()) |
| 5469 | return false; |
| 5470 | |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5471 | WebDataSource* ds = frame->provisionalDataSource(); |
| 5472 | const WebURLRequest& failed_request = ds->request(); |
| 5473 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5474 | // Load an empty page first so there is an immediate response to the error, |
| 5475 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5476 | frame->loadHTMLString(std::string(), |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5477 | GURL(kUnreachableWebDataURL), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5478 | error.unreachableURL, |
| 5479 | replace); |
| 5480 | |
| 5481 | // Now, create a fetcher for the error page and associate it with the data |
| 5482 | // source we just created via the LoadHTMLString call. That way if another |
| 5483 | // navigation occurs, the fetcher will get destroyed. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 5484 | InternalDocumentStateData* internal_data = |
| 5485 | InternalDocumentStateData::FromDataSource(frame->provisionalDataSource()); |
| 5486 | internal_data->set_alt_error_page_fetcher( |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5487 | new AltErrorPageResourceFetcher( |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5488 | error_page_url, frame, failed_request, error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 5489 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 5490 | base::Unretained(this)))); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5491 | return true; |
| 5492 | } |
| 5493 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5494 | void RenderViewImpl::AltErrorPageFinished(WebFrame* frame, |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5495 | const WebURLRequest& original_request, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5496 | const WebURLError& original_error, |
| 5497 | const std::string& html) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5498 | // Here, we replace the blank page we loaded previously. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 5499 | // If we failed to download the alternate error page, LoadNavigationErrorPage |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5500 | // will simply display a default error page. |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5501 | LoadNavigationErrorPage(frame, original_request, original_error, html, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5502 | } |
| 5503 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5504 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5505 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5506 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5507 | } |
| 5508 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5509 | void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5510 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5511 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5512 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 5513 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5514 | ShouldDisplayScrollbars(params.new_size.width(), |
| 5515 | params.new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5516 | } |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 5517 | UpdateScrollState(webview()->mainFrame()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5518 | } |
| 5519 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5520 | RenderWidget::OnResize(params); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5521 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 5522 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5523 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5524 | #if defined(ENABLE_PLUGINS) |
| 5525 | // Notify all instances that we painted. The same caveats apply as for |
| 5526 | // ViewFlushedPaint regarding instances closing themselves, so we take |
| 5527 | // similar precautions. |
| 5528 | PepperPluginSet plugins = active_pepper_instances_; |
| 5529 | for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) { |
| 5530 | if (active_pepper_instances_.find(*i) != active_pepper_instances_.end()) |
| 5531 | (*i)->ViewInitiatedPaint(); |
| 5532 | } |
| 5533 | #endif |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5534 | } |
| 5535 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5536 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5537 | #if defined(ENABLE_PLUGINS) |
| 5538 | // Notify all instances that we flushed. This will call into the plugin, and |
| 5539 | // we it may ask to close itself as a result. This will, in turn, modify our |
| 5540 | // set, possibly invalidating the iterator. So we iterate on a copy that |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5541 | // won't change out from under us. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5542 | PepperPluginSet plugins = active_pepper_instances_; |
| 5543 | for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) { |
| 5544 | // The copy above makes sure our iterator is never invalid if some plugins |
| 5545 | // are destroyed. But some plugin may decide to close all of its views in |
| 5546 | // response to a paint in one of them, so we need to make sure each one is |
| 5547 | // still "current" before using it. |
| 5548 | // |
| 5549 | // It's possible that a plugin was destroyed, but another one was created |
| 5550 | // with the same address. In this case, we'll call ViewFlushedPaint on that |
| 5551 | // new plugin. But that's OK for this particular case since we're just |
| 5552 | // notifying all of our instances that the view flushed, and the new one is |
| 5553 | // one of our instances. |
| 5554 | // |
| 5555 | // What about the case where a new one is created in a callback at a new |
| 5556 | // address and we don't issue the callback? We're still OK since this |
| 5557 | // callback is used for flush callbacks and we could not have possibly |
[email protected] | 0704ac3 | 2013-10-03 15:24:22 | [diff] [blame] | 5558 | // started a new paint for the new plugin while processing a previous paint |
| 5559 | // for an existing one. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5560 | if (active_pepper_instances_.find(*i) != active_pepper_instances_.end()) |
| 5561 | (*i)->ViewFlushedPaint(); |
| 5562 | } |
| 5563 | #endif |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 5564 | |
[email protected] | 5b1dec8c | 2012-02-07 04:35:38 | [diff] [blame] | 5565 | // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 5566 | // See crbug.com/112921. |
| 5567 | if (!webview()) |
| 5568 | return; |
| 5569 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5570 | WebFrame* main_frame = webview()->mainFrame(); |
| 5571 | |
| 5572 | // If we have a provisional frame we are between the start and commit stages |
| 5573 | // of loading and we don't want to save stats. |
| 5574 | if (!main_frame->provisionalDataSource()) { |
| 5575 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5576 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 5577 | InternalDocumentStateData* data = |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 5578 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 5579 | if (data->did_first_visually_non_empty_layout() && |
| 5580 | !data->did_first_visually_non_empty_paint()) { |
| 5581 | data->set_did_first_visually_non_empty_paint(true); |
| 5582 | Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_, |
| 5583 | page_id_)); |
| 5584 | } |
| 5585 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5586 | // TODO(jar): The following code should all be inside a method, probably in |
| 5587 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5588 | Time now = Time::Now(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5589 | if (document_state->first_paint_time().is_null()) { |
| 5590 | document_state->set_first_paint_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5591 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5592 | if (document_state->first_paint_after_load_time().is_null() && |
| 5593 | !document_state->finish_load_time().is_null()) { |
| 5594 | document_state->set_first_paint_after_load_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5595 | } |
| 5596 | } |
| 5597 | } |
| 5598 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 5599 | PepperPluginInstanceImpl* RenderViewImpl::GetBitmapForOptimizedPluginPaint( |
| 5600 | const gfx::Rect& paint_bounds, |
| 5601 | TransportDIB** dib, |
| 5602 | gfx::Rect* location, |
| 5603 | gfx::Rect* clip, |
| 5604 | float* scale_factor) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5605 | #if defined(ENABLE_PLUGINS) |
| 5606 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 5607 | i != active_pepper_instances_.end(); ++i) { |
| 5608 | PepperPluginInstanceImpl* instance = *i; |
| 5609 | // In Flash fullscreen , the plugin contents should be painted onto the |
| 5610 | // fullscreen widget instead of the web page. |
| 5611 | if (!instance->FlashIsFullscreenOrPending() && |
| 5612 | instance->GetBitmapForOptimizedPluginPaint(paint_bounds, dib, location, |
| 5613 | clip, scale_factor)) |
| 5614 | return *i; |
| 5615 | } |
| 5616 | #endif |
| 5617 | return NULL; |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5618 | } |
| 5619 | |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5620 | gfx::Vector2d RenderViewImpl::GetScrollOffset() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5621 | WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5622 | return gfx::Vector2d(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 5623 | } |
| 5624 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5625 | void RenderViewImpl::OnClearFocusedNode() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5626 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5627 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5628 | } |
| 5629 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5630 | void RenderViewImpl::OnSetBackground(const SkBitmap& background) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5631 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5632 | webview()->setIsTransparent(!background.empty()); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 5633 | if (compositor_) |
| 5634 | compositor_->setHasTransparentBackground(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5635 | |
| 5636 | SetBackground(background); |
| 5637 | } |
| 5638 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5639 | void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) { |
| 5640 | if (accessibility_mode_ == new_mode) |
| 5641 | return; |
| 5642 | accessibility_mode_ = new_mode; |
| 5643 | if (renderer_accessibility_) { |
| 5644 | delete renderer_accessibility_; |
| 5645 | renderer_accessibility_ = NULL; |
| 5646 | } |
| 5647 | if (accessibility_mode_ == AccessibilityModeComplete) |
| 5648 | renderer_accessibility_ = new RendererAccessibilityComplete(this); |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 5649 | #if !defined(OS_ANDROID) |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5650 | else if (accessibility_mode_ == AccessibilityModeEditableTextOnly) |
| 5651 | renderer_accessibility_ = new RendererAccessibilityFocusOnly(this); |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 5652 | #endif |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5653 | } |
| 5654 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5655 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5656 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5657 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 5658 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5659 | #if defined(ENABLE_PLUGINS) && defined(OS_MACOSX) |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 5660 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5661 | for (plugin_it = plugin_delegates_.begin(); |
| 5662 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5663 | (*plugin_it)->SetWindowFocus(active); |
| 5664 | } |
| 5665 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5666 | } |
| 5667 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5668 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5669 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5670 | #if defined(ENABLE_PLUGINS) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5671 | // Inform plugins that their container has changed visibility. |
| 5672 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5673 | for (plugin_it = plugin_delegates_.begin(); |
| 5674 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5675 | (*plugin_it)->SetContainerVisibility(visible); |
| 5676 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5677 | #endif |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5678 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5679 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5680 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 5681 | const gfx::Rect& view_frame) { |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5682 | #if defined(ENABLE_PLUGINS) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5683 | // Inform plugins that their window's frame has changed. |
| 5684 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5685 | for (plugin_it = plugin_delegates_.begin(); |
| 5686 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5687 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 5688 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5689 | #endif |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5690 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5691 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5692 | void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text, |
| 5693 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5694 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5695 | // applies to it or not, so inform all the delegates. |
| 5696 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5697 | for (plugin_it = plugin_delegates_.begin(); |
| 5698 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5699 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5700 | } |
| 5701 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5702 | #endif // OS_MACOSX |
| 5703 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5704 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5705 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5706 | WebView* doomed = webview(); |
| 5707 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 5708 | g_view_map.Get().erase(doomed); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 5709 | g_routing_id_view_map.Get().erase(routing_id_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5710 | } |
| 5711 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5712 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 5713 | ClearEditCommands(); |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5714 | } |
| 5715 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5716 | bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent& event) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 5717 | context_menu_source_type_ = ui::MENU_SOURCE_MOUSE; |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5718 | possible_drag_event_info_.event_source = |
| 5719 | ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 5720 | possible_drag_event_info_.event_location = |
| 5721 | gfx::Point(event.globalX, event.globalY); |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5722 | |
| 5723 | #if defined(ENABLE_PLUGINS) |
| 5724 | // This method is called for every mouse event that the render view receives. |
| 5725 | // And then the mouse event is forwarded to WebKit, which dispatches it to the |
| 5726 | // event target. Potentially a Pepper plugin will receive the event. |
| 5727 | // In order to tell whether a plugin gets the last mouse event and which it |
| 5728 | // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets |
| 5729 | // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 5730 | // |pepper_last_mouse_event_target_|. |
| 5731 | pepper_last_mouse_event_target_ = NULL; |
| 5732 | #endif |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 5733 | |
| 5734 | // If the mouse is locked, only the current owner of the mouse lock can |
| 5735 | // process mouse events. |
| 5736 | return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 5737 | } |
| 5738 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5739 | bool RenderViewImpl::WillHandleKeyEvent(const blink::WebKeyboardEvent& event) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 5740 | context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD; |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 5741 | return false; |
| 5742 | } |
| 5743 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5744 | bool RenderViewImpl::WillHandleGestureEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5745 | const blink::WebGestureEvent& event) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 5746 | context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5747 | possible_drag_event_info_.event_source = |
| 5748 | ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH; |
| 5749 | possible_drag_event_info_.event_location = |
| 5750 | gfx::Point(event.globalX, event.globalY); |
| 5751 | return false; |
| 5752 | } |
| 5753 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 5754 | void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 5755 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5756 | } |
| 5757 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5758 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 5759 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 5760 | } |
| 5761 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 5762 | bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const { |
| 5763 | if (!webview()) |
| 5764 | return false; |
| 5765 | return webview()->hasTouchEventHandlersAt(point); |
| 5766 | } |
| 5767 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5768 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5769 | RenderWidget::OnWasHidden(); |
| 5770 | |
[email protected] | 68877c28 | 2013-09-20 05:52:42 | [diff] [blame] | 5771 | #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 5772 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 5773 | SuspendDevices(true); |
| 5774 | #endif |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 5775 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 5776 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5777 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5778 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5779 | #if defined(ENABLE_PLUGINS) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5780 | // Inform PPAPI plugins that their page is no longer visible. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5781 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 5782 | i != active_pepper_instances_.end(); ++i) |
| 5783 | (*i)->PageVisibilityChanged(false); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5784 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5785 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5786 | // Inform NPAPI plugins that their container is no longer visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5787 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5788 | for (plugin_it = plugin_delegates_.begin(); |
| 5789 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5790 | (*plugin_it)->SetContainerVisibility(false); |
| 5791 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5792 | #endif // OS_MACOSX |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5793 | #endif // ENABLE_PLUGINS |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5794 | } |
| 5795 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 5796 | void RenderViewImpl::OnWasShown(bool needs_repainting) { |
| 5797 | RenderWidget::OnWasShown(needs_repainting); |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5798 | |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 5799 | #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 5800 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 5801 | SuspendDevices(false); |
| 5802 | #endif |
| 5803 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 5804 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5805 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5806 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5807 | #if defined(ENABLE_PLUGINS) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5808 | // Inform PPAPI plugins that their page is visible. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5809 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 5810 | i != active_pepper_instances_.end(); ++i) |
| 5811 | (*i)->PageVisibilityChanged(true); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5812 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5813 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5814 | // Inform NPAPI plugins that their container is now visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5815 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5816 | for (plugin_it = plugin_delegates_.begin(); |
| 5817 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5818 | (*plugin_it)->SetContainerVisibility(true); |
| 5819 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5820 | #endif // OS_MACOSX |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5821 | #endif // ENABLE_PLUGINS |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5822 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5823 | |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 5824 | GURL RenderViewImpl::GetURLForGraphicsContext3D() { |
| 5825 | DCHECK(webview()); |
| 5826 | if (webview()->mainFrame()) |
| 5827 | return GURL(webview()->mainFrame()->document().url()); |
| 5828 | else |
| 5829 | return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5830 | } |
| 5831 | |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 5832 | bool RenderViewImpl::ForceCompositingModeEnabled() { |
| 5833 | return webkit_preferences_.force_compositing_mode; |
| 5834 | } |
| 5835 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5836 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5837 | RenderWidget::OnSetFocus(enable); |
| 5838 | |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5839 | #if defined(ENABLE_PLUGINS) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5840 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5841 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5842 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5843 | for (plugin_it = plugin_delegates_.begin(); |
| 5844 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5845 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5846 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5847 | // activation state to change just like a call to setIsActive. |
| 5848 | if (enable) |
| 5849 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5850 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5851 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5852 | } |
| 5853 | } |
[email protected] | a01da568 | 2012-06-30 00:37:31 | [diff] [blame] | 5854 | // Notify all Pepper plugins. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5855 | for (PepperPluginSet::iterator i = active_pepper_instances_.begin(); |
| 5856 | i != active_pepper_instances_.end(); ++i) |
| 5857 | (*i)->SetContentAreaFocus(enable); |
| 5858 | #endif |
[email protected] | 32103299 | 2012-11-08 01:01:27 | [diff] [blame] | 5859 | // Notify all BrowserPlugins of the RenderView's focus state. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 5860 | if (browser_plugin_manager_.get()) |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 5861 | browser_plugin_manager_->UpdateFocusState(); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5862 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5863 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5864 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5865 | const string16& text, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5866 | const std::vector<blink::WebCompositionUnderline>& underlines, |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5867 | int selection_start, |
| 5868 | int selection_end) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5869 | #if defined(ENABLE_PLUGINS) |
| 5870 | if (focused_pepper_plugin_) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5871 | // When a PPAPI plugin has focus, we bypass WebKit. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5872 | if (!IsPepperAcceptingCompositionEvents()) { |
| 5873 | pepper_composition_text_ = text; |
| 5874 | } else { |
| 5875 | // TODO(kinaba) currently all composition events are sent directly to |
| 5876 | // plugins. Use DOM event mechanism after WebKit is made aware about |
| 5877 | // plugins that support composition. |
| 5878 | // The code below mimics the behavior of WebCore::Editor::setComposition. |
| 5879 | |
| 5880 | // Empty -> nonempty: composition started. |
| 5881 | if (pepper_composition_text_.empty() && !text.empty()) |
| 5882 | focused_pepper_plugin_->HandleCompositionStart(string16()); |
| 5883 | // Nonempty -> empty: composition canceled. |
| 5884 | if (!pepper_composition_text_.empty() && text.empty()) |
| 5885 | focused_pepper_plugin_->HandleCompositionEnd(string16()); |
| 5886 | pepper_composition_text_ = text; |
| 5887 | // Nonempty: composition is ongoing. |
| 5888 | if (!pepper_composition_text_.empty()) { |
| 5889 | focused_pepper_plugin_->HandleCompositionUpdate( |
| 5890 | pepper_composition_text_, underlines, selection_start, |
| 5891 | selection_end); |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5892 | } |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5893 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5894 | return; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5895 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5896 | |
| 5897 | #if defined(OS_WIN) |
| 5898 | // When a plug-in has focus, we create platform-specific IME data used by |
| 5899 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 5900 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 5901 | // instance ID is the same one as the specified ID.) |
| 5902 | if (focused_plugin_id_ >= 0) { |
| 5903 | std::vector<int> clauses; |
| 5904 | std::vector<int> target; |
| 5905 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 5906 | clauses.push_back(underlines[i].startOffset); |
| 5907 | clauses.push_back(underlines[i].endOffset); |
| 5908 | if (underlines[i].thick) { |
| 5909 | target.clear(); |
| 5910 | target.push_back(underlines[i].startOffset); |
| 5911 | target.push_back(underlines[i].endOffset); |
| 5912 | } |
| 5913 | } |
| 5914 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5915 | for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) { |
| 5916 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 5917 | focused_plugin_id_); |
| 5918 | } |
| 5919 | return; |
| 5920 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5921 | #endif // OS_WIN |
| 5922 | #endif // ENABLE_PLUGINS |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5923 | RenderWidget::OnImeSetComposition(text, |
| 5924 | underlines, |
| 5925 | selection_start, |
| 5926 | selection_end); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5927 | } |
| 5928 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 5929 | void RenderViewImpl::OnImeConfirmComposition( |
| 5930 | const string16& text, |
| 5931 | const gfx::Range& replacement_range, |
| 5932 | bool keep_selection) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5933 | #if defined(ENABLE_PLUGINS) |
| 5934 | if (focused_pepper_plugin_) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5935 | // When a PPAPI plugin has focus, we bypass WebKit. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5936 | // Here, text.empty() has a special meaning. It means to commit the last |
| 5937 | // update of composition text (see |
| 5938 | // RenderWidgetHost::ImeConfirmComposition()). |
| 5939 | const string16& last_text = text.empty() ? pepper_composition_text_ : text; |
| 5940 | |
| 5941 | // last_text is empty only when both text and pepper_composition_text_ is. |
| 5942 | // Ignore it. |
| 5943 | if (last_text.empty()) |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5944 | return; |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5945 | |
| 5946 | if (!IsPepperAcceptingCompositionEvents()) { |
[email protected] | 28fccb3 | 2013-08-29 22:25:46 | [diff] [blame] | 5947 | base::i18n::UTF16CharIterator iterator(&last_text); |
| 5948 | int32 i = 0; |
| 5949 | while (iterator.Advance()) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 5950 | blink::WebKeyboardEvent char_event; |
| 5951 | char_event.type = blink::WebInputEvent::Char; |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5952 | char_event.timeStampSeconds = base::Time::Now().ToDoubleT(); |
| 5953 | char_event.modifiers = 0; |
| 5954 | char_event.windowsKeyCode = last_text[i]; |
| 5955 | char_event.nativeKeyCode = last_text[i]; |
[email protected] | 28fccb3 | 2013-08-29 22:25:46 | [diff] [blame] | 5956 | |
| 5957 | const int32 char_start = i; |
| 5958 | for (; i < iterator.array_pos(); ++i) { |
| 5959 | char_event.text[i - char_start] = last_text[i]; |
| 5960 | char_event.unmodifiedText[i - char_start] = last_text[i]; |
| 5961 | } |
| 5962 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5963 | if (webwidget()) |
| 5964 | webwidget()->handleInputEvent(char_event); |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5965 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5966 | } else { |
| 5967 | // Mimics the order of events sent by WebKit. |
| 5968 | // See WebCore::Editor::setComposition() for the corresponding code. |
| 5969 | focused_pepper_plugin_->HandleCompositionEnd(last_text); |
| 5970 | focused_pepper_plugin_->HandleTextInput(last_text); |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5971 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5972 | pepper_composition_text_.clear(); |
| 5973 | return; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5974 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5975 | #if defined(OS_WIN) |
| 5976 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 5977 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 5978 | // it to WebKit to prevent WebKit from controlling IMEs. |
| 5979 | // TODO(thakis): Honor |replacement_range| for plugins? |
| 5980 | if (focused_plugin_id_ >= 0) { |
| 5981 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5982 | for (it = plugin_delegates_.begin(); |
| 5983 | it != plugin_delegates_.end(); ++it) { |
| 5984 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 5985 | } |
| 5986 | return; |
| 5987 | } |
[email protected] | a80af12e | 2013-08-07 23:36:13 | [diff] [blame] | 5988 | #endif // OS_WIN |
| 5989 | #endif // ENABLE_PLUGINS |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 5990 | if (replacement_range.IsValid() && webview()) { |
| 5991 | // Select the text in |replacement_range|, it will then be replaced by |
| 5992 | // text added by the call to RenderWidget::OnImeConfirmComposition(). |
| 5993 | if (WebFrame* frame = webview()->focusedFrame()) { |
| 5994 | WebRange webrange = WebRange::fromDocumentRange( |
| 5995 | frame, replacement_range.start(), replacement_range.length()); |
| 5996 | if (!webrange.isNull()) |
| 5997 | frame->selectRange(webrange); |
| 5998 | } |
| 5999 | } |
| 6000 | RenderWidget::OnImeConfirmComposition(text, |
| 6001 | replacement_range, |
| 6002 | keep_selection); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 6003 | } |
| 6004 | |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 6005 | void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) { |
| 6006 | RenderWidget::SetDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 6007 | if (webview()) { |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 6008 | webview()->setDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 6009 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 6010 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | c162ced8 | 2013-06-29 01:24:53 | [diff] [blame] | 6011 | webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled( |
| 6012 | ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_)); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 6013 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 6014 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | 06fc4d3b | 2013-07-08 21:07:24 | [diff] [blame] | 6015 | webview()->settings()-> |
| 6016 | setAcceleratedCompositingForFixedRootBackgroundEnabled( |
| 6017 | ShouldUseAcceleratedFixedRootBackground(device_scale_factor_)); |
[email protected] | e341590 | 2013-10-17 15:00:46 | [diff] [blame] | 6018 | webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled( |
| 6019 | ShouldUseAcceleratedCompositingForScrollableFrames( |
| 6020 | device_scale_factor_)); |
| 6021 | webview()->settings()->setCompositedScrollingForFramesEnabled( |
| 6022 | ShouldUseCompositedScrollingForFrames(device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 6023 | } |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 6024 | if (auto_resize_mode_) |
| 6025 | AutoResizeCompositor(); |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 6026 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 6027 | if (browser_plugin_manager_.get()) |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 6028 | browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_); |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 6029 | } |
| 6030 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6031 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6032 | #if defined(ENABLE_PLUGINS) |
| 6033 | if (focused_pepper_plugin_) |
| 6034 | return focused_pepper_plugin_->text_input_type(); |
| 6035 | #endif |
| 6036 | return RenderWidget::GetTextInputType(); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 6037 | } |
| 6038 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 6039 | void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6040 | #if defined(ENABLE_PLUGINS) |
| 6041 | if (focused_pepper_plugin_) { |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 6042 | // TODO(kinaba) http://crbug.com/101101 |
| 6043 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 6044 | // use the caret position as an empty range for now. It will be updated |
| 6045 | // after Pepper API equips features related to surrounding text retrieval. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6046 | gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds(); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 6047 | *start = caret; |
| 6048 | *end = caret; |
| 6049 | return; |
| 6050 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6051 | #endif |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 6052 | RenderWidget::GetSelectionBounds(start, end); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 6053 | } |
| 6054 | |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 6055 | #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA) |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 6056 | void RenderViewImpl::GetCompositionCharacterBounds( |
| 6057 | std::vector<gfx::Rect>* bounds) { |
| 6058 | DCHECK(bounds); |
| 6059 | bounds->clear(); |
| 6060 | |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6061 | #if defined(ENABLE_PLUGINS) |
| 6062 | if (focused_pepper_plugin_) { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 6063 | return; |
| 6064 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6065 | #endif |
| 6066 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 6067 | if (!webview()) |
| 6068 | return; |
| 6069 | size_t start_offset = 0; |
| 6070 | size_t character_count = 0; |
| 6071 | if (!webview()->compositionRange(&start_offset, &character_count)) |
| 6072 | return; |
| 6073 | if (character_count == 0) |
| 6074 | return; |
| 6075 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6076 | blink::WebFrame* frame = webview()->focusedFrame(); |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 6077 | if (!frame) |
| 6078 | return; |
| 6079 | |
| 6080 | bounds->reserve(character_count); |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6081 | blink::WebRect webrect; |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 6082 | for (size_t i = 0; i < character_count; ++i) { |
| 6083 | if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { |
| 6084 | DLOG(ERROR) << "Could not retrieve character rectangle at " << i; |
| 6085 | bounds->clear(); |
| 6086 | return; |
| 6087 | } |
| 6088 | bounds->push_back(webrect); |
| 6089 | } |
| 6090 | } |
| 6091 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 6092 | void RenderViewImpl::GetCompositionRange(gfx::Range* range) { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6093 | #if defined(ENABLE_PLUGINS) |
| 6094 | if (focused_pepper_plugin_) { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 6095 | return; |
| 6096 | } |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6097 | #endif |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 6098 | RenderWidget::GetCompositionRange(range); |
| 6099 | } |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 6100 | #endif |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 6101 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6102 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 6103 | #if defined(ENABLE_PLUGINS) |
| 6104 | if (focused_pepper_plugin_) |
| 6105 | return IsPepperAcceptingCompositionEvents(); |
| 6106 | #endif |
| 6107 | return true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 6108 | } |
| 6109 | |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 6110 | void RenderViewImpl::InstrumentWillBeginFrame() { |
| 6111 | if (!webview()) |
| 6112 | return; |
| 6113 | if (!webview()->devToolsAgent()) |
| 6114 | return; |
| 6115 | webview()->devToolsAgent()->didBeginFrame(); |
| 6116 | } |
| 6117 | |
| 6118 | void RenderViewImpl::InstrumentDidBeginFrame() { |
| 6119 | if (!webview()) |
| 6120 | return; |
| 6121 | if (!webview()->devToolsAgent()) |
| 6122 | return; |
| 6123 | // TODO(jamesr/caseq): Decide if this needs to be renamed. |
| 6124 | webview()->devToolsAgent()->didComposite(); |
| 6125 | } |
| 6126 | |
| 6127 | void RenderViewImpl::InstrumentDidCancelFrame() { |
| 6128 | if (!webview()) |
| 6129 | return; |
| 6130 | if (!webview()->devToolsAgent()) |
| 6131 | return; |
| 6132 | webview()->devToolsAgent()->didCancelFrame(); |
| 6133 | } |
| 6134 | |
| 6135 | void RenderViewImpl::InstrumentWillComposite() { |
| 6136 | if (!webview()) |
| 6137 | return; |
| 6138 | if (!webview()->devToolsAgent()) |
| 6139 | return; |
| 6140 | webview()->devToolsAgent()->willComposite(); |
| 6141 | } |
| 6142 | |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 6143 | bool RenderViewImpl::AllowPartialSwap() const { |
| 6144 | return allow_partial_swap_; |
| 6145 | } |
| 6146 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 6147 | void RenderViewImpl::SetScreenMetricsEmulationParameters( |
| 6148 | float device_scale_factor, float root_layer_scale) { |
| 6149 | if (webview()) { |
| 6150 | webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor); |
| 6151 | webview()->setRootLayerScaleTransform(root_layer_scale); |
| 6152 | } |
| 6153 | } |
| 6154 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6155 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6156 | const FileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 6157 | WebFileChooserCompletion* completion) { |
| 6158 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 6159 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 6160 | // This sanity check prevents too many file choose requests from getting |
| 6161 | // queued which could DoS the user. Getting these is most likely a |
| 6162 | // programming error (there are many ways to DoS the user so it's not |
| 6163 | // considered a "real" security check), either in JS requesting many file |
| 6164 | // choosers to pop up, or in a plugin. |
| 6165 | // |
| 6166 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 6167 | // a file picker, which will address this issue in a better way. |
| 6168 | return false; |
| 6169 | } |
| 6170 | |
| 6171 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 6172 | new PendingFileChooser(params, completion))); |
| 6173 | if (file_chooser_completions_.size() == 1) { |
| 6174 | // Actually show the browse dialog when this is the first request. |
| 6175 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 6176 | } |
| 6177 | return true; |
| 6178 | } |
| 6179 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6180 | blink::WebGeolocationClient* RenderViewImpl::geolocationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 6181 | if (!geolocation_dispatcher_) |
| 6182 | geolocation_dispatcher_ = new GeolocationDispatcher(this); |
| 6183 | return geolocation_dispatcher_; |
[email protected] | 7e0c470 | 2010-12-31 14:06:25 | [diff] [blame] | 6184 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6185 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6186 | blink::WebSpeechInputController* RenderViewImpl::speechInputController( |
| 6187 | blink::WebSpeechInputListener* listener) { |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6188 | #if defined(ENABLE_INPUT_SPEECH) |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6189 | if (!input_tag_speech_dispatcher_) |
| 6190 | input_tag_speech_dispatcher_ = |
| 6191 | new InputTagSpeechDispatcher(this, listener); |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6192 | #endif |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6193 | return input_tag_speech_dispatcher_; |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6194 | } |
| 6195 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6196 | blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6197 | if (!speech_recognition_dispatcher_) |
| 6198 | speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6199 | return speech_recognition_dispatcher_; |
| 6200 | } |
| 6201 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6202 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 6203 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6204 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 6205 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 6206 | // different). |
| 6207 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 6208 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6209 | int minimum_percent = static_cast<int>( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 6210 | ZoomLevelToZoomFactor(minimum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6211 | int maximum_percent = static_cast<int>( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 6212 | ZoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6213 | |
| 6214 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 6215 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 6216 | } |
| 6217 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6218 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6219 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6220 | float zoom_level = webview()->zoomLevel(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 6221 | |
| 6222 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged()); |
| 6223 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6224 | // Tell the browser which url got zoomed so it can update the menu and the |
| 6225 | // saved values if necessary |
| 6226 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6227 | routing_id_, zoom_level, remember, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 6228 | GURL(webview()->mainFrame()->document().url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6229 | } |
| 6230 | |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 6231 | double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const { |
| 6232 | return ZoomLevelToZoomFactor(zoom_level); |
| 6233 | } |
| 6234 | |
| 6235 | double RenderViewImpl::zoomFactorToZoomLevel(double factor) const { |
| 6236 | return ZoomFactorToZoomLevel(factor); |
| 6237 | } |
| 6238 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6239 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
| 6240 | const WebString& base_url, |
| 6241 | const WebString& url, |
| 6242 | const WebString& title) { |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 6243 | bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6244 | GURL base(base_url); |
| 6245 | GURL absolute_url = base.Resolve(UTF16ToUTF8(url)); |
| 6246 | if (base.GetOrigin() != absolute_url.GetOrigin()) { |
| 6247 | return; |
| 6248 | } |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 6249 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
| 6250 | UTF16ToUTF8(scheme), |
| 6251 | absolute_url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 6252 | title, |
| 6253 | user_gesture)); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6254 | } |
| 6255 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6256 | blink::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
| 6257 | blink::WebPageVisibilityState current_state = is_hidden() ? |
| 6258 | blink::WebPageVisibilityStateHidden : |
| 6259 | blink::WebPageVisibilityStateVisible; |
| 6260 | blink::WebPageVisibilityState override_state = current_state; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6261 | if (GetContentClient()->renderer()-> |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6262 | ShouldOverridePageVisibilityState(this, |
| 6263 | &override_state)) |
| 6264 | return override_state; |
| 6265 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 6266 | } |
| 6267 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6268 | blink::WebUserMediaClient* RenderViewImpl::userMediaClient() { |
[email protected] | 60ee79f | 2013-09-11 13:49:55 | [diff] [blame] | 6269 | // This can happen in tests, in which case it's OK to return NULL. |
| 6270 | if (!InitializeMediaStreamClient()) |
| 6271 | return NULL; |
| 6272 | |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 6273 | return web_user_media_client_; |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6274 | } |
| 6275 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6276 | blink::WebMIDIClient* RenderViewImpl::webMIDIClient() { |
[email protected] | 7b77f6cb | 2013-07-25 16:23:14 | [diff] [blame] | 6277 | if (!midi_dispatcher_) |
| 6278 | midi_dispatcher_ = new MIDIDispatcher(this); |
| 6279 | return midi_dispatcher_; |
| 6280 | } |
| 6281 | |
[email protected] | a0629af9 | 2012-08-08 00:39:37 | [diff] [blame] | 6282 | void RenderViewImpl::draggableRegionsChanged() { |
| 6283 | FOR_EACH_OBSERVER( |
| 6284 | RenderViewObserver, |
| 6285 | observers_, |
| 6286 | DraggableRegionsChanged(webview()->mainFrame())); |
| 6287 | } |
| 6288 | |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 6289 | WebMediaPlayer* RenderViewImpl::CreateWebMediaPlayerForMediaStream( |
| 6290 | WebFrame* frame, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6291 | const blink::WebURL& url, |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 6292 | WebMediaPlayerClient* client) { |
| 6293 | #if defined(ENABLE_WEBRTC) |
| 6294 | if (!InitializeMediaStreamClient()) { |
| 6295 | LOG(ERROR) << "Failed to initialize MediaStreamClient"; |
| 6296 | return NULL; |
| 6297 | } |
| 6298 | #if !defined(GOOGLE_TV) |
| 6299 | if (media_stream_client_->IsMediaStream(url)) { |
| 6300 | #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
| 6301 | bool found_neon = |
| 6302 | (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; |
| 6303 | UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon); |
| 6304 | #endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
| 6305 | return new WebMediaPlayerMS(frame, client, AsWeakPtr(), |
| 6306 | media_stream_client_, new RenderMediaLog()); |
| 6307 | } |
| 6308 | #endif // !defined(GOOGLE_TV) |
| 6309 | #endif // defined(ENABLE_WEBRTC) |
| 6310 | return NULL; |
| 6311 | } |
| 6312 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6313 | #if defined(OS_ANDROID) |
| 6314 | WebContentDetectionResult RenderViewImpl::detectContentAround( |
| 6315 | const WebHitTestResult& touch_hit) { |
| 6316 | DCHECK(!touch_hit.isNull()); |
| 6317 | DCHECK(!touch_hit.node().isNull()); |
| 6318 | DCHECK(touch_hit.node().isTextNode()); |
| 6319 | |
| 6320 | // Process the position with all the registered content detectors until |
| 6321 | // a match is found. Priority is provided by their relative order. |
| 6322 | for (ContentDetectorList::const_iterator it = content_detectors_.begin(); |
| 6323 | it != content_detectors_.end(); ++it) { |
| 6324 | ContentDetector::Result content = (*it)->FindTappedContent(touch_hit); |
| 6325 | if (content.valid) { |
| 6326 | return WebContentDetectionResult(content.content_boundaries, |
| 6327 | UTF8ToUTF16(content.text), content.intent_url); |
| 6328 | } |
| 6329 | } |
| 6330 | return WebContentDetectionResult(); |
| 6331 | } |
| 6332 | |
| 6333 | void RenderViewImpl::scheduleContentIntent(const WebURL& intent) { |
| 6334 | // Introduce a short delay so that the user can notice the content. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 6335 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6336 | FROM_HERE, |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 6337 | base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, |
| 6338 | AsWeakPtr(), |
| 6339 | intent, |
| 6340 | expected_content_intent_id_), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6341 | base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); |
| 6342 | } |
| 6343 | |
| 6344 | void RenderViewImpl::cancelScheduledContentIntents() { |
| 6345 | ++expected_content_intent_id_; |
| 6346 | } |
| 6347 | |
| 6348 | void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, |
| 6349 | size_t request_id) { |
| 6350 | if (request_id != expected_content_intent_id_) |
| 6351 | return; |
| 6352 | |
| 6353 | // Remove the content highlighting if any. |
| 6354 | scheduleComposite(); |
| 6355 | |
| 6356 | if (!intent.is_empty()) |
| 6357 | Send(new ViewHostMsg_StartContentIntent(routing_id_, intent)); |
| 6358 | } |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 6359 | |
| 6360 | bool RenderViewImpl::openDateTimeChooser( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6361 | const blink::WebDateTimeChooserParams& params, |
| 6362 | blink::WebDateTimeChooserCompletion* completion) { |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 6363 | date_time_picker_client_.reset( |
| 6364 | new RendererDateTimePicker(this, params, completion)); |
| 6365 | return date_time_picker_client_->Open(); |
| 6366 | } |
| 6367 | |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 6368 | WebMediaPlayer* RenderViewImpl::CreateAndroidWebMediaPlayer( |
| 6369 | WebFrame* frame, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6370 | const blink::WebURL& url, |
[email protected] | 40bed81 | 2013-11-05 06:59:15 | [diff] [blame] | 6371 | WebMediaPlayerClient* client) { |
| 6372 | GpuChannelHost* gpu_channel_host = |
| 6373 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
| 6374 | CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
| 6375 | if (!gpu_channel_host) { |
| 6376 | LOG(ERROR) << "Failed to establish GPU channel for media player"; |
| 6377 | return NULL; |
| 6378 | } |
| 6379 | |
| 6380 | scoped_ptr<StreamTextureFactory> stream_texture_factory; |
| 6381 | if (UsingSynchronousRendererCompositor()) { |
| 6382 | SynchronousCompositorFactory* factory = |
| 6383 | SynchronousCompositorFactory::GetInstance(); |
| 6384 | stream_texture_factory = factory->CreateStreamTextureFactory(routing_id_); |
| 6385 | } else { |
| 6386 | scoped_refptr<cc::ContextProvider> context_provider = |
| 6387 | RenderThreadImpl::current()->SharedMainThreadContextProvider(); |
| 6388 | |
| 6389 | if (!context_provider.get()) { |
| 6390 | LOG(ERROR) << "Failed to get context3d for media player"; |
| 6391 | return NULL; |
| 6392 | } |
| 6393 | |
| 6394 | stream_texture_factory.reset(new StreamTextureFactoryImpl( |
| 6395 | context_provider->Context3d(), gpu_channel_host, routing_id_)); |
| 6396 | } |
| 6397 | |
| 6398 | scoped_ptr<WebMediaPlayerAndroid> web_media_player_android( |
| 6399 | new WebMediaPlayerAndroid( |
| 6400 | frame, |
| 6401 | client, |
| 6402 | AsWeakPtr(), |
| 6403 | media_player_manager_, |
| 6404 | stream_texture_factory.release(), |
| 6405 | RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(), |
| 6406 | new RenderMediaLog())); |
| 6407 | #if defined(ENABLE_WEBRTC) && defined(GOOGLE_TV) |
| 6408 | if (media_stream_client_ && media_stream_client_->IsMediaStream(url)) { |
| 6409 | RTCVideoDecoderFactoryTv* factory = RenderThreadImpl::current() |
| 6410 | ->GetMediaStreamDependencyFactory()->decoder_factory_tv(); |
| 6411 | // |media_stream_client| and |factory| outlives |web_media_player_android|. |
| 6412 | if (!factory->AcquireDemuxer() || |
| 6413 | !web_media_player_android->InjectMediaStream( |
| 6414 | media_stream_client_, |
| 6415 | factory, |
| 6416 | base::Bind( |
| 6417 | base::IgnoreResult(&RTCVideoDecoderFactoryTv::ReleaseDemuxer), |
| 6418 | base::Unretained(factory)))) { |
| 6419 | LOG(ERROR) << "Failed to inject media stream."; |
| 6420 | return NULL; |
| 6421 | } |
| 6422 | } |
| 6423 | #endif // defined(ENABLE_WEBRTC) && defined(GOOGLE_TV) |
| 6424 | return web_media_player_android.release(); |
| 6425 | } |
| 6426 | |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6427 | #endif // defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6428 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6429 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6430 | void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) { |
[email protected] | 68dc3ba | 2010-12-06 21:43:15 | [diff] [blame] | 6431 | if (external_popup_menu_ == NULL) { |
| 6432 | // Crash reports from the field indicate that we can be notified with a |
| 6433 | // NULL external popup menu (we probably get notified twice). |
| 6434 | // If you hit this please file a bug against jcivelli and include the page |
| 6435 | // and steps to repro. |
| 6436 | NOTREACHED(); |
| 6437 | return; |
| 6438 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6439 | external_popup_menu_->DidSelectItem(selected_index); |
| 6440 | external_popup_menu_.reset(); |
| 6441 | } |
| 6442 | #endif |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 6443 | |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6444 | #if defined(OS_ANDROID) |
| 6445 | void RenderViewImpl::OnSelectPopupMenuItems( |
| 6446 | bool canceled, |
| 6447 | const std::vector<int>& selected_indices) { |
| 6448 | // It is possible to receive more than one of these calls if the user presses |
| 6449 | // a select faster than it takes for the show-select-popup IPC message to make |
| 6450 | // it to the browser UI thread. Ignore the extra-messages. |
| 6451 | // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 6452 | if (!external_popup_menu_) |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6453 | return; |
| 6454 | |
| 6455 | external_popup_menu_->DidSelectItems(canceled, selected_indices); |
| 6456 | external_popup_menu_.reset(); |
| 6457 | } |
| 6458 | #endif |
| 6459 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6460 | void RenderViewImpl::OnContextMenuClosed( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6461 | const CustomContextMenuContext& custom_context) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6462 | if (custom_context.request_id) { |
| 6463 | // External request, should be in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6464 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6465 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 6466 | if (client) { |
| 6467 | client->OnMenuClosed(custom_context.request_id); |
| 6468 | pending_context_menus_.Remove(custom_context.request_id); |
| 6469 | } |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6470 | } else { |
| 6471 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 6472 | context_menu_node_.reset(); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6473 | } |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 6474 | } |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6475 | |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 6476 | void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) { |
[email protected] | a14ddcd | 2013-06-21 22:53:03 | [diff] [blame] | 6477 | context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU; |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 6478 | touch_editing_context_menu_location_ = location; |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 6479 | if (webview()) |
| 6480 | webview()->showContextMenu(); |
| 6481 | } |
| 6482 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6483 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6484 | if (!webview()) |
| 6485 | return; |
| 6486 | WebFrame* main_frame = webview()->mainFrame(); |
| 6487 | if (!main_frame) |
| 6488 | return; |
| 6489 | main_frame->enableViewSourceMode(true); |
| 6490 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 6491 | |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 6492 | void RenderViewImpl::OnDisownOpener() { |
| 6493 | if (!webview()) |
| 6494 | return; |
| 6495 | |
| 6496 | WebFrame* main_frame = webview()->mainFrame(); |
| 6497 | if (main_frame && main_frame->opener()) |
| 6498 | main_frame->setOpener(NULL); |
| 6499 | } |
| 6500 | |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6501 | #if defined(OS_ANDROID) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6502 | bool RenderViewImpl::didTapMultipleTargets( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame^] | 6503 | const blink::WebGestureEvent& event, |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6504 | const WebVector<WebRect>& target_rects) { |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 6505 | // Never show a disambiguation popup when accessibility is enabled, |
| 6506 | // as this interferes with "touch exploration". |
| 6507 | if (accessibility_mode_ == AccessibilityModeComplete) |
| 6508 | return false; |
| 6509 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6510 | gfx::Rect finger_rect( |
| 6511 | event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2, |
| 6512 | event.data.tap.width, event.data.tap.height); |
| 6513 | gfx::Rect zoom_rect; |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6514 | float new_total_scale = |
| 6515 | DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( |
| 6516 | finger_rect, target_rects, GetSize(), |
| 6517 | gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(), |
| 6518 | device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect); |
| 6519 | if (!new_total_scale) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6520 | return false; |
| 6521 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 6522 | bool handled = false; |
| 6523 | switch (renderer_preferences_.tap_multiple_targets_strategy) { |
| 6524 | case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM: |
| 6525 | handled = webview()->zoomToMultipleTargetsRect(zoom_rect); |
| 6526 | break; |
| 6527 | case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: { |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 6528 | gfx::Size canvas_size = |
| 6529 | gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale)); |
| 6530 | TransportDIB* transport_dib = NULL; |
| 6531 | { |
| 6532 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 6533 | RenderProcess::current()->GetDrawingCanvas(&transport_dib, |
| 6534 | gfx::Rect(canvas_size))); |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 6535 | if (!canvas) { |
| 6536 | handled = false; |
| 6537 | break; |
| 6538 | } |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6539 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 6540 | // TODO(trchen): Cleanup the device scale factor mess. |
| 6541 | // device scale will be applied in WebKit |
| 6542 | // --> zoom_rect doesn't include device scale, |
| 6543 | // but WebKit will still draw on zoom_rect * device_scale_factor_ |
| 6544 | canvas->scale(new_total_scale / device_scale_factor_, |
| 6545 | new_total_scale / device_scale_factor_); |
| 6546 | canvas->translate(-zoom_rect.x() * device_scale_factor_, |
| 6547 | -zoom_rect.y() * device_scale_factor_); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6548 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 6549 | webwidget_->paint( |
| 6550 | canvas.get(), |
| 6551 | zoom_rect, |
| 6552 | WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent); |
| 6553 | } |
| 6554 | |
| 6555 | gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect( |
| 6556 | ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect))); |
| 6557 | Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_, |
| 6558 | physical_window_zoom_rect, |
| 6559 | canvas_size, |
| 6560 | transport_dib->id())); |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 6561 | handled = true; |
| 6562 | break; |
| 6563 | } |
| 6564 | case TAP_MULTIPLE_TARGETS_STRATEGY_NONE: |
| 6565 | // No-op. |
| 6566 | break; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6567 | } |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6568 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 6569 | return handled; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6570 | } |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6571 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6572 | |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 6573 | unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const { |
| 6574 | return history_list_length_; |
| 6575 | } |
| 6576 | |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 6577 | void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) { |
| 6578 | if (enable) { |
| 6579 | if (has_focus()) |
| 6580 | return; |
| 6581 | OnSetActive(true); |
| 6582 | OnSetFocus(true); |
| 6583 | } else { |
| 6584 | if (!has_focus()) |
| 6585 | return; |
| 6586 | OnSetFocus(false); |
| 6587 | OnSetActive(false); |
| 6588 | } |
| 6589 | } |
| 6590 | |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 6591 | void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) { |
[email protected] | b54fe45 | 2013-06-07 14:01:53 | [diff] [blame] | 6592 | ViewMsg_Resize_Params params; |
| 6593 | params.screen_info = screen_info_; |
| 6594 | params.screen_info.deviceScaleFactor = factor; |
| 6595 | params.new_size = size(); |
| 6596 | params.physical_backing_size = |
| 6597 | gfx::ToCeiledSize(gfx::ScaleSize(size(), factor)); |
| 6598 | params.overdraw_bottom_height = 0.f; |
| 6599 | params.resizer_rect = WebRect(); |
| 6600 | params.is_fullscreen = is_fullscreen(); |
| 6601 | OnResize(params); |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 6602 | } |
| 6603 | |
[email protected] | 9265016 | 2013-10-30 03:31:02 | [diff] [blame] | 6604 | void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) { |
| 6605 | gfx::Rect new_position(rootWindowRect().x, |
| 6606 | rootWindowRect().y, |
| 6607 | new_size.width(), |
| 6608 | new_size.height()); |
| 6609 | ResizeSynchronously(new_position); |
| 6610 | } |
| 6611 | |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 6612 | void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) { |
| 6613 | resizing_mode_selector_->set_is_synchronous_mode(enable); |
| 6614 | } |
| 6615 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 6616 | void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size, |
| 6617 | const gfx::Size& max_size) { |
| 6618 | OnEnableAutoResize(min_size, max_size); |
| 6619 | } |
| 6620 | |
| 6621 | void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) { |
| 6622 | OnDisableAutoResize(new_size); |
| 6623 | } |
| 6624 | |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 6625 | void RenderViewImpl::SetMediaStreamClientForTesting( |
[email protected] | 5e35a8d | 2013-07-10 19:37:21 | [diff] [blame] | 6626 | MediaStreamClient* media_stream_client) { |
[email protected] | c3bdce15 | 2013-07-10 04:56:34 | [diff] [blame] | 6627 | DCHECK(!media_stream_client_); |
| 6628 | DCHECK(!web_user_media_client_); |
| 6629 | media_stream_client_ = media_stream_client; |
| 6630 | } |
| 6631 | |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 6632 | bool RenderViewImpl::IsPluginFullscreenAllowed() { |
| 6633 | return renderer_preferences_.plugin_fullscreen_allowed; |
| 6634 | } |
| 6635 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6636 | void RenderViewImpl::OnReleaseDisambiguationPopupDIB( |
| 6637 | TransportDIB::Handle dib_handle) { |
| 6638 | TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
| 6639 | RenderProcess::current()->ReleaseTransportDIB(dib); |
| 6640 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6641 | |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 6642 | void RenderViewImpl::DidCommitCompositorFrame() { |
| 6643 | RenderWidget::DidCommitCompositorFrame(); |
| 6644 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame()); |
| 6645 | } |
| 6646 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 6647 | void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) { |
| 6648 | if (!urls.empty()) |
| 6649 | Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls)); |
| 6650 | } |
| 6651 | |
| 6652 | void RenderViewImpl::DidStopLoadingIcons() { |
| 6653 | int icon_types = WebIconURL::TypeFavicon; |
| 6654 | if (TouchEnabled()) |
| 6655 | icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
| 6656 | |
| 6657 | WebVector<WebIconURL> icon_urls = |
| 6658 | webview()->mainFrame()->iconURLs(icon_types); |
| 6659 | |
| 6660 | std::vector<FaviconURL> urls; |
| 6661 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 6662 | WebURL url = icon_urls[i].iconURL(); |
| 6663 | if (!url.isEmpty()) |
| 6664 | urls.push_back(FaviconURL(url, |
| 6665 | ToFaviconType(icon_urls[i].iconType()))); |
| 6666 | } |
| 6667 | SendUpdateFaviconURL(urls); |
| 6668 | } |
| 6669 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6670 | } // namespace content |